Skip to main content

hatch plugin to use pip-compile to manage project dependencies

Project description

hatch-pip-compile

hatch plugin to use pip-compile to manage project dependencies and lockfiles.

PyPI PyPI - Python Version GitHub License Hatch project Ruff pre-commit semantic-release Gitmoji

Installation

Declare hatch-pip-compile as a dependency in your pyproject.toml file under the [tool.hatch.env] table and hatch will automatically install it. You must also have your environment type set to pip-compile (see Configuration).

  • pyproject.toml

    [tool.hatch.env]
    requires = [
        "hatch-pip-compile"
    ]
    
    [tool.hatch.envs.default]
    type = "pip-compile"
    
  • hatch.toml

    [env]
    requires = [
        "hatch-pip-compile"
    ]
    
    [envs.default]
    type = "pip-compile"
    

Usage

The hatch-pip-compile plugin will automatically run pip-compile whenever your environment needs to be updated. Behind the scenes, this plugin creates a lockfile at requirements.txt (non-default lockfiles are located at requirements/requirements-{env_name}.txt). Alongside pip-compile, this plugin also uses pip-sync to install the dependencies from the lockfile into your environment.

Configuration

The environment plugin name is pip-compile. Set your environment type to pip-compile to use this plugin for the respective environment.

  • pyproject.toml

    [tool.hatch.envs.default]
    type = "pip-compile"
    
  • hatch.toml

    [envs.default]
    type = "pip-compile"
    

Configuration Options

name type description
lock-filename str The filename of the ultimate lockfile. default env is requirements.txt, non-default is requirements/requirements-{env_name}.txt
pip-compile-hashes bool Whether to generate hashes in the lockfile. Defaults to true.
pip-compile-strip-extras bool Whether to strip the extras from the lockfile ensuring it is constraints compatible, defaults to true
pip-compile-verbose bool Set to true to run pip-compile in verbose mode instead of quiet mode, set to false to silence warnings
pip-compile-args list[str] Additional command-line arguments to pass to pip-compile

Examples

lock-filename

The path (including the directory) to the ultimate lockfile. Defaults to requirements.txt in the project root for the default environment, and requirements/requirements-{env_name}.txt for non-default environments.

Changing the lock file path:

  • pyproject.toml

    [tool.hatch.envs.<envName>]
    type = "pip-compile"
    lock-filename = "locks/{env_name}.lock"
    
  • hatch.toml

    [envs.<envName>]
    type = "pip-compile"
    lock-filename = "locks/{env_name}.lock"
    

Changing the lock filename to a path in the project root:

  • pyproject.toml

    [tool.hatch.envs.lint]
    type = "pip-compile"
    lock-filename = "linting-requirements.txt"
    
  • hatch.toml

    [envs.lint]
    type = "pip-compile"
    lock-filename = "linting-requirements.txt"
    
pip-compile-hashes

Whether to generate hashes in the lockfile. Defaults to true.

  • pyproject.toml

    [tool.hatch.envs.<envName>]
    type = "pip-compile"
    pip-compile-hashes = true
    
  • hatch.toml

    [envs.<envName>]
    type = "pip-compile"
    pip-compile-hashes = true
    
pip-compile-args

Extra arguments to pass to pip-compile. Custom PyPI indexes can be specified here.

  • pyproject.toml

    [tool.hatch.envs.<envName>]
    type = "pip-compile"
    pip-compile-args = [
        "--index-url",
        "https://pypi.org/simple",
    ]
    
  • hatch.toml

    [envs.<envName>]
    type = "pip-compile"
    pip-compile-args = [
        "--index-url",
        "https://pypi.org/simple",
    ]
    
pip-compile-verbose

Set to true to run pip-compile in verbose mode instead of quiet mode.

Optionally, if you would like to silence any warnings set the pip-compile-verbose option to false.

  • pyproject.toml

    [tool.hatch.envs.<envName>]
    type = "pip-compile"
    pip-compile-verbose = true
    
  • hatch.toml

    [envs.<envName>]
    type = "pip-compile"
    pip-compile-verbose = true
    

Notes

Dev Dependencies

Using the default hatch configuration, dev dependencies listed in your default environment (like pytest) will be included on the default lockfile (requirements.txt). If you want to remove your dev dependencies from the lockfile you must remove them from the default environment on your pyproject.toml / hatch.toml file.

Manual Installation

If you want to manually install this plugin instead of adding it to the [tool.hatch.env] table, you can do so with pipx:

pipx install hatch
pipx inject hatch hatch-pip-compile

Alternatively, you can install it with pip:

pip install hatch hatch-pip-compile


Check Out the Docs

Looking to contribute? See the Contributing Guide

See the Changelog




logo

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

hatch_pip_compile-1.0.2.tar.gz (135.0 kB view hashes)

Uploaded Source

Built Distribution

hatch_pip_compile-1.0.2-py3-none-any.whl (7.6 kB view hashes)

Uploaded Python 3

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