Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add ability to configure pre-commit files per project #17

Merged
merged 1 commit into from
Dec 15, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
3 changes: 3 additions & 0 deletions config.yml.example
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 4 additions & 1 deletion pydc_control/commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
7 changes: 4 additions & 3 deletions pydc_control/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
4 changes: 4 additions & 0 deletions pydc_control/data.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
Loading