https://pantsbuild.org/ logo
#general
Title
# general
p

plain-fireman-49959

11/23/2021, 2:17 PM
Hello, I am a bit confused... I have the following setup: • source_root/org/project/main.py (and other files) • source_root/org/project/submodule_a/[some].py • source_root/org/project/submodule_b/[some].py main.py explicitly imports from both submodules, shouldn't I see them listed when I run
./pants dependencies source_root/org/project
?
c

curved-television-6568

11/23/2021, 2:20 PM
do you see them if you run
./pants dependencies source_root/org/project/main.py
?
p

plain-fireman-49959

11/23/2021, 2:33 PM
when pointing at main.py, I see the same "main module" files, PLUS third party deps imported directly in main (not other imported elsewhere) and a
root_source/org/other_project
init.py. That's probably because I added
Copy code
[python-infer]
inits = true
I can run run with the
--transitive
option and see all the deps, but when running the
check
goal on main.py fails to find implementations or stubs for import in the same folder or in a submodule
c

curved-television-6568

11/23/2021, 3:12 PM
OK, so this feels like it could be an issue with how your BUILD files are setup.. and also, first it seems prevalent to check that the source roots are correctly identified. So, does
./pants roots
give you the correct roots? Related docs: https://www.pantsbuild.org/docs/source-roots
p

plain-fireman-49959

11/23/2021, 3:13 PM
source roots returns
.
and
src
which are correct (I assumed I need
.
for the main poetry pyproject.toml file
I then have BUILD files in
src/org/project, src/org/submodule_a/ and submodule_b
, they only contains
python_sources
macro
c

curved-television-6568

11/23/2021, 3:14 PM
OK, I don’t think you need
.
as you can refer to the pyproject.toml file from configuration alone.
And where do you have
__init__.py
files?
And in main.py, do you import from
org.submodule_a.
etc.. ?
p

plain-fireman-49959

11/23/2021, 3:22 PM
main.py does import from some files in the submodules, which in turn import from other files in same submodule
my init files are in every module folder, they import and expose "public" stuff with
___all___
I'll try to remove the
.
source root!
c

curved-television-6568

11/23/2021, 3:38 PM
I’m headed out, but I’m sure you’ll get excellent help from the team members over in US as they’re about to wake up any time now… 😉
🙌 1
p

plain-fireman-49959

11/23/2021, 3:38 PM
the main thing i'm worried about is that mypy can't seem to follow any import (not even modules in the same folder), I think that's a symptom of some misconfiguration
c

curved-television-6568

11/23/2021, 3:40 PM
ping @hundreds-father-404 perhaps you can take a look when you’re ready.. ?
h

happy-kitchen-89482

11/23/2021, 7:39 PM
Hi! The
.
src root does no harm, as we take the innermost root, in this case
src
What do the imports in
main.py
look like? What is the package root for them?
I.e., is it
import org.project.submodule_a.[some]
for example?
p

plain-fireman-49959

11/24/2021, 10:00 AM
yes, I try to always use absolute imports, as that look clearer to me. I'll check that though
I had some relative imports in the init files (for exposing them in
__all__
). I changed those to absolute and I still get the same result: main only displays direct deps (which might be correct), mypy can't follow any import, but packaging works correctly and builds a working pex.
c

curved-television-6568

11/24/2021, 11:36 AM
Just guessing here… but perhaps you need some config for mypy? From one of my projects, I have:
Copy code
# pants.toml
[mypy]
args = "--namespace-packages --explicit-package-bases"
config = "mypy.ini"
And
Copy code
# mypy.ini
[mypy]
mypy_path = src
show_error_codes = True
To give you some ideas… if at all relevant?
p

plain-fireman-49959

11/24/2021, 11:45 AM
mypy_path
was definitely missing (did not realize that in the example repo the source root was the repo root), I had to use the
args
too. The example repo also uses "absolute" imports but does not seem to need those args... those did fix it however! thank you very much!
👍 1
c

curved-television-6568

11/24/2021, 11:47 AM
Happy it worked out! 😄
p

plain-fireman-49959

11/24/2021, 11:49 AM
another quick question: I need to use some mypy plugins, the correct workflow would be to add them as dev dependencies and add them to the
mypy.ini
, correct? mypy still can't find stubs for a library that needs a plugin for typing, any ideas? am I missing something again? 😄
c

curved-television-6568

11/24/2021, 11:51 AM
This doc section mentions that use case. https://www.pantsbuild.org/docs/python-linters-and-formatters#configuring-the-tools-eg-adding-plugins If it does not help you, we should improve the docs there.. 🙂
🙌 2
I’m not entirely sure how to use type stubs myself… 😉
2 Views