Hello all, I’ve been trying to suppress some warni...
# general
d
Hello all, I’ve been trying to suppress some warnings when importing a transitive dependency in my project. In my
requirements.txt
I have the
scipy
dep, which itself has
numpy
as dependency
Copy code
scipy==1.10.1
I have a little script that imports both packages
Copy code
import scipy
import numpy

print(scipy.__version__)
print(numpy.__version__)
I ran
pants tailor ::
and this gives me my
BUILD
file.
Copy code
python_requirements(
    name="reqs0",
)

python_sources(
    name="root",
)
When I run
pants run script.py
I get the following warning
Copy code
17:38:20.11 [WARN] Pants cannot infer owners for the following imports in the target //script.py:root:

  * numpy (line: 2)

If you do not expect an import to be inferrable, add `# pants: no-infer-dep` to the import line. Otherwise, see <https://www.pantsbuild.org/v2.15/docs/troubleshooting#import-errors-and-missing-dependencies> for common problems.
1.10.1
1.24.3
What’s the best way to go about suppressing this error correctly? Is the only way to add
numpy
explicitly in my
requirement.txt
file or
pyproject.toml
file here? Or is there another way to tell pants “numpy is a transitive dependency of scipy” so use that.
r
You will have to add numpy as an explicit 3rd party dependency if you are importing it anywhere in your code. Otherwise yeah pants will keep complain until you ignore it as suggested by pants.
e
@dazzling-elephant-33766 what is the motivation for not declaring a direct dependency?
d
@enough-analyst-54434 mostly lazyness. But also I guess I’m concerned what would happen if Scipy alters it’s numpy requirements, then further down the line my lockfile resolution might end up failing and I’ll have to bump my own version. All of which feels like it could be avoided
e
If your code doesn't care about version say
numpy
. If it does, add a version constraint. If your version constraint ends up conflicting with scipy's and fails a resolve at some point, that's excellent! You found out as fast as possible you have a real issue.