Hi all, maybe it’s me, but I continue on my pants ...
# general
c
Hi all, maybe it’s me, but I continue on my pants path of 3 steps forward and 2 back. 😉 I briefly had pants working for me, and I’m not sure what changed, but now when I run
./pants lint ::
it reports a bunch of
E0401: Unable to import
errors for my own custom modules.
b
The first debugging step for me is always "what does Pants think about the world?" In this case, that translates to
./pants dependencies <myfile.py>
and verifying Pants' view of the world is what you expect
h
Also, looking at
./pants roots
and seeing if your source roots are what you expect them to be
c
Thanks, here’s the results of
./pants roots
Copy code
project/app
tests
and
./pants dependencies project/app/v1/models/schedules.py
(one of my modules:
Copy code
project:poetry#fastapi
project:poetry#fastapi-utils
project:poetry#sqlmodel
I think this is what I expect….
b
Is the modules its failing to import in the list of dependencies?
c
Nope
b
Great! We've found the problem 🙂
So let's find out why 🙂
c
Cool!! Though I’m not sure how to resolve it.. 😬
b
Can you give an example of an import that is missing, and where that module exists on disk (if firstparty) or the package (if thirdparty)?
Also, consider setting https://www.pantsbuild.org/v2.15/docs/reference-python-infer#unowned_dependency_behavior to
error
so that Pants hard errors if you have `import`s it can't find the owner of
c
Here’s the last set of messages for a module as reported by lint:
Copy code
************* Module project.app.v1.models.schedules
project/app/v1/models/schedules.py:7:0: E0401: Unable to import 'app.v1.models.shared' (import-error)
project/app/v1/models/schedules.py:8:0: E0401: Unable to import 'app.v1.models.users' (import-error)
The path is the same as the ** Module line
e
There's your answer, you have a bad source root, should be
project
not
project/app
? What is the structure under
porject/app
?
1
b
Remember that source roots can be thought of as the path-prefix that should be added to a module's import name to form the on-disk path. Or put another way, they are entires in
PYTHONPATH
c
Under
project
I have the Dockerfile, poetry.log, pyproject.toml. Under
project/app
I have the actual project code (FastAPI app)
In my code I import with code like this:
Copy code
from app.v1.models.shared import blah, blah, blah
b
So it sounds like your first project root should be
project
. That or you should import using
import v1.models...
Otherwise your code layount and source roots dont agree.
c
Confusing, but okay. I just changed
pants.toml
to have this as my [source]
Copy code
[source]
root_patterns = [
    "project",
    "tests",
]
and
./pans lint ::
runs now… This is interesting to me because I’ve talked with people here before (probably you and Benjy) and have been back and forth about what to set source roots as.
b
c
Thanks for your help again Joshua…
b
I (and we) just love seeing people succeed with Pants 🙂
c
My hope/goal is to get good enough with Pants to “twist some arms” with my team and get some adoption going…. 😉
b
It is now my hope as well 🙂
c
I will keep you updated on the progress of the arm twisting.. 😈