From 8c96a36756511deafaa3c18e35860b2d31f3e888 Mon Sep 17 00:00:00 2001 From: saville Date: Fri, 15 Dec 2023 10:59:16 -0700 Subject: [PATCH] Add ability to configure pre-commit files per project --- README.md | 9 +++++---- config.yml.example | 3 +++ pydc_control/commands.py | 5 ++++- pydc_control/config.py | 7 ++++--- pydc_control/data.py | 4 ++++ 5 files changed, 20 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index 7f73edb..0ee7f43 100644 --- a/README.md +++ b/README.md @@ -21,8 +21,8 @@ upstream docker images or developing using local code. this project can control them * Allows easy development of a single project or multiple projects at the same time * Generate dynamic docker-compose files using Jinja templates for any number of projects -* Manage a [pre-commit](https://pre-commit.com/) config file in one place to copy and - install in each project +* Manages [pre-commit](https://pre-commit.com/) config file(s) by copying and + installing in each configured project ## Setup @@ -47,8 +47,9 @@ my-app/ config.yml # Environment variable configuration, symlinked to all projects automatically docker-compose.env - # Optional pre-commit config file that will be copied and installed in each project - .pre-commit-config.yaml + # Optional pre-commit config file(s) + # This needs to be configured in each project to be copied and installed + my-pre-commit-config.yaml # Arbitrary projects project1/ # The only required file for a project is a docker-compose file diff --git a/config.yml.example b/config.yml.example index ac97c83..d224546 100644 --- a/config.yml.example +++ b/config.yml.example @@ -44,6 +44,9 @@ projects: directory: my-project1 # The repository to clone the project from repository: git@github.com:myorg/project1.git + # An optional reference to a pre-commit config file to copy and install in the repo on repo update/clone + # This file should be in the control project + #pre_commit_config: my-pre-commit-file.yaml # A list of services (containers) to run services: # The service name is automatically prefixed with the service prefix configured above diff --git a/pydc_control/commands.py b/pydc_control/commands.py index 99fc50a..cfdf5d7 100644 --- a/pydc_control/commands.py +++ b/pydc_control/commands.py @@ -256,8 +256,11 @@ def _handle_extra_remotes(extra_remotes: List[str], project: Project) -> None: def _handle_pre_commit(project: Project) -> None: + if not project.pre_commit_config: + return + # If there is a pre-commit config file, then copy it to each repo, git add it, and install it - pre_commit_config_path = config.get_pre_commit_config_path() + pre_commit_config_path = config.get_pre_commit_config_path(project.pre_commit_config) if os.path.exists(pre_commit_config_path): log.get_logger().debug(f'Pre-commit config file {pre_commit_config_path} exists, installing') pre_commit_file_name = os.path.basename(pre_commit_config_path) diff --git a/pydc_control/config.py b/pydc_control/config.py index 6b7e5f0..180f475 100644 --- a/pydc_control/config.py +++ b/pydc_control/config.py @@ -46,10 +46,11 @@ def get_env_file_path() -> str: return os.path.join(_BASE_DIR, ENV_FILE) -# The following methods are cached so that we only retrieve/validate them once (config cannot be changed mid-run) @lru_cache() -def get_pre_commit_config_path() -> str: - return os.path.join(_BASE_DIR, str(PRE_COMMIT_CONFIG_FILE)) +def get_pre_commit_config_path(project_pre_commit_config: Union[str, bool]) -> str: + if isinstance(project_pre_commit_config, bool): + return os.path.join(_BASE_DIR, str(PRE_COMMIT_CONFIG_FILE)) + return os.path.join(_BASE_DIR, project_pre_commit_config) @lru_cache() diff --git a/pydc_control/data.py b/pydc_control/data.py index 3912ff5..c3c9dd3 100644 --- a/pydc_control/data.py +++ b/pydc_control/data.py @@ -171,6 +171,10 @@ def directory(self) -> Optional[str]: def repository(self) -> Optional[str]: return self.data.get('repository') + @property + def pre_commit_config(self) -> Union[str, bool]: + return self.data.get('pre_commit_config', False) + @property def path(self) -> str: if not self.directory: