ancient-lawyer-12557
01/03/2024, 6:13 PMpex_binary
targets had entry_point="foo/src/main.py"
and entry_point="bar/src/main.py"
- each referring to a different main.py
file in their projects.
As long as there was just one of said binaries the PEX built just fine, presumably because there was just a single main
module on the path. Pants inferred the right dependency and included it in the resulting pex file. However, as soon as a second project with a main
module on the path appeared, pants no longer inferred the dependency and produced an empty PEX file - which we only noticed when trying to run the empty pex: ImportError: No module named main
The surprising thing for me here was that pants package
didn't fail. If I use an entry_point pointing at a file that doesn't exist at all, pants package
rightfully fails with an error. But I was surprised that it didn't fail when the entry_point reference is ambiguous - the error appeared at runtime.
The fix in our case was to add explicit dependencies=["foo/src/main.py:lib"]
and dependencies=["bar/src/main.py:lib"]
to the pex binary targets, and pants does the right thing. Is this expected? Is there some way to ensure that pants will not silently drop an inferred dependency when using a file path for the entry_point?
(python 3.11, pants 2.18.1, macOS Sonoma on ARM)ancient-lawyer-12557
01/03/2024, 7:15 PMcareful-address-89803
01/06/2024, 6:45 PMcurved-dog-69256
01/09/2024, 2:59 PMservice_a
was created using a main
entry point, no explicit dependencies declared. This worked.
service_b
was then added with a main
entry point which resulted in a No module named main
error without the explicit dependencies declared in service_b
. This meant we declared explicit dependencies for service_b
but we were unaware that this would affect service_a
at this time.
At a later date, service_a
got rebuilt but now had an ambiguous entry point. Since it was built in CI the warning went unnoticed and the service was deployed with an empty pex.
Is there a reason that an ambiguous entry point isn't an error here? The warning message even says that pants can't resolve the dependency safely and advises manual action be taken so it feels like it should make a bit of noise (or we should be able to make it make a bit of noise i.e. error)careful-address-89803
01/10/2024, 4:48 PMhappy-kitchen-89482
01/10/2024, 9:19 PMhappy-kitchen-89482
01/10/2024, 9:21 PMunowned_dependency_behavior
careful-address-89803
01/10/2024, 9:25 PM