Is there a trick? or something I am missing?
# general
n
Is there a trick? or something I am missing?
e
What do you mean by namespace/pathing - are you referring to python namespace packages? You'll need to provide a bit more detail of the errors you encountered before coming to the solution of one BUILD file to make this more clear.
n
So for example, if I have a file that I want to import into a python file like
from foo.bar import helloworld
I find myself having to have a
BUILD
file at the parent of
/foo
instead of
/foo/bar/BUILD
In order to keep that pathing.
e
Aha - @brief-engineer-67497's line of questioning is related. Pants expects code to be housed under "source roots"; ie
src/python
. When it can't auto-guess your source roots, it assumes the source root is where the BUILD file lives. I'm guessing your repo layout is:
Copy code
foo/
  __init__.py
  bar/
  __init__.py
setup.py
The source roots can be configured in pants.ini but I'm not sure off the top of my head if there is a way to say the root of the repo is the source root.
Just a sec - checking on this...
n
Thanks I know its a config issue
Do you know where in the documentation its saying this?
e
There is mention of source roots in the setup docs, but it's not super helpful for your case: https://www.pantsbuild.org/setup_repo.html
b
hmm so the "root" of code source and resources are somewhat bind ?
e
no
You can have an arbitrary number of source roots
When packaging code, pants follows dependency links in BUILD files and subtracts off source roots from paths to make bundles - jars, wheels, etc
b
ok so given
Copy code
register('--source-root-patterns', metavar='<list>', type=list, fingerprint=True,
             default=cls._DEFAULT_SOURCE_ROOT_PATTERNS, advanced=True,
             help=pattern_help_fmt.format('source'))
how do I now what is the scope in pants.ini ?
is it like
Copy code
[source]
rout-patterns: [<val>]
?
e
It's non-trivial. If you drop the leading
--
and convert
-
to
_
, you can always:
Copy code
$ ./pants options | grep source_root_patterns
source.source_root_patterns = ['src/*', 'src/main/*'] (from HARDCODED)
So it's:
Copy code
[source]
source_root_patterns: [<vals>]
b
hmm nice trick ! thank you very much
n
Oh okay I’ll test that out later today
thanks
e
Test out what? I'm not sure how to solve your problem @nutritious-monkey-78516
b
I'm really surprise to learn that the BUILD file do not decied of what is the root of sources
e
Stepping back, on of the main thrusts of pants from day one was to be able to take a large source tree and divide it up into fine grained targets. In this case you have 1 source tree with many (hundreds or thousands) of build files down in the tree. In that case the BUILD files do not live in the source root - it's seperate up higher, at - say - src/java.
n
Trying out the source_roots thing in my
pants.ini
b
and It explain why intellij is messed up for "play" project that somewhat decided that sources should be under an
app
directory
n
I think that’s what I am trying to get to.
e
OK. I don't follow the details - but Intellij has the exact same concept. You mark directories source roots, test roots, resource roots, etc.
n
Yeah, I think if I adjsut the pants.ini source_root I can import everything correctly instead of having one bloated
BUILD
file that is pulling everything in.
e
@nutritious-monkey-78516 the magic is:
Copy code
[source]
source_roots: {
    '': ['python']
  }
n
Okay thanks I’ll play around with that tonight
Is that anywhere in the documentation?
e
No
I'm of two minds about this. Clearly it should be documented as things stand since your layout is the typical python project layout sans-pants. Better would be for pants to understand this layout out of the box. I'll file an issue either way here shortly.
n
I just tried this into my pants.ini and its giving me errors.
Actually I think it has to do something with the parsing of the string. I have to put it into one line.
e
The spacing in my example is significant to be sure. all continuation lines must be indented.
n
Yeah, I’ll try out with the spacing, but I just made everything one line, and it worked.
Okay, I got it to work. I think, my stuff was doing the indents at two-spaces