Hi, in this e.g: I'm creating a package that holds...
# general
a
Hi, in this e.g: I'm creating a package that holds other packages so it's easily installable 🙂 , the thing is that I need to maintain this manually I'm wondering if is there any way to pass a wildcard in dependencies or any way to search for relevant targets and pass them as dependencies
Copy code
python_sources(
    name="lib",
    sources=["scripts/*.py"],
    dependencies=[
        f"{base_path}/package1:lib",
        f"{base_path}/package2:lib",
        f"{base_path}/package3:lib",
        f"{base_path}/packageN:lib"
    ],
)
Copy code
python_sources(
    name="lib",
    sources=["scripts/*.py"],
    dependencies=[
        f"{base_path}/package*:lib", #does not work
    ],
)
c
no, there are no dynamism to dependencies in BUILD files. However, you can use a generic
target
to avoid duplicating the effort of maintaining that list if you have it in multiple places..
Copy code
target(
  name="libs",
    dependencies=[
        f"{base_path}/package1:lib",
        f"{base_path}/package2:lib",
        f"{base_path}/package3:lib",
        f"{base_path}/packageN:lib"
    ],
)

python_sources(.., dependencies=[":libs"])
another option is you can potentially reduce the boilerplate by using a function (or as a macro if you need the same thing in more than one BUILD file):
Copy code
def libs(*names, base_path="src/path/..."):
  for name in names:
    yield f"{base_path}/{name}:lib"

python_sources(.., dependencies=[*libs("package1", "package2", ...)])
a
any way to list/search the targets in BUILD file?
e
Yeah, ask this of the parent dir path containing the BUILD file:
Copy code
pants list the/build/file/is/in/here:
The
:
is like
*
, glob all targets here. The
::
is like
**
, glob all targets here and under recursively.
c
and if you want to see the field values of them as parsed, including inferred dependencies and such, there’s
pants peek
a
I need to do this programmatically, so I can calculate the dependencies inside the same directory tree
Copy code
def search_dependencies(path:str)->list[str]:
    # implementation

python_sources(
    name="lib",
    sources=["scripts/*.py"],
    dependencies=search_dependencies(base_path)
)