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 hatch, poetry, and uv.

Installation

You can install depcon via pipx or the uvx plugin manager:

# Using uvx
uvx install depcon

# Using pipx
pipx install 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 hatch.lock or requirements.lock file.

Additional Options

  • Specify requirements.in files for pinned dependency resolution:
depcon -r requirements.in
  • Use depcon with different tools (e.g., poetry) by specifying custom behavior (future support planned).

Benefits of this Workflow

  • Unified Configuration: Manage dependencies and metadata in a single pyproject.toml file.
  • Modern Tools: Leverage the power of uv, hatch, and 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)

Examples

depcon -r requirements.txt -d requirements-dev.txt -p pyproject.toml
depcon -r requirements.in -p pyproject.toml
depcon -r requirements.txt 

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.3.tar.gz (4.6 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.3-py3-none-any.whl (4.8 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for depcon-0.1.3.tar.gz
Algorithm Hash digest
SHA256 c85b0a4f3a3e8e0e776bccd48a6a574142793493047f5c770fa19ceab7d29bb4
MD5 121e283b69958cc8854692ecd0f782bb
BLAKE2b-256 38d51f5de01dca95cc3553e44ce0c19785ae212588264a987ade49e34f142880

See more details on using hashes here.

File details

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

File metadata

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

File hashes

Hashes for depcon-0.1.3-py3-none-any.whl
Algorithm Hash digest
SHA256 9226304c16c5ebb4eead994037f7e5655e06c678569f6d6a5b70c4c6dd13fcb2
MD5 71bcce1842f356f1ffe4e11155edcb3a
BLAKE2b-256 4db0edda7908598bc65873f6468a1a19bb742b1d54f2026f7a7a5a4e40213918

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