Heyo! A question about dependency inference. I hav...
# general
f
Heyo! A question about dependency inference. I have a Dash app build sort of like this
Copy code
my_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
Copy code
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
Copy code
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
*
Copy code
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.
g
I think the missing link here is that
python_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.
(Consider what would happen with a default
python_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.)