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

elegant-salesclerk-19767

03/06/2023, 8:02 PM
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

enough-analyst-54434

03/06/2023, 8:08 PM
Do you use relative imports? Focusing on the
.
literal in the message.
e

elegant-salesclerk-19767

03/06/2023, 8:09 PM
I also don’t understand the BUILD file
e

enough-analyst-54434

03/06/2023, 8:10 PM
One thing at a time please.
e

elegant-salesclerk-19767

03/06/2023, 8:10 PM
Where is No source root found for
.
coming from?
e

enough-analyst-54434

03/06/2023, 8:11 PM
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

elegant-salesclerk-19767

03/06/2023, 8:12 PM
Nope
from config.app_config import AppConfig
e

enough-analyst-54434

03/06/2023, 8:12 PM
Thank you.
Can you provide an open example of this structure? That's always easiest.
e

elegant-salesclerk-19767

03/06/2023, 8:13 PM
So backend/sync.py needs to include config/app_config
e

enough-analyst-54434

03/06/2023, 8:17 PM
Do you have code not in
src/python
or
test/python
? You removed the default source roots and those include
/
- that might explain
.
e

elegant-salesclerk-19767

03/06/2023, 8:20 PM
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

enough-analyst-54434

03/06/2023, 8:22 PM
What version of Pants and what is the contents of the BUILD file closest to that file you want to run?
But yes!
e

elegant-salesclerk-19767

03/06/2023, 8:23 PM
pants_version = “2.15.0”
e

enough-analyst-54434

03/06/2023, 8:23 PM
You elided your full command line in the OP - always good not to elide.
e

elegant-salesclerk-19767

03/06/2023, 8:23 PM
BUILD all got populated with the same thing
python_sources()
e

enough-analyst-54434

03/06/2023, 8:23 PM
Ok looks good (in combo with Pants 2.15.0)
So what is your full command line + full output then?
e

elegant-salesclerk-19767

03/06/2023, 8:25 PM
Screenshot 2023-03-06 at 3.24.59 PM.png
e

enough-analyst-54434

03/06/2023, 8:26 PM
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

elegant-salesclerk-19767

03/06/2023, 8:26 PM
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

enough-analyst-54434

03/06/2023, 8:28 PM
Name is totally arbitrary.
The author liked it, nothing more.
e

elegant-salesclerk-19767

03/06/2023, 8:29 PM
its used in references elsewhere?
e

enough-analyst-54434

03/06/2023, 8:29 PM
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.
2 Views