Judging by the docs and FAQ, I think this is a fai...
# general
h
Judging by the docs and FAQ, I think this is a fairly common problem due my naive setup -- pants seems to be missing 3rd party python dependencies (requests, pandas, etc.) when testing. for example, a very rough sample of the structure, using two packages
Copy code
pkg1
|_BUILD <contains poetry_requirements>
|_pyproject.toml <specifies dependency on requests>
|_pgk1
  |_BUILD <contains empty python requirements>
  |_source.py <import requests>
pkg2
|_BUILD <contains poetry_requirements>
|_pyproject.toml <specifies dependency on pkg1>
|_pgk2
  |_BUILD <contains empty python requirements>
  |_source.py <uses pkg1.source>
Here, running tests for pkg2 fails because
requests
is missing. From the docs, the solution seems to be to add these dependencies to
BUILD
files rather than relying purely on
tailor
. The only snag is I have way too many
BUILD
files to do this manually? Am I missing an easy solution?
b
pants should be inferring that dependencies are required from statements in the code like
import requests
, so it sounds like that's not working as expected. Some questions: • Can you share your
pants.toml
configuration? • Are there any warnings from pants when you run things? • What does
pants dependencies --transitive
show for the various files?
h
there are many warnings 😅
Copy code
[WARN] Pants cannot infer owners for the following imports in the target llama-index-core/llama_index/core/download/dataset.py:

  * requests (line: 8)
  * tqdm (line: 9)

[WARN] Pants cannot infer owners for the following imports in the target llama-index-core/llama_index/core/llama_dataset/base.py:

  * openai.RateLimitError (line: 9)
  * pandas.DataFrame (line: 10)
  * tqdm (line: 8)
My pants.toml is
Copy code
[GLOBAL]
pants_version = "2.19.0"

backend_packages = [
  "pants.backend.python",
  "pants.backend.experimental.python.lint.ruff",
  "pants.backend.python.typecheck.mypy",
  "pants.backend.python.lint.black",
]

[python]
interpreter_constraints = ['>=3.8.1']

[source]
marker_filenames = ["pyproject.toml"]
I'm guessing I will have to solve the warnings -- but hopefully without manually editing every build file?
b
yes, resolve the warnings should fix this. The focus to resolve them should be on how the external dependencies are loaded, i.e. just the
python_requirement
,
python_requirements
or
poetry_requirements
targets. I'm not in a position to help in detail, but often having duplicate dependencies within a single "resolve" is the problem
h
hmm alright 🤔 thanks!
yea so far, it seems like I'll have to manually update
BUILD
files to remove ambiguity. There's no "unsafe" option for it to just pick the first one in the list right? Might have to write a script to do this for me haha
b
What we do is have a single definition of all our requirements (i.e. one
pyproject.toml
that contains external dependencies), and then there's no ambiguity. You could potentially do this with a new
pyproject.toml
that has all the deps that's imported with a
python_requirements
target, and then delete any other targets (potentially using https://www.pantsbuild.org/2.18/reference/subsystems/python#tailor_requirements_targets to ensure that they're not re-added by
tailor
).