
"At Caktus, many of our projects use pip-tools for dependency management. Following Tobias' post How to Migrate your Python & Django Projects to uv, we were looking to migrate other projects to uv, but the path seemed less clear with existing pip-tools setups. Our requirements are often spread across multiple files, like this: $ find requirements/ -type f requirements/test/test.in requirements/test/test.txt requirements/deploy/deploy.txt requirements/deploy/deploy.in requirements/dev/dev.txt requirements/dev/dev.in requirements/base/base.in requirements/base/base.txt"
"In a perfect world, we would have always pinned the versions directly in our .in files. But we're not perfect; sometimes those versions drift, or we forget to update them. Simply importing these with uv add -r does not work well. It either misses pinned versions from our .in files or pins all the sub-dependencies in the .txt files, which we want to avoid. Our ideal solution is in the middle: updating .in files with the specific versions pinned in the corresponding .txt files."
"Create a pinning script We can automate this with a simple Python script. This script reads the versions from a .txt file and applies them to the packages listed in the associated .in file. We prefer this approach because: We don't end up polluting our new pyproject.toml file with a needlessly detailed list of requirements, i.e., by importing the .txt file directly."
Many projects use pip-tools and store requirements across multiple .in and .txt files, causing mismatched or drifting pins. Simply importing requirement files into uv either misses explicit pins in .in files or imports all sub-dependencies from .txt files. The recommended solution is to update .in files with versions extracted from their corresponding .txt files. A Python pinning script can read versions from a .txt and apply them to the associated .in file. This approach preserves a minimal pyproject.toml while carrying forward the project's direct dependency versions. The method only pins direct dependencies; uv may resolve newer sub-dependency versions, which is an accepted trade-off for receiving fixes.
Read at Caktusgroup
Unable to calculate read time
Collection
[
|
...
]