I'm in the process of incremental adoption of pant...
# general
b
I'm in the process of incremental adoption of pants in our repo. I have
lint
working and I'm trying to get
check
working. It's failing due to ambiguous dependencies. We have the source code for a few python packages in this repo, so we do have multiple requirements.txt files with overlapping dependencies. We currently build one virtualenv which includes all requirements so I don't think there are any conflicts. We use this virtualenv to do typechecking and run tests. Is it possible to tell pants to use the correct requirements.txt file based on the directory structure so that I can enable
check
without breaking our existing build?
b
There's two ways to do this: 1. use resolves to have separate requirements files, and set the appropriate resolve per target: https://www.pantsbuild.org/docs/python-third-party-dependencies#warning-multiple-versions-of-the-same-dependency (potentially using `__defaults__`s to set it for a whole subtree) 2. only import one set of requirements and use it for the whole repo, e.g. add a parent requirement file that just has lines like
-r path/to/requirements.txt
,
-r another/path/requirements.txt
, and only one
python_requirements(...)
target in the whole tree The second one is likely to be simpler/smoother (having a single set of dependencies for the majority of the repo).
b
Thanks! How do I tell pants tailor to ignore some requirements files?
b
I think you can set some settings in
pants.toml
, either: 1.
[python] tailor_requirements_targets = false
https://www.pantsbuild.org/docs/reference-python#tailor_requirements_targets to ignore all requirements files by default (and then add the targets manually, as required) 2.
[tailor] ignore_adding_targets = [...]
https://www.pantsbuild.org/docs/reference-tailor#ignore_adding_targets to ignore specific ones I'd probably go with 1, I think
h
With #2 Pants won't parse those included requirements, afaik, so I don't think that will work?
I think Pants ignores
-r
lines because it expects the included requirements files to have their own
python_requirements()
targets
b
Ah, oops, sorry for the misleading evidence (I’ve recently done a poetry integration rather than a requirements.txt one)
h
But - Pants 2.16 resolves dep inference ambiguity based on source roots
So code in a given source root will take the dep provider from the same source root
but I'm not sure that works for python_requirements, it was designed to solve a problem with first party code inference, so I'll need to check
OK, it should work for 3rdparty deps, but you'll need to set
Copy code
[python-infer]
ambiguity_resolution = "by_source_root"
In pants.toml
b
It doesn't look like pants follows
-r
in requirements.txt. I ended up concatenating all the requirements file into one and telling pants to ignore the originals.
Is there a way to add a shell command as a dependency to
python_requirements
?
h
Yes, Pants doesn't follow
-r
, but in 2.16 you can use the ambiguity resolution strategy I outlined above and have
python_requirements()
targets for each of your requirements.txts