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

Enhancement/improved dependency management #76

Open
wants to merge 9 commits into
base: develop
Choose a base branch
from
22 changes: 22 additions & 0 deletions .poetry-pre-commit-sync.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{
"pre-commit": {
"repo": "https://github.com/pre-commit/pre-commit-hooks",
"rev": "v${rev}"
},
"ruff": {
"repo": "https://github.com/charliermarsh/ruff-pre-commit",
"rev": "v${rev}"
},
"typos": {
"repo": "https://github.com/crate-ci/typos",
"rev": "v${rev}"
},
"mypy": {
"repo": "https://github.com/pre-commit/mirrors-mypy",
"rev": "v${rev}"
},
"black": {
"repo": "https://github.com/psf/black",
"rev": "${rev}"
}
}
18 changes: 12 additions & 6 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ fail_fast: false

repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v3.2.0
rev: v3.4.0
hooks:
- id: check-toml
- id: check-yaml
Expand All @@ -19,28 +19,34 @@ repos:
- id: requirements-txt-fixer

- repo: https://github.com/psf/black
rev: 22.10.0
rev: 22.12.0
hooks:
- id: black
args: [--config=pyproject.toml]

- repo: https://github.com/charliermarsh/ruff-pre-commit
# Ruff version.
rev: "v0.0.257"
rev: "v0.0.287"
hooks:
- id: ruff
args: [--fix, --exit-non-zero-on-fix, "--config=pyproject.toml"] # enable autofix

- repo: https://github.com/pre-commit/mirrors-mypy
rev: v1.1.1
rev: v1.5.1
hooks:
- id: mypy
language: system
args: ["--config-file=pyproject.toml"]
exclude: ^tests/

- repo: https://github.com/crate-ci/typos
rev: v1.16.1
rev: v1.16.11
hooks:
- id: typos
args: [--config=_typos.toml]
pass_filenames: false

- repo: https://github.com/floatingpurr/sync_with_poetry
rev: "1.1.0"
hooks:
- id: sync_with_poetry
args: ["--db=.poetry-pre-commit-sync.json"]
54 changes: 54 additions & 0 deletions DEVELOPMENT.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,3 +49,57 @@ Optionally, to run the hooks against all of the files, run the following command
```bash
pre-commit run --all-files
```

## Updating Dependency Versions
Dependency versioning is handled by `poetry`.

To trigger an update of the dependencies run the following (ensuring you are in the `poetry` shell)

```bash
poetry update
```

This will carry out the package resolution as per the [pyproject.toml](pyproject.toml) file,
ensuring there are no package conflicts, then updating the [poetry.lock](poetry.lock) file.

Finally, to ensure that the `pre-commit` hooks are correctly updated inline with the new lock file,
run:

```bash
pre-commit run sync_with_poetry --all-files
```

This command runs a pre-commit meta-hook
([sync_with_poetry](https://github.com/floatingpurr/sync_with_poetry/tree/main)) which parses the
[poetry.lock](poetry.lock) file and updates the corresponding revisions ("rev")
in [.pre-commit-config.yaml](.pre-commit-config.yaml)

### Adding a new `pre-commit` dependency
When adding a new `pre-commit` hooks, to ensure the above dependency management tracks the new hook,
you should follow the following steps:

1. Use `poetry` to add the dependency to the "dev" group:

```bash
poetry add <pkg>@<version> --group dev
```

Where &lt;pkg&gt; is the dependency package name and &lt;version&gt; is the semantic version string.
E.g. `requests@^2.13.0`.
See [dependency specification](https://python-poetry.org/docs/dependency-specification/) for more details.

This will update the [pyproject.toml](pyproject.toml) and [poetry.lock](poetry.lock) files automatically.

2. Add the repo details for the dependency to [.poetry-pre-commit-sync.json](.poetry-pre-commit-sync.json)

This file is a reference for the `pre-commit` repositories. Add in a new block of the form:

```json
"<repo-name-in-pypi>": {
"repo": "<repo-url>",
"rev": "<revision-format>"
}
```

More details on the specifics of this config can be found on
the [sync_with_poetry github](https://github.com/floatingpurr/sync_with_poetry/tree/main)
Loading