A tool to convert uv.lock files to Pipfile.lock.
Project description
uv-to-pipfile
A tool and pre-commit hook to convert uv.lock files to Pipfile.lock format, allowing you to use uv for dependency resolution while maintaining compatibility with Pipenv workflows.
Installation
With pre-commit
Add this to your .pre-commit-config.yaml:
- repo: https://github.com/FlavioAmurrioCS/uv-to-pipfile
rev: v0.0.7 # Use the ref you want to point at
hooks:
- id: uv-to-pipfile
How it works
Packages
The conversion process follows these steps:
uv.locklists packages as an array. We parse all of these and create a dictionary where the key is the package name and the value is the package metadata.- We identify the virtual package which represents the project itself. This lists the dependencies.
- We create a queue with these packages and iterate through them, adding each to the respective section (default or develop).
- We then add their dependencies to the queue and continue processing.
- We repeat the same process for dev packages.
Python Version Detection
The tool determines Python version requirements in the following order:
- Check for a
.python-versionfile in the same directory as theuv.lockfile - Extract the
requires-pythonfield from theuv.lock(ignoring range markers such as>=) - Default to Python 3.11 if no version information is found
Python Version Compatibility
This tool is compatible with Python 3.8 and later versions. The implementation is designed to work seamlessly across different Python environments:
- For Python 3.11+: No additional dependencies are required as
tomllibis included in the standard library - For Python 3.8-3.10: The
tomlipackage is automatically installed as a dependency
The script can be executed in several ways:
- As an installed package via
uv-to-pipfilecommand - Directly as a PEP 723 compliant script using
pipx run,hatch run, oruv run - With Python 3.11+ using standard
python uv_to_pipfile.py
Known Issues and Limitations
uv.lockdoes not provide markers information. Pipenv doesn't seem to mind this omission.uv.lockdoes not list all the hashes for a specific version. Some hashes might be filtered out.- Potential solution: Call the PyPI API to fetch missing hashes
- Challenge: Additional work would be needed to support non-REST pip indexes like Artifactory
- The
_meta.hash.sha256value will be missing from generatedPipfile.lockfiles. This appears to be a hash of the Pipfile and doesn't seem necessary. - Currently, the tool only supports one index. Multi-index support could be added if needed.
- System-specific dependencies might be handled differently:
- For example,
coloramais only needed on Windows machines - It may not be listed in the original
Pipfile.lockbut gets listed inuv.lock - Installing the generated
Pipfile.lockmight install packages not strictly needed on your platform
- For example,
- Dependencies installed in different ways across package sections may have different mappings:
- For example, if
requestsis installed from a git source in main packages and as a transitive dependency from PyPI in dev packages - In Pipenv, it will be listed with the git URL and ref hash in main dependencies but with package name and version in dev dependencies
- Potential fix: Forward metadata from the virtual root package, which would populate the correct fields depending on how it's listed
- For example, if
Development Roadmap
The following enhancements are planned for future releases:
Code Improvements
- Refactor package traversal logic to eliminate code duplication between main and dev package handling
- Move type definitions into a separate module to improve code organization
- Add type validation using Pydantic TypeAdapter to ensure proper type definitions
Testing Enhancements
- Improve test infrastructure by adding direct
uvandpipenvexecution capabilities - Implement integration tests that compare virtual environments created from both
uv.lockandPipfile.lock - Optimize test performance:
- Current approach: Generate
uv.lock, then usepipenv install <deps...>for dependency resolution - Planned approach: Create
requirements.txtfromuvwith pinned versions, then use withpipenv
- Current approach: Generate
Feature Development
- Implement recursive approach for package traversal to simplify marker forwarding
- Add multi-index support for more complex dependency configurations
- Implement PyPI API integration to retrieve missing hashes
- Consider publishing as a PyPI package based on community adoption
Contributing
Contributions are welcome! Feel free to open issues or pull requests on GitHub.
License
MIT
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file uv_to_pipfile-0.0.7.tar.gz.
File metadata
- Download URL: uv_to_pipfile-0.0.7.tar.gz
- Upload date:
- Size: 17.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d028502342615807e0c18152beb1913b377bd8604de94df3ede4cd7abeb6324f
|
|
| MD5 |
ba5c18b8eec37a82209f9cfa7a7b3303
|
|
| BLAKE2b-256 |
1a2552186608ca6c5eaaddba110818ff14c476fe072e4ec4797e55fe5ebf25db
|
Provenance
The following attestation bundles were made for uv_to_pipfile-0.0.7.tar.gz:
Publisher:
main.yaml on FlavioAmurrioCS/uv-to-pipfile
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
uv_to_pipfile-0.0.7.tar.gz -
Subject digest:
d028502342615807e0c18152beb1913b377bd8604de94df3ede4cd7abeb6324f - Sigstore transparency entry: 494975072
- Sigstore integration time:
-
Permalink:
FlavioAmurrioCS/uv-to-pipfile@bb7753b8269bf1f28a6eec90f1e455d1517ccef1 -
Branch / Tag:
refs/tags/v0.0.7 - Owner: https://github.com/FlavioAmurrioCS
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
main.yaml@bb7753b8269bf1f28a6eec90f1e455d1517ccef1 -
Trigger Event:
push
-
Statement type:
File details
Details for the file uv_to_pipfile-0.0.7-py3-none-any.whl.
File metadata
- Download URL: uv_to_pipfile-0.0.7-py3-none-any.whl
- Upload date:
- Size: 11.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
39a86ada0780215e7be9d207222342959caa2b4e3df7ab6d8b9cced852ec708d
|
|
| MD5 |
9d9365a7388a55b6804626b3bd28db9c
|
|
| BLAKE2b-256 |
e4b3983d0a930c482067b97661fd0b5346e33a2b0e1dd45aaacbfcff7d91565a
|
Provenance
The following attestation bundles were made for uv_to_pipfile-0.0.7-py3-none-any.whl:
Publisher:
main.yaml on FlavioAmurrioCS/uv-to-pipfile
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
uv_to_pipfile-0.0.7-py3-none-any.whl -
Subject digest:
39a86ada0780215e7be9d207222342959caa2b4e3df7ab6d8b9cced852ec708d - Sigstore transparency entry: 494975085
- Sigstore integration time:
-
Permalink:
FlavioAmurrioCS/uv-to-pipfile@bb7753b8269bf1f28a6eec90f1e455d1517ccef1 -
Branch / Tag:
refs/tags/v0.0.7 - Owner: https://github.com/FlavioAmurrioCS
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
main.yaml@bb7753b8269bf1f28a6eec90f1e455d1517ccef1 -
Trigger Event:
push
-
Statement type: