stale-nightfall-29801
11/30/2021, 4:22 PMpex_binary
depends on a python_library
and when it's packed up the pex contains mylib/[python_file_i_need.py | __init__.py]
Which seems fine, I've seen it do this in other places in my codebase and work... BUT in the __init__.py
other parts of mylib
are imported so I'm getting: ModuleNotFoundError: No module named ...
errors. Do I need to explicitly depend on the rest of the library (or at least the part pulled into init_.py ?enough-analyst-54434
11/30/2021, 4:25 PM__init__.py
contents?stale-nightfall-29801
11/30/2021, 4:26 PMenough-analyst-54434
11/30/2021, 4:28 PMenough-analyst-54434
11/30/2021, 4:29 PMstale-nightfall-29801
11/30/2021, 4:32 PMenough-analyst-54434
11/30/2021, 4:34 PMstale-nightfall-29801
11/30/2021, 4:36 PMmylib/python_file_i_need.py
and only that file
But mylib/files_i_dont_need.py
(which init.py import) requires lots of other parts of my monorepo and other libraries... so the pex goes from 10mb to 40mb bundling in dependencies I don't needenough-analyst-54434
11/30/2021, 4:40 PMwitty-crayon-22786
11/30/2021, 5:41 PMwitty-crayon-22786
11/30/2021, 5:42 PM__init__.py
files…? but tailor
makes that a non issue i think.enough-analyst-54434
11/30/2021, 5:42 PMdependencies=["!___init___.py"]
). Thats a lazy unvetted idea though.happy-kitchen-89482
11/30/2021, 5:44 PMwitty-crayon-22786
11/30/2021, 5:44 PMhappy-kitchen-89482
11/30/2021, 6:41 PMhundreds-father-404
12/01/2021, 4:24 PMthat i’m not sure that the original justification for leaving it disabled is still validThe motivation was because before we had the
overrides
mechanism, you would have to create a separate python_library
target specifically for the __init__.py
to avoid metadata for sibling files being set on the __init__.py
.
For example, assume only utils.py
actually needs NumPy and it can't be inferred, so you set this
python_library(dependencies=["//:numpy"])
Now, every single file in that folder and all subdirectories will transitively depend on NumPy because the __init__.py
picked it up and you automatically depend on ancestor __init__.py
files
This was particularly egregious before dependency inference, when you declared everything explicitly in BUILD files. We reverted __init__.py
being on by default for Pants 2.0 because it was hurting caching etc too much with v1 users migrating
--
We don't live in that world anymore. Most people use dep inference now, and overrides
gives you a workaround to the above problem
We should change the default. Or possibly least try to auto-detect the behavior, i.e. only infer if there is content in the file?witty-crayon-22786
12/01/2021, 5:40 PM