https://pantsbuild.org/ logo
a

ambitious-student-81104

09/15/2021, 3:15 PM
Hi Pants! Is there a quick way to specify "all targets in and under this directory", like how we can
./pants test ::
at the top level?
./pants goal path/to::
does not seem to work.
c

curved-television-6568

09/15/2021, 3:23 PM
What does pants say? Seems to work for me..
Copy code
$ ./pants list tests::
tests/python/pants_test/init
tests/python/pants_test/init:tests
tests/python/pants_test/integration
tests/python/pants_test/integration:build_ignore_integration
tests/python/pants_test/integration:goal_rule_integration
tests/python/pants_test/integration:graph_integration
...
a

ambitious-student-81104

09/15/2021, 3:33 PM
I want to use it in a dependency, like
dependencies=["path/to/module::", ]
and it said
InvalidTargetName: Address spec path/to/module:: has no name part.
but
./pants list
on a path to modul works
c

curved-television-6568

09/15/2021, 3:35 PM
Perhaps globs work in dependencies?
dependencies=["path/to/module/**"]
?
a

ambitious-student-81104

09/15/2021, 3:37 PM
DM'ed
šŸ‘ 1
glob also doesn't work. hit
Copy code
Target path/to/module's `sources` field does not match a file path/to/module/**.
@happy-kitchen-89482 Any suggestions?
h

happy-kitchen-89482

09/15/2021, 3:41 PM
Ah yes,
./pants goal path/to::
works on the cmd line, but not in dependencies
You have to enumerate each dependency
šŸ™ 1
You can create an aggregator target (of type
target
, that has as its
dependencies
all the underlying targets) and then depend on that, so at least you only have to enumerate once.
And if this is a common thing, you could create a custom macro that does this expansion
a

ambitious-student-81104

09/15/2021, 3:43 PM
thank you @happy-kitchen-89482! My use case was that I was trying to create a whl of a library
h

happy-kitchen-89482

09/15/2021, 3:43 PM
I'm not sure if our current macros would support this, but the upcoming "target generators" probably could
a

ambitious-student-81104

09/15/2021, 3:43 PM
but if pex works i don't have to use a whl, hence i was also asking if i can load pex to the environmetn too
h

happy-kitchen-89482

09/15/2021, 3:43 PM
@hundreds-father-404 right?
Is pex not working?
Also, is dep inference not working? usually that cuts down explicit dependencies to (almost) zero
āž• 1
What is the example of needing these globs?
a

ambitious-student-81104

09/15/2021, 3:47 PM
pex is working, i was wondering if other than just running pex, we can also load pex into the environment, like how we load it to notebook
is dep inference not working?
It does not include the subdirectory targets under
path/to/module
What is the example of needing these globs?
building a whl of a library
h

hundreds-father-404

09/15/2021, 3:50 PM
I'm not sure if our current macros would support this, but the upcoming "target generators" probably could
Yeah. You'll soon have two options: a macro https://www.pantsbuild.org/docs/macros which is really limited but sometimes all you need, or creating a "target generator" which can access the full Rules API. Meaning you can do things like run a process or read from the filesystem
a

ambitious-student-81104

09/15/2021, 3:51 PM
so just this should work for now?
Copy code
target(name="lib_name", dependencies=[<output of ./pants list path::>])
h

hundreds-father-404

09/15/2021, 3:54 PM
It does not include the subdirectory targets underĀ path/to/module
Hm, you shouldn't need to explicitly depend on every target you want included due to transitive dependencies. For example, if you add
dependencies=["src/py/project:app"]
, and that itself already depends on
src/py/project/util
etc (e.g. via dependency inference), then you will pull in that dependency transitively Does
./pants dependencies --transitive path/to:python_distribution
already have some things you want, or it's missing everything?
a

ambitious-student-81104

09/15/2021, 4:01 PM
that itself already depends onĀ 
src/py/project/util
Pants thinks it doesn't depend on its submodules. the
__init__.py
files are empty, not explicitly importing submodules.
./pants dependencies --transitive path/to:python_distribution
It has some things I want but missing some others
e

enough-analyst-54434

09/15/2021, 4:32 PM
That implies your code uses a plugin system or other dynamic import mechanism? Otherwise dependency inference should generally follow all your imports and link those deps in.
h

happy-kitchen-89482

09/15/2021, 5:10 PM
Yeah, curious how this code is being used? It may be possible to tweak dep inference to do the right thing.
For example, you could try turning on "string imports": https://www.pantsbuild.org/docs/reference-python-infer#section-string-imports
a

ambitious-student-81104

09/15/2021, 8:22 PM
Thanks for the reply, all! Will take a deeper dive into this later
2 Views