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

high-magician-46188

03/27/2023, 3:00 PM
Hi, Can i reference a target from build BUILD file in another if those 2 BUILD files are in adjacent folders? My specific issue is that I have a (Python) package which has implicit dependencies on
.py
files in another package. I thought to solve this by adding the following target in the first BUILD file:
Copy code
"dependencies": [
        ":second-package-sources",  # this refers to all of the '.py' files in the second package
    ],
1
e

enough-analyst-54434

03/27/2023, 3:01 PM
":x" is a shortcut for targets defined in BUILD files in the same directory. For all others, use the full path from the build root, i.e.: "src/python/other/package/dir:second-packages-sources".
h

high-magician-46188

03/27/2023, 3:02 PM
Ooh!
e

enough-analyst-54434

03/27/2023, 3:05 PM
The full form is spelled out here: https://www.pantsbuild.org/docs/targets#target-addresses The abbreviated ":x" form is somewhat weirdly only called out later after switching to talking about sources and dependencies fields.
h

high-magician-46188

03/27/2023, 3:06 PM
I see. Well, that solved it. Do you maybe know if there is a better solution for cases in which a package is a bundle of
py
files that are dynamically imported based an application conditions?
e

enough-analyst-54434

03/27/2023, 3:07 PM
Nope, that's the most straightforward way. Everything else will probably be more complication than its worth.
What's the loading mechanism? Conditional static imports or dynamic string imports?
h

high-magician-46188

03/27/2023, 3:08 PM
dynamic string imports
e

enough-analyst-54434

03/27/2023, 3:08 PM
h

high-magician-46188

03/27/2023, 3:09 PM
The strings are an input that are constructed dynamically too DX
c

curved-television-6568

03/27/2023, 3:11 PM
depending on your use case, there’s support for stevedore plugins in pants most recent versions: https://github.com/pantsbuild/pants/pull/18132 may or may not be suitable for you..
h

high-magician-46188

03/27/2023, 3:14 PM
Will take a look, thanks 🙂
2 Views