bland-cpu-3662
05/27/2025, 1:10 PMelegant-florist-94385
05/27/2025, 1:26 PMelegant-florist-94385
05/27/2025, 1:27 PMbland-cpu-3662
05/27/2025, 1:34 PMfast-nail-55400
05/27/2025, 1:49 PMfast-nail-55400
05/27/2025, 1:49 PMfast-nail-55400
05/27/2025, 1:50 PMbland-cpu-3662
05/27/2025, 1:55 PMfast-nail-55400
05/27/2025, 2:02 PMfast-nail-55400
05/27/2025, 2:02 PMfast-nail-55400
05/27/2025, 2:04 PMbland-cpu-3662
05/27/2025, 3:30 PMelegant-florist-94385
05/27/2025, 6:10 PMpyproject.toml
file doesn't (directly) play into pants' dependency inference system.
A few concepts to understand:
• python_requirement
target represents a single third party dependency. Usually you create these using python_requirements
(for requirements.txt
) or poetry_requirements
(for pyproject.toml
) target generators, which are just a macro that creates individual python requirement
targets for each dependency in your file(s).
• A resolve
is essentially a "universe" of dependencies. In the default case, any time pants finds a python_requirement
target, it understands that that dependency should belong in the universe, (ie. its part of your resolve
)
◦ It doesn't matter where these requirements are found, they all get pulled into the same resolve. (so if there are multiple pyproject.toml files, they aren't actually separate things, as far as pants is concerned)
◦ A resolve
must be consistent, in terms of compatible versions of dependencies.
• When you try to use a python file (whether by run
, check
, test
, building a pex
, etc.) pants will assume it belongs in your resolve, and interpret imports accordingly.
Typically, I organize my project like:
• 3rdparty/python/pyproject.toml (contains all my dependencies used anywhere)
• 3rdparty/python/my-lockfile.lock (the generated lockfile that contains the exact versions that were resolved, including transitive dependencies)
• src/python/library, src/python/projectA, src/python/projectB, etc. (source code that is free to import anything from the 3rdparty dependencies)
https://www.pantsbuild.org/prerelease/docs/python/overview/lockfiles has more good information on this.
As a note: There are ways to have separate resolves for different projects. Generally, I would only recommend to do this if you need to have conflicting dependencies (eg. if Project A and Project B must use different versions of Django, or something like that.) (remember that its okay to have dependencies that are unused by some projects. the dependency inference will avoid pulling them in where they are not needed).
If you do need a separate resolve for each project, you need to explicitly tell each python_requirement
which resolve it must belong to, and then your source files will also specify which resolve they are compatible with. In the case of a shared library, you would use parametrize
to indicate that it is supposed to be used with both Project A resolve and Project B resolve. (and then it will lint
, check
, test
etc. against each resolve)