fancy-policeman-6755
05/07/2024, 11:24 AMmy_app/
+-- app.py
+-- pages/
+-- page1.py
+-- page2.py
The modules page1.py
/ page2.py
are not explicitly imported anywhere - they don't even appear as strings, since Dash does some dynamic loading shenanigans. This means I have to tell pants to include them anyways. If in my build file I do this
python_sources(
name="app_src",
sources=["my_app/**/*.py", "!my_app/pages/*.py"],
dependencies=[":pages"],
)
python_sources(
name="pages",
sources=["my_app/pages/*.py"],
)
everything works. If instead I just do
python_sources(
name="app_src",
sources=["my_app/**/*.py"],
)
it doesn't (I can see the files are indeed not included by running with pants run --keep-sandboxes=always my_app/app.py
). This doesn't either, so I don't think it's about the **
vs *
python_sources(
name="app_src",
sources=["my_app/**/*.py", "my_app/pages/*.py"],
)
I can go with the first version, I'm just trying to understand what's going on.gorgeous-winter-99296
05/07/2024, 7:28 PMpython_sources
isn't a "real" target. In Pants parlance, it's a target generator. When evaluated, it expands to one actual target per matched source. Then, Pants dependency inference will handle those individually -- and you end up with no dependency inference again.
When you create an explicit dependency, that ensures that all those expanded per-page-sources are picked up as dependencies regardless of the app sources.gorgeous-winter-99296
05/07/2024, 7:30 PMpython_sources()
in a directory... if that implied a dependency on all files matched -- default *.py
-- it'd make the dependency inference practically useless as you'd pull in whole directories whenever you depended on a single module.)