Skip to main content

Convert requirements files to pyproject.toml format used in uv

Project description

depcon

   |                             
 __|   _    _   __   __   _  _   
/  |  |/  |/ \_/    /  \_/ |/ |  
\_/|_/|__/|__/ \___/\__/   |  |_/
         /|                      
         \|                      

depcon is a tool designed to simplify the migration of dependency specifications from traditional requirements.txt, requirements.in, requirements-dev.txt, and requirements-dev.in files into the modern pyproject.toml format created using the uv or hatch tools. This allows for a streamlined, standardized, and more maintainable approach to dependency management in Python projects.

Rationale

Traditional requirements.txt files are widely used to manage dependencies in Python projects, but they have limitations:

  • They do not natively integrate with modern Python packaging tools.
  • Managing separate files for base and development dependencies can be error-prone.
  • Adding, updating, or syncing dependencies requires external tools like pip-tools.

By migrating dependencies to pyproject.toml, you can leverage a unified and declarative format for dependency and project configuration. This format is now the standard for Python packaging and works seamlessly with tools like uv.

Installation

You can install depcon using either pipx or uv:

# Install with pipx
pipx install depcon

# Install with uv
uv tool install depcon

You can also run it directly with uvx without installing:

uvx depcon

Usage

depcon integrates into a workflow involving uv for project initialization and management. Here’s how you can use it:

Workflow Overview

  1. Initialize your project with uv init.
  2. Migrate your dependencies with depcon.
  3. Sync and lock your dependencies with uv sync.

Step-by-Step Instructions

  1. Initialize your Project

Start by creating a pyproject.toml file for your project using uv init:

uv init

This will create a pyproject.toml file with basic metadata for your project.

  1. Migrate Dependencies with depcon

Run depcon to migrate dependencies from existing requirements files into your pyproject.toml file. For example:

  • Migrate base dependencies from requirements.txt:
depcon -r requirements.txt

or

depcon -r requirements.in
  • Migrate development dependencies from requirements-dev.txt:
depcon -d requirements-dev.txt

or

depcon -r requirements.txt -d requirements-dev.txt

By default, depcon will add dependencies to the [project.dependencies] section for base dependencies, and to [tool.uv.dev-dependencies] for development dependencies.

  1. Sync and Lock Dependencies

Once dependencies are migrated, sync and lock them with uv:

uv sync

This will resolve, install, and lock all dependencies into a uv.lock or requirements.lock file.

Additional Options

  • Specify requirements.in files for pinned dependency resolution:
depcon -r requirements.in

Benefits of this Workflow

  • Unified Configuration: Manage dependencies and metadata in a single pyproject.toml file.
  • Modern Tools: Leverage the power of uv and other modern packaging workflows.
  • Ease of Use: Simplify the migration and maintenance of dependencies.

Review of command line options

  • -r, --requirements: Path to requirements.txt file
  • -d, --requirements-dev: Path to requirements-dev.txt file
  • -p, --pyproject: Path to target pyproject.toml file (default: ./pyproject.toml)
  • -a, --append: Append to existing dependencies instead of overwriting them

Examples

# Overwrite existing dependencies (default behavior)
depcon -r requirements.txt -d requirements-dev.txt -p pyproject.toml

# Append to existing dependencies
depcon -r requirements.txt -d requirements-dev.txt -p pyproject.toml --append

# Append only base requirements
depcon -r requirements.in -p pyproject.toml --append

# Append only dev requirements
depcon -d requirements-dev.txt --append

Contributing

Contributions are welcome! If you’d like to improve depcon or add features, feel free to submit an issue or pull request on the GitHub repository.

License

depcon is licensed under the MIT License. See the LICENSE file for details.

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

depcon-0.1.6.tar.gz (5.2 kB view details)

Uploaded Source

Built Distribution

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

depcon-0.1.6-py3-none-any.whl (5.3 kB view details)

Uploaded Python 3

File details

Details for the file depcon-0.1.6.tar.gz.

File metadata

  • Download URL: depcon-0.1.6.tar.gz
  • Upload date:
  • Size: 5.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.5.14

File hashes

Hashes for depcon-0.1.6.tar.gz
Algorithm Hash digest
SHA256 9dd67dbe68c6e5f0964da22b8dd9c301c48d9345b61e6f6c9e9e7230ac23efb2
MD5 37c901761ca9f6f4ba92a519dfca8ebb
BLAKE2b-256 5d56ade455da0fee19b65738780b76c5a6144d754474cfd3995379d04f9fa19c

See more details on using hashes here.

File details

Details for the file depcon-0.1.6-py3-none-any.whl.

File metadata

  • Download URL: depcon-0.1.6-py3-none-any.whl
  • Upload date:
  • Size: 5.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.5.14

File hashes

Hashes for depcon-0.1.6-py3-none-any.whl
Algorithm Hash digest
SHA256 114c72430b7d7ba18d2f1a17fcaa8dc1dd5921f19636d3d2ae0d1a6d62ebad19
MD5 78e1cc84d54fad14018c734483b1ffb1
BLAKE2b-256 1500f7611ae7bac40130ac855e80be3762739ccf7b024565aff64c7ead1cf419

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