Hi Pants! Is there a quick way to specify "all tar...
# general
a
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
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
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
Perhaps globs work in dependencies?
dependencies=["path/to/module/**"]
?
a
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
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
thank you @happy-kitchen-89482! My use case was that I was trying to create a whl of a library
h
I'm not sure if our current macros would support this, but the upcoming "target generators" probably could
a
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
@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
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
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
so just this should work for now?
Copy code
target(name="lib_name", dependencies=[<output of ./pants list path::>])
h
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
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
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
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
Thanks for the reply, all! Will take a deeper dive into this later