Skip to main content

Import constraints.txt into pyproject.toml as tool.uv.constraint-dependencies

Project description

uv-import-constraint-dependencies

A CLI tool to import constraints.txt files into pyproject.toml as tool.uv.constraint-dependencies.

Overview

This tool reads a pip constraints file (local or remote) and adds the pinned dependencies to your pyproject.toml in the format expected by the uv package manager.

Installation

uv tool install uv-import-constraint-dependencies

Or with pip:

pip install uv-import-constraint-dependencies

Usage

Basic Usage

Import constraints from a local file:

uv-import-constraint-dependencies -c constraints.txt

Import constraints from a remote URL:

uv-import-constraint-dependencies -c https://example.com/constraints.txt

Options

Option Short Description
--constraints -c Path or URI to constraints.txt file (required)
--pyproject -p Path to pyproject.toml file (default: pyproject.toml)
--custom-constraints --cc Path to local custom constraints file for overriding base constraints
--merge Merge with existing constraint-dependencies instead of replacing
--version Show version information
--help Show help message

Examples

Custom pyproject.toml path:

uv-import-constraint-dependencies -c constraints.txt -p path/to/pyproject.toml

Merge with existing constraints instead of replacing:

uv-import-constraint-dependencies -c constraints.txt --merge

Override base constraints with local customizations:

uv-import-constraint-dependencies -c https://example.com/constraints.txt --cc custom-constraints.txt

Behavior

Replace Mode (Default)

By default, all existing constraint-dependencies in pyproject.toml are replaced with the new ones from the constraints file.

Merge Mode (--merge)

When using --merge, new constraints are merged with existing ones in tool.uv.constraint-dependencies:

  • New packages are added
  • Existing packages are updated with the new version specifier
  • Packages not in the new constraints file are preserved
  • Constraints are sorted alphabetically

Custom Constraints (--cc)

The --cc (or --custom-constraints) option allows you to override specific packages from the base constraints file with local customizations. This is useful when:

  • You use a shared/remote constraints file but need different versions for specific packages
  • You want to test newer versions of certain dependencies without modifying the base file

How it works:

  1. Base constraints are loaded from -c (can be local or remote)
  2. Custom constraints from --cc are merged on top (custom takes precedence)
  3. The combined result is then merged with or replaces existing pyproject.toml constraints (depending on --no-merge)

Example workflow:

# Remote base constraints + local overrides
uv-import-constraint-dependencies -c https://example.com/constraints.txt --cc custom-constraints.txt

Example custom-constraints.txt:

# Override requests version from base constraints
requests==2.32.0

# Add a package not in base constraints
my-internal-package==1.0.0

Constraints File Format

The tool supports standard pip constraints file format:

# Comments are ignored
requests==2.31.0
flask>=2.0.0,<3.0.0
numpy==1.24.3 ; python_version >= "3.9"  # Inline comments are stripped
urllib3>=1.26.0

# Include directives are skipped
-r requirements.txt
-c other-constraints.txt

Output Format

The constraints are written to pyproject.toml as:

[tool.uv]
constraint-dependencies = [
    "flask>=2.0.0,<3.0.0",
    "numpy==1.24.3 ; python_version >= \"3.9\"",
    "requests==2.31.0",
    "urllib3>=1.26.0",
]

Requirements

  • Python >= 3.10

Dependencies

  • click >= 8.0 - CLI framework
  • tomlkit >= 0.12 - TOML manipulation with formatting preservation

License

MIT

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

uv_import_constraint_dependencies-0.1.2.tar.gz (50.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

File details

Details for the file uv_import_constraint_dependencies-0.1.2.tar.gz.

File metadata

File hashes

Hashes for uv_import_constraint_dependencies-0.1.2.tar.gz
Algorithm Hash digest
SHA256 1cc4705d6d75f0149274293a09833963ed1f8480b3f3bfa54d8762a5e45d2c4f
MD5 e9a7113360b8fbccad9e6857e8b6d052
BLAKE2b-256 0aa7b259c7df47c580cf84482ba49b9d2f949819aeff2c3caa5479d79baba2da

See more details on using hashes here.

File details

Details for the file uv_import_constraint_dependencies-0.1.2-py3-none-any.whl.

File metadata

File hashes

Hashes for uv_import_constraint_dependencies-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 0247a071779b057c24f9a26ac4d79edbc5bdc6622a1f573ee7bf5a8fb5c3b4e1
MD5 bfa9492643cb026ee8ec69ab7e684867
BLAKE2b-256 4cc3a8fc2bb9eecdb49609a3de0d3872f0ee15033174692b95578a68936b3a69

See more details on using hashes here.

Supported by

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