<#18197 `./pants run dir/file.py` that has multipl...
# github-notifications
q
#18197 `./pants run dir/file.py` that has multiple pexes fails with `TooManyTargetsException` with unhelpful error message Issue created by huonw Describe the bug If a Python file is both: 1. part of a
python_sources()
without a name 2. the entry point of multiple `pex_binary`s (this happens in practice with docker builds https://blog.pantsbuild.org/optimizing-python-docker-deploys-using-pants/, one PEX with
include_sources=False, include_requirements=True
and one with the
include_sources=True, include_requirements=False
)
Copy code
# dir/BUILD
python_sources()
pex_binary(name="pex1", entry_point="x.py")
pex_binary(name="pex2", entry_point="x.py")
running that Python file directly is awkward:
pants run dir/x.py
complaints and lists out the original
dir/x.py
input as a "better" target to choose from:
Copy code
TooManyTargetsException: The `run` goal only works with one valid target, but was given multiple valid targets:

  * dir/x.py
  * dir:pex1
  * dir:pex2

Please select one of these targets to run.
The correct way to run it is
pants run dir/x.py:dir
. The first line of the error message should thus say
dir/x.py:dir
instead of
dir/x.py
. (If the
python_sources
is given an explicit name, e.g.
name="dir"
, the error message is fine.) Reproducer: https://gist.github.com/huonw/73b947b318b115a298f0bcf57e6a0d51
Copy code
git clone <https://gist.github.com/73b947b318b115a298f0bcf57e6a0d51.git>
cd 73b947b318b115a298f0bcf57e6a0d51
./run.sh
Pants version 2.14.0, 2.15.0rc3, 2.16.0.dev6 OS macOS Additional info https://gist.github.com/huonw/73b947b318b115a298f0bcf57e6a0d51 pantsbuild/pants