Open jasonwbarnett opened 8 months ago
Sorry for the trouble! Reproducer:
cd $(mktemp -d)
cat > pants.toml <<EOF
[GLOBAL]
pants_version = "2.19.0"
backend_packages = ["pants.backend.python"]
[python]
interpreter_constraints = ["==3.*"]
enable_resolves = true
default_resolve = "a"
[python.resolves]
a = "a.lock"
b = "b.lock"
EOF
cat > BUILD <<EOF
python_sources(name="py")
pex_binary(name="pex", entry_point="main.py", resolve="b")
pex_binary(name="pex-explicit-dep", entry_point="main.py", dependencies=[":py"], resolve="b")
EOF
touch main.py
# prepare the resolve
pants generate-lockfiles
# BUG: prints nothing
pants dependencies :pex
# BUG: `ImportError: No module named main`
pants run :pex
# GOOD: `NoCompatibleResolveException` diagnostic
pants run :pex-explicit-dep
Output of bash ./run.sh
:
10:00:57.62 [INFO] Initializing scheduler...
10:01:00.00 [INFO] Scheduler initialized.
10:01:00.04 [INFO] Starting: Generate lockfile for b
10:01:00.78 [INFO] Completed: Generate lockfile for b
10:01:00.79 [INFO] Wrote lockfile for the resolve `a` to a.lock
10:01:00.79 [INFO] Wrote lockfile for the resolve `b` to b.lock
Traceback (most recent call last):
File "/Users/huon/.pyenv/versions/3.7.13/lib/python3.7/runpy.py", line 193, in _run_module_as_main
"__main__", mod_spec)
File "/Users/huon/.pyenv/versions/3.7.13/lib/python3.7/runpy.py", line 85, in _run_code
exec(code, run_globals)
...
File "/Users/huon/.pyenv/versions/3.7.13/lib/python3.7/runpy.py", line 136, in _get_module_details
raise error("No module named %s" % mod_name)
ImportError: No module named main
10:03:03.81 [ERROR] 1 Exception encountered:
Engine traceback:
in `run` goal
NoCompatibleResolveException: The target //:pex-explicit-dep uses the `resolve` `b`, but some of its dependencies are not compatible with that resolve:
* //main.py:py (a)
All dependencies must work with the same `resolve`. To fix this, either change the `resolve=` field on those dependencies to `b`, or change the `resolve=` of the target //:pex-explicit-dep. If those dependencies should work with multiple resolves, use the `parametrize` mechanism with the `resolve=` field or manually create multiple targets for the same entity.
For more information, see https://www.pantsbuild.org/v2.19/docs/python-third-party-dependencies#multiple-lockfiles.
Note that there's no errors or warnings from for the :pex
, main.py
is just silently ignored, resulting in runtime failures. The :pex-explicit-dep
version has an explicit diagnostic, which would be great to see for the entry_point
version too.
I thought that this might have been fixed by https://github.com/pantsbuild/pants/pull/20390 , but it doesn't seem to be. I think the ownership on "main.py" is being ignore and no owners are found since it's not in the resolve, so "main.py" isn't added as a dependency. We then return no owners. We could resolve this by adding a check/warning that some owner was found, probably at this line https://github.com/pantsbuild/pants/commit/13bb69f46b01bd5a28061578834a74d51380538c#diff-4740170d8c26730e2b985731f39b65d20446a0e3ea2def3c82491c3f7c99a17fR306
Describe the bug
I was onboarding a monorepo that has 100's of
pyproject.toml
. I went through the onboarding process withpants tailor ::
which generated all of theBUILD
files. After which I addedpex_binary
to one of theBUILD
files . Then I enabled[python].enable_resolves
and added a couple of new[python.resolves]
and updated theBUILD
file to use the new one I created. When I ran the generated pex binary I was getting an import error. I attempted to manually add thedependencies
at which point pants had a beautiful error message which essentially guided me through adding all of the sub modules to the sameresolve
. After updating them all and re-running pants package the binary worked as expected. I was then able to remove the explicitly defineddependencies
and everything continued to work.My expectation is that if pants detects a dependency isn't using the same
resolve
it should warn about this situation.For more context, this is a full diff of what was required to fix the my issue:
Pants version 2.19
pants.toml
OS MacOS
Additional info
One more note, before updating the
BUILD
files withresolve
pants dependencies --transitive
returned no dependencies.After making the changes described in the diff above, it now shows the correct
dependencies
, even with the explicitly defineddependencies
was removed.