Hi! I recently upgraded from 2.17 to 2.18 and now...
# general
w
Hi! I recently upgraded from 2.17 to 2.18 and now have huge problems with dependency inference. Python imports that worked great in 2.17 are broken under 2.18. I think I've followed the upgrade guidance appropriately, but perhaps I missed something.
b
Are you using the Rust parser?
b
Sorry for the trouble! Do you have an example of the change in behaviour? And the relevant code?
w
Hi! Thanks for the help! Got pulled into a meeting shortly after messaging you. Please allow me to get back to you after we wrap
f
Josh, have we added support for no deps infer pragmas?
b
To the Rust parser? Yes
And it's heavily tested 🙂
1
f
That wasn't supported in the Rust parser initially
f
I remember there were some discrepancy in the inferred deps in my codebase, too, need to test on the latest version
Interesting, I remember it said there was no support for pragmas in the change log
w
Alright - I'm back - thank you for your patients! Very basic example: I have openpyxl in my 3rdparty/python/requirements.txt file. I have lockfile generation enables and re-generated lockfiles In my working folder, let's call it foo/explore.py I have: import pyxl print('hello world') print(dir(openpyxl)) in BUILD I have: python_sources(name="libs") When I execute: pants run foo/explore.py I get: ModuleNotFoundError: No module named 'openpyxl'
If I modify my BUILD file to be: python_sources( name="libs", dependencies=["3rdparty/python:reqs#openpyxl"] ) Then it works.
Under 2.17 manually specifying the dependency was not required.
b
Can you try:
pants --no-python-infer-use-rust-parser dependencies <python file>
and then
pants --python-infer-use-rust-parser dependencies <python file>
without the dependency in the
BUILD
file?
w
Trying now!
Alright - your first command led me to the issue - There was a second requirements file referencing openpyxl in the repo. I removed the second and now it seems happy.
openpyxl is conditionally imported deep inside pandas when using xlsx files, and the conditionality makes it hard for pants infer the dependency. Looks like I created this error while trying to convince pants of the dep. Is using the raw dependency in the BUILD file the best way to handle this situation, in your opinion?
b
You could tel Pants that
pandas
depends on
openpyxl
w
Ahh that makes good sense.
I'll give take that as an "exercise for the reader" and reach back if I get stuck.... That said, I have one further dependency issue for which I still need help.
I have a package I write that has an
__init__.py
that imports a py file in the directory into the namespace, e.g.:
from . my_lib import *
In 2.17 pants recognized my_lib.py as a dependency and copied into the sandbox and everything worked fine. In 2.18, pants no longer see my_lib.py as a dep of
__init__.py
and does not copy my_lib.py into the sandbox. Python error is thus my_lib.py not found. Any thoughts on resolving this one?
b
Can we try the above commands again, but with the init?
w
absolutely - i'm on it
Interesting, that lists the expected dependencies.
b
Both commands?
w
stand by
Good call, the second command does not list the my_lib.py file
b
Congrats! You might've found a bug in the Rust-based dependency inference parser 🙂
w
Glad to help!
b
For now, you can set
[python-infer].use_rust_parser = False
in your
pants.toml
Also, mind filing an issue with the relevant info?
w
I'd be glad to file a bug, via github?
b
w
Excellent! I will do that. Let me try to reproduce the error in clean, simple repo and provide that with the bug report.
b
❤️
w
Thank you for your help! Loving pants - I plan to reach out to Benjy before end of year about our company becoming a sponsor.
❤️ 2
🙏 2
The pyhon-infer pants.toml mod got me past the issue - thank you!