Hi totally new to pants today! Is there someone wh...
# general
e
Hi totally new to pants today! Is there someone who can help with an initial pants setup.. I’m looking at monolithic python app with multiple tools. I’ve gone through some basic pants setups, but I keep running into errors with pants
run backend/sync.py
NoSourceRootError: No source root found for
.``
[source]
root_patterns = ["src/python", "test/python"]
But things like this work..
pants count-loc ::
returns..
e
Do you use relative imports? Focusing on the
.
literal in the message.
e
I also don’t understand the BUILD file
e
One thing at a time please.
e
Where is No source root found for
.
coming from?
e
I'm going to force you to focus on the question above 1st. Do you use relative imports? Focusing on the
.
literal in the message.
I.E.
from . import sibling_module
e
Nope
from config.app_config import AppConfig
e
Thank you.
Can you provide an open example of this structure? That's always easiest.
e
So backend/sync.py needs to include config/app_config
e
Do you have code not in
src/python
or
test/python
? You removed the default source roots and those include
/
- that might explain
.
e
ok.. I removed my sources definition and picked up default
Copy code
pants roots 
.
src
src/python
Copy code
pants dependencies --transitive src/python/backend/sync.py
3rdparty/python/requirements.txt:reqs
3rdparty/python:reqs#psutil
src/python/config/app_config.py
That looks good
How do I run “pants run backend/sync.py” ?
Do I need to use ‘pants run src/python/backend/sync.py’ ?
e
What version of Pants and what is the contents of the BUILD file closest to that file you want to run?
But yes!
e
pants_version = “2.15.0”
e
You elided your full command line in the OP - always good not to elide.
e
BUILD all got populated with the same thing
python_sources()
e
Ok looks good (in combo with Pants 2.15.0)
So what is your full command line + full output then?
e
Screenshot 2023-03-06 at 3.24.59 PM.png
e
Yeah - so that's the issue. So please include full command lines - that would have been super obvious to support from the get go. You must use full path to the file.
👍 1
And screen shots are not awesome for support.
So I think you original source roots were good. The issue was not using a full path.
e
You must use full path to the file.
Thanks this is very helpful
I think I will figure things out.. last question was why in BUILD examples this was used/
python_sources(
name="lib",
)
in the examples? what did ‘lib’ represent as it was not a folder, function, nor anything I could find.
e
Name is totally arbitrary.
The author liked it, nothing more.
e
its used in references elsewhere?
e
I'd guess that back in the day
python_sources
was
python_library
.
Yes. A target address is
path/to/build/parent/dir:target_name
If the name is left empty its assumed to be the same name as the parent dir name.
🙏 1
But targets are relics. You almost never need them. Thats why tailor exists - to get us through a hobbling period where they still exist and are mostly not needed. Dependency inference means most targets are not of your concern. Just your import statements are - aka you don't repeat yourself, you just need to use tailor as the not so dirty secret.
@elegant-salesclerk-19767 are you coming from Bazel experience per chance?
👎 1
Pants can be confusing to different users in very different ways. The strange BUILD files tailor produces can be confusing for Bazel users in particular.