Skip to content

Track pre-commit hooks as Poetry dependencies - #397

Merged
cjolowicz merged 23 commits into
masterfrom
pre-commit-poetry-nox
Jul 15, 2020
Merged

cjolowicz merged 23 commits into
masterfrom
pre-commit-poetry-nox

Conversation

@cjolowicz

@cjolowicz cjolowicz commented Jun 13, 2020 •

Copy link
Copy Markdown
Owner

This PR changes the way pre-commit is integrated with projects. Python-language hooks are no longer managed by pre-commit. Instead, they are tracked as development dependencies in Poetry, and installed into the Nox session alongside pre-commit itself. As development dependencies, they are also present in the Poetry environment.

In detail, this includes the following changes:

  • Python-language hooks are converted to repository-local¹ system hooks².
  • Hook dependencies are added to Poetry.
  • Hook dependencies are installed into the Nox session for pre-commit.

¹ Repository-local hooks are not backed by an external git repository.
² System hooks are not installed into a pre-commit environment.

This approach has some advantages:

  • All project dependencies are managed by Poetry.
  • Hooks receive automatic upgrades from Dependabot.
  • Nox can serve as a single entry point for all checks.
  • Additional hook dependencies can be upgraded by a dependency manager. An example for this are Flake8 extensions. By contrast, pre-commit autoupdate does not include additional dependencies.
  • Dependencies of dependencies (subdependencies) can be locked automatically, making checks more repeatable and deterministic.
  • Linters and formatters are available in the Poetry environment, which is useful for editor integration.

There are also some drawbacks to this technique:

  • This is not the officially supported way to integrate pre-commit hooks.
  • The hook scripts installed by pre-commit do not activate the virtual environment in which pre-commit and the hooks are installed. To work around this limitation, the Nox session patches hook scripts on installation.
  • Adding a hook is more work, including updating pyproject.toml and noxfile.py, and adding the hook definition to pre-commit-config.yaml.

See #316

@cjolowicz cjolowicz added the enhancement New feature or request label Jun 13, 2020
@cjolowicz cjolowicz added this to the 2020.7.15 milestone Jun 13, 2020
@cjolowicz
cjolowicz marked this pull request as draft June 13, 2020 18:05
@cjolowicz cjolowicz modified the milestones: 2020.7.15, Backlog Jul 1, 2020
@cjolowicz
cjolowicz force-pushed the pre-commit-poetry-nox branch from 6da3199 to 2f1417d Compare July 3, 2020 10:11
@cjolowicz
cjolowicz marked this pull request as ready for review July 8, 2020 12:35
@cjolowicz

Copy link
Copy Markdown
Owner Author

@paw-lu Any thoughts on this?

@cjolowicz
cjolowicz force-pushed the pre-commit-poetry-nox branch from ed0de9f to 6269a20 Compare July 8, 2020 12:44
@cjolowicz
cjolowicz merged commit affd195 into master Jul 15, 2020
@cjolowicz
cjolowicz deleted the pre-commit-poetry-nox branch July 15, 2020 11:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant