https://pantsbuild.org/ logo
c

chilly-tailor-75063

01/09/2023, 5:21 PM
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

bitter-ability-32190

01/09/2023, 5:22 PM
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

happy-kitchen-89482

01/09/2023, 5:22 PM
Also, looking at
./pants roots
and seeing if your source roots are what you expect them to be
c

chilly-tailor-75063

01/09/2023, 5:26 PM
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

bitter-ability-32190

01/09/2023, 5:26 PM
Is the modules its failing to import in the list of dependencies?
c

chilly-tailor-75063

01/09/2023, 5:27 PM
Nope
b

bitter-ability-32190

01/09/2023, 5:27 PM
Great! We've found the problem 🙂
So let's find out why 🙂
c

chilly-tailor-75063

01/09/2023, 5:27 PM
Cool!! Though I’m not sure how to resolve it.. 😬
b

bitter-ability-32190

01/09/2023, 5:28 PM
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

chilly-tailor-75063

01/09/2023, 5:30 PM
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

enough-analyst-54434

01/09/2023, 5:30 PM
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

bitter-ability-32190

01/09/2023, 5:32 PM
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

chilly-tailor-75063

01/09/2023, 5:32 PM
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

bitter-ability-32190

01/09/2023, 5:35 PM
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

chilly-tailor-75063

01/09/2023, 5:37 PM
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

bitter-ability-32190

01/09/2023, 5:38 PM
c

chilly-tailor-75063

01/09/2023, 5:42 PM
Thanks for your help again Joshua…
b

bitter-ability-32190

01/09/2023, 5:42 PM
I (and we) just love seeing people succeed with Pants 🙂
c

chilly-tailor-75063

01/09/2023, 5:44 PM
My hope/goal is to get good enough with Pants to “twist some arms” with my team and get some adoption going…. 😉
b

bitter-ability-32190

01/09/2023, 5:47 PM
It is now my hope as well 🙂
c

chilly-tailor-75063

01/09/2023, 5:47 PM
I will keep you updated on the progress of the arm twisting.. 😈