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

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

Installation

pip install hatch-pip-compile

pipx

If you use pipx to install and use hatch you will need to inject the hatch-pip-compile plugin into the hatch environment.

pipx install hatch
pipx inject hatch hatch-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 .hatch/<envName>.lock). 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.

  • pyproject.toml

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

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

Configuration Options

name type description
lock-directory str The directory where the lockfiles will be stored. default env is project root, non-default is .hatch
lock-filename str The filename of the ultimate lockfile. default env is requirements.txt, non-default is <envName>.lock
pip-compile-hashes bool Whether to generate hashes in the lockfile. Defaults to true.
pip-compile-header bool Whether to use the pip-compile header instead of the hatch-pip-compile header, defaults to false
pip-compile-strip-extras bool Whether to strip the extras from the lockfile ensuring it is constraints compatible, defaults to true
pip-compile-args list[str] Additional command-line arguments to pass to pip-compile

Examples

lock-directory

The directory where the lockfiles will be stored. Defaults to the project root for the default environment, and .hatch for non-default environments.

  • pyproject.toml

    [tool.hatch.envs.<envName>]
    type = "pip-compile"
    lock-directory = "requirements"
    
  • hatch.toml

    [envs.<envName>]
    type = "pip-compile"
    lock-directory = "requirements"
    
lock-filename

The filename of the ultimate lockfile. Defaults to requirements.txt for the default environment, and <envName>.lock for non-default environments.

  • pyproject.toml

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

    [envs.lint]
    type = "pip-compile"
    lock-directory = "."
    lock-filename = "linting-lockfile.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",
    ]
    

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.



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-0.2.0.tar.gz (109.7 kB view hashes)

Uploaded Source

Built Distribution

hatch_pip_compile-0.2.0-py3-none-any.whl (6.8 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