Hi, I’ve a dependency inference question when runn...
# general
b
Hi, I’ve a dependency inference question when running tests - 🧵
I’ve a deps A, B listed in my requirements.txt. B is an 
extra_requires
 dependency of A.
There is a test that imports A, but not B
Pants seems to ignore B when it creates the requirements.pex resulting in a test failure
(pants 2.4.0)
h
Hello! If it is an
extra_requires
, then you would want to update your
requirements.txt
to say
my_req[the_extra]
, rather than
my_req
. Otherwise Pants won't install that extra for you
b
ah, got it. Thanks
Will pants detect the change in the
requirements.txt
file and build a new requirements.pex?
h
Yes, it should, and please let us know if you are seeing differently
b
It did not. I had to clear the ~/.cache/pants directory for it to pick up the requirements.txt change
also, I used the
req[extra_req]
format. But the test that depends on
extra_req
still failed
Copy code
14:42:29.24 [INFO] Completed: Building requirements.pex with 2 requirements: CherryPy[routes], six
h
It did not. I had to clear the ~/.cache/pants directory for it to pick up the requirements.txt change
Hm, where is your
requirements.txt
located in your repo?
b
I’ve a requirements.txt for reach namespaced pkg
so
src/python/ns/pkg-1/requirements.txt
and
src/python/ns/pkg-2/requirements.txt
.
ns
being the namespace.
and there is a
BUILD
file with
python_requirements
at root of both packages
h
Cool, thanks. I see why the invalidation didn't happen, indeed that's a bug. You can this to your
pants.toml
as a temporary workaround
Copy code
[GLOBAL]
pantsd_invalidation_globs.add = ["**/requirements.txt"]
This is a long standing bug that causes the pants daemon to not be invalidated properly.
~/.cache/pants
shouldn't be the issue, but the daemon is memoizing things such that even wiping that folder wouldn't invalidate things because it's still memoized Please try running the test again with that change made
b
I still see a test failure
h
What does
./pants dependencies path/to/test.py
show? You said the requirement you do import is showing up, right? Solely to get the test working, you can try adding to the
dependencies
field that other req that isn't being installed. It will help confirm what the issue is:
Copy code
python_tests(..., dependencies=["src/python/ns/pkg-2:dep_b"])
b
./pants dependencies
lists the source file that the test imports
It works if I add the extra dependency explicitly in the requirements.txt and also add it to the
python_tests
target in the pkg BUILD file