Skip to main content

A piptools pre-commit version sync utility

Project description

Piptools-sync


A pre-commit plugin to align pre-commit repository versions with those derived by pip-tools.

PyPI Downloads Status Python Version tests Codecov CodeQl pre-commit.ci status readthedocs CodeFactor Codeclimate Imports: isort Code style: black Checked with mypy security: bandit Commitizen friendly Conventional Commits DeepSource license

pip-tools and Pre-Commit are two of my favourite development tools. However, they don't always necessarily agree on what versions of packages should be installed. This lack of consolidation can lead to problems with pre-commit. This pre-commit plugin syncs the pre-commit package versions with the versions generated by pip-tools' compile process.

Introduction


Project Rationale

A while ago I came across an issue committing files to my local git repository. The issue occured at the flake8 linting stage using pre-commit. There was however no problem manually running flake8 from the command line. Upon investigation It was found that flake8 had an incompatibility issue with one of its plugins. With further investigation I noticed that pip-tools had pinned flake8 to an earlier version to what pre-commit was caching.

In short - pip-tools does a spectacularly good job pinning your dependencies and the dependencies of these dependencies. It has one job to do and it does it perfectly. The pre-commit autoupdate command just updates the "rev" for the "repo" in the .pre-commit-config.yaml file to the latest version available and ignores the dependencies.

The following example displays the way flake8 and a few plugins are configured by the two tools :

  • pip-tools (via requirements.txt)
flake8==4.0.1
    # via ...
flake8-bugbear==22.8.23
    # via ...
flake8-comprehensions==3.10.0
    # via ...
flake8-eradicate==1.3.0
    # via ...
flake8-simplify==0.19.3
    # via ...
  • pre-commit (via .pre-commit-config.yaml)
  - repo: https://github.com/pycqa/flake8
    rev 5.0.4
    hooks:
      - id: flake8
        additional_dependencies:
          - flake8-bugbear
          - flake8-comprehensions
          - flake8-eradicate
          - flake8-simplify
        args: ["--ignore=E800,F842,F841,W503"]

If we force pip-tools to use a later version of flake8 (e,g 5.0.4) by manually pinning the version in the ".in" file and recompiling it is clear pip-tools is unhappy... A quick look at the dependencies shows why.

Could not find a version that matches flake8!=3.2.0,<5.0.0,<6,==5.0.4,>=3.0.0,>=3.3.0,>=3.5,>=3.7,>=3.9.1,>=4.0.1 (from -r requirements\development.in (line 12))
Tried: 0.1, 0.2, 0.3, 0.4, 0.5, 0.6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==5.0.4 (from -r requirements\development.in (line 12))
  flake8>=3.7 (from flake8-simplify==0.19.3->-r requirements\development.in (line 20))
  flake8<5.0.0 (from flake8-bugbear==22.8.23->-r requirements\development.in (line 14))
  flake8!=3.2.0,>=3.0 (from flake8-comprehensions==3.10.0->-r requirements\development.in (line 15))
  flake8<6,>=3.5 (from flake8-eradicate==1.3.0->-r requirements\development.in (line 17))

The tools store packages in different areas on the file system. Pre-commit uses a cache area in the user folder, whereas pip-tools uses the usual site-packages area.

It should be noted that not all pre-commit hooks are written in Python for Python, so it makes sense that it has its own cache file system independent of pip. Therefore, not all pre-commit repositories have an entry in PyPI. They can simply be defined by a GitHub repository URL.

Lastly, browsing the internet looking for a solution I came across the following issue raised under the pip-tools project (dated 24 Jun 2021). The issue is still open and describes the exact same problem.

https://github.com/jazzband/pip-tools/issues/1437

Installation


1 - Install into pre-commit

Just add to the pre-commit configuration file (.pre-commit-config.yaml). I have configured it to run at every commit at the pre-commit stage of git.

  - repo: https://github.com/Stephen-RA-King/piptools-sync
    rev: 0.3.1
    hooks:
      - id: piptools_sync

2 - Install by pip

Installing by pip enables the package to be run from the command line at any time.

pip install piptools-sync

Usage


1 - Automatic running by pre-commit

Passing example.

piptools_sync............................................................Passed

Failing example.

piptools_sync............................................................Failed
- hook id: piptools_sync
- exit code: 1
- files were modified by this hook

INFO:init:flake8          - piptools: 4.0.1      !=     pre-commit: 5.0.4

Note: In this case piptools-sync will automatically update the pre-commit config file with pip-tools version. However, the commit with fail and will need to be re-run.

2 - Running from the command line

Passing example.

$ piptools_sync
Success! - pre-commit is in sync with piptools

Failing example.

$ piptools_sync
flake8          - piptools: 4.0.1      !=     pre-commit: 5.0.4

Note: In this case piptools-sync will automatically update the pre-commit config file with pip-tools version

For more examples and usage, please refer to the Wiki.

Documentation


Read the Docs

Wiki

Future Enhancements


  • Move some global variables into a separate settings file (toml).
  • Settings configurable from the command line (and therefore configurable from the pre-commit.yaml file).
  • Improve web request performance with asyncio / aiohttp libraries.

Meta


Stephen R A King : sking.github@gmail.com

Distributed under the MIT license. See for more information.

Created with Cookiecutter template: pydough version 1.2.1

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

piptools_sync-1.0.4.tar.gz (23.1 kB view details)

Uploaded Source

Built Distribution

piptools_sync-1.0.4-py3-none-any.whl (19.3 kB view details)

Uploaded Python 3

File details

Details for the file piptools_sync-1.0.4.tar.gz.

File metadata

  • Download URL: piptools_sync-1.0.4.tar.gz
  • Upload date:
  • Size: 23.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.8.0 pkginfo/1.9.6 readme-renderer/37.3 requests/2.28.2 requests-toolbelt/0.10.1 urllib3/1.26.14 tqdm/4.64.1 importlib-metadata/6.0.0 keyring/23.13.1 rfc3986/2.0.0 colorama/0.4.6 CPython/3.9.10

File hashes

Hashes for piptools_sync-1.0.4.tar.gz
Algorithm Hash digest
SHA256 cdc3fe32c637f2df16e536ade44315c38d6ba8ea1e5ba62ef57056f94a7049c3
MD5 1810cf3872e16dd655984970217a275f
BLAKE2b-256 3f0898f72c3444c30913c89b6a0de6da62c82030bedf47196941adecab57167f

See more details on using hashes here.

File details

Details for the file piptools_sync-1.0.4-py3-none-any.whl.

File metadata

  • Download URL: piptools_sync-1.0.4-py3-none-any.whl
  • Upload date:
  • Size: 19.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.8.0 pkginfo/1.9.6 readme-renderer/37.3 requests/2.28.2 requests-toolbelt/0.10.1 urllib3/1.26.14 tqdm/4.64.1 importlib-metadata/6.0.0 keyring/23.13.1 rfc3986/2.0.0 colorama/0.4.6 CPython/3.9.10

File hashes

Hashes for piptools_sync-1.0.4-py3-none-any.whl
Algorithm Hash digest
SHA256 1f8ef16199e4b8f711bee2a8a3d44b526d3b0b8f1aa050b69fb90d3656a24f68
MD5 1a8cce699463bbd3f4462b6b58a39eb1
BLAKE2b-256 5c2413b32f055a06ce3e967ac0e043c1fc048a0a8ff41a6b0bed413703355287

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page