Hi everyone, hope you're well. I recently started ...
# general
g
Hi everyone, hope you're well. I recently started using Pants within my organisation and I am facing some issues with dependencies for tests. I have generated a lockfile using pants generate-lockfiles that generated a lockfile based on my pyproject.toml. However, whenever I run a test I get an error that says "No module named numba", despite numba being within the locked_requirements section of my pants lockfile. Below is my setup, was wondering if anyone has any insight on to this, or can tell me what I'm doing wrong? pants.toml
Copy code
[python]
interpreter_constraints = ["==3.10.*"]
enable_resolves = true
default_resolve = "poetry-lockfile"

[python.resolves]
poetry-lockfile = "poetrylock.lock"
BUILD (in top-level with pyproject.toml)
Copy code
poetry_requirements(name='poetry')
BUILD (in same directory as tests)
Copy code
python_sources(
    name='repo_sources',
    sources=[
        'repo/**/*.py',
    ],
    resolves='poetry-lockfile'
)

python_tests(
    name='tests',
    sources=[
        'tests/**/*.py'
    ],
    resolve="poetry-lockfile"
)
1
g
Does anything actually import numba in your test?
It might be useful to look at the output of
pants peek
,
pants dependencies --transitive
of the test in question to see what Pants thinks.
1
h
Yep, what @gorgeous-winter-99296 is getting at is that Pants uses dependency inference to create sandboxes for your code. If there is no explicit import of
numba
then Pants won’t know to pull it into the sandbox. You can work around this by adding an explicit
dependencies=
to your
python_sources
. Or even better, add it via an
overrides
, so that you’re adding it as a dep of just the file that actually uses it, instead of every file you’re globbing over…
1
But first try adding it as a dep for everything, just to see if it solves things
g
Thank you both, that worked