pants: Pex binary errors when depending on a distribution

Describe the bug I have a python_distribution target that can be successfully built. I have a pex_binary target that can also be built. However, when that pex_binary includes the distribution as a dependency, packaging the pex fails.

Here’s an example of what I have with some sensitive information redacted.

resources(name="all_my_things", sources=["<glob pattern for my py modules>"])

python_distribution(
    name="things_distributed",
    provides=python_artifact(name="things", version="0"),
    dependencies=[":all_my_things"],
    entry_points={
        "console_scripts": {
            "some_helpful_script": "path.to.my.script:main"
        }
    })

pex_binary(
    name="executable_things",
    script="conscript",
    dependencies=[":things_distributed", "//:reqs#conscript"])

Running ./pants package :executable_things results in the following error and traceback

15:49:49.47 [ERROR] 1 Exception encountered:

Engine traceback:
  in select
  in pants.core.goals.run.run
  in pants.backend.python.goals.run_pex_binary.create_pex_binary_run_request (//:executable_things)
  in pants.backend.python.util_rules.local_dists.build_local_dists
  in pants.backend.python.util_rules.local_dists.isolate_local_dist_wheels (//:things_distributed)
  in pants.engine.process.fallible_to_exec_result_or_raise
Traceback (most recent call last):
  File "/home/nathanael/.cache/pants/setup/bootstrap-Linux-x86_64/2.10.0_py38/lib/python3.8/site-packages/pants/engine/process.py", line 285, in fallible_to_exec_result_or_raise
    raise ProcessExecutionFailure(
pants.engine.process.ProcessExecutionFailure: Process 'List contents of artifacts produced by //:things_distributed' failed with exit code 9.

stderr:
+ for f in things_distributed-0-py3-none-any.whl things_distributed-0.tar.gz
+ /usr/bin/unzip -Z1 things_distributed-0-py3-none-any.whl
+ for f in things_distributed-0-py3-none-any.whl things_distributed-0.tar.gz
+ /usr/bin/unzip -Z1 things_distributed-0.tar.gz
[things_distributed-0.tar.gz]
  End-of-central-directory signature not found.  Either this file is not
  a zipfile, or it constitutes one disk of a multi-part archive.  In the
  latter case the central directory and zipfile comment will be found on
  the last disk(s) of this archive.
zipinfo:  cannot find zipfile directory in one of things_distributed-0.tar.gz or
          things_distributed-0.tar.gz.zip, and cannot find things_distributed-0.tar.gz.ZIP, period.

Pants version 2.10

OS Ubuntu 20.04

About this issue

  • Original URL
  • State: open
  • Created 2 years ago
  • Comments: 24 (17 by maintainers)

Commits related to this issue

Most upvoted comments

Update, looks like the .tar.gz problem is related to https://github.com/pantsbuild/pants/pull/14889 and if so should be fixed in 2.11.0. I’ll keep this open until we have confirmation that this is fixed in 2.11.x.

So now we’re left with the my_module.py problem. @engnatha can you open a separate issue for that one? Thanks!

Yeah, sorry, it’s an edited form of the real case. I’ve updated it to be more consistent hopefully.

I did try out sdist=False and I am still able to ./pants package :things_distributed fine, but I am getting a different hash error for running ./pants package :executable_things

stderr:
Traceback (most recent call last):
  File "/home/nathanael/.cache/pants/named_caches/pex_root/unzipped_pexes/3c037481d92e64c70b4c4d598b63e24e6c2bb819/.bootstrap/pex/pex.py", line 503, in execute
    exit_value = self._wrap_coverage(self._wrap_profiling, self._execute)
  File "/home/nathanael/.cache/pants/named_caches/pex_root/unzipped_pexes/3c037481d92e64c70b4c4d598b63e24e6c2bb819/.bootstrap/pex/pex.py", line 408, in _wrap_coverage
    return runner(*args)
  File "/home/nathanael/.cache/pants/named_caches/pex_root/unzipped_pexes/3c037481d92e64c70b4c4d598b63e24e6c2bb819/.bootstrap/pex/pex.py", line 439, in _wrap_profiling
    return runner(*args)
  File "/home/nathanael/.cache/pants/named_caches/pex_root/unzipped_pexes/3c037481d92e64c70b4c4d598b63e24e6c2bb819/.bootstrap/pex/pex.py", line 559, in _execute
    return self.execute_entry(self._pex_info.entry_point)
  File "/home/nathanael/.cache/pants/named_caches/pex_root/unzipped_pexes/3c037481d92e64c70b4c4d598b63e24e6c2bb819/.bootstrap/pex/pex.py", line 695, in execute_entry
    return self.execute_pkg_resources(entry_point)
  File "/home/nathanael/.cache/pants/named_caches/pex_root/unzipped_pexes/3c037481d92e64c70b4c4d598b63e24e6c2bb819/.bootstrap/pex/pex.py", line 727, in execute_pkg_resources
    return runner()
  File "/home/nathanael/.cache/pants/named_caches/pex_root/installed_wheels/9fb4bc59f7085c6133bed415fd8806a166d6f472798f2350158f7f0a710ec0f6/pex-2.1.71-py2.py3-none-any.whl/pex/bin/pex.py", line 724, in main
    do_main(
  File "/home/nathanael/.cache/pants/named_caches/pex_root/installed_wheels/9fb4bc59f7085c6133bed415fd8806a166d6f472798f2350158f7f0a710ec0f6/pex-2.1.71-py2.py3-none-any.whl/pex/bin/pex.py", line 745, in do_main
    pex_builder = build_pex(
  File "/home/nathanael/.cache/pants/named_caches/pex_root/installed_wheels/9fb4bc59f7085c6133bed415fd8806a166d6f472798f2350158f7f0a710ec0f6/pex-2.1.71-py2.py3-none-any.whl/pex/bin/pex.py", line 571, in build_pex
    pex_builder.add_from_requirements_pex(requirements_pex)
  File "/home/nathanael/.cache/pants/named_caches/pex_root/installed_wheels/9fb4bc59f7085c6133bed415fd8806a166d6f472798f2350158f7f0a710ec0f6/pex-2.1.71-py2.py3-none-any.whl/pex/pex_builder.py", line 318, in add_from_requirements_pex
    add(cached_location, dist_name, dist_hash)
  File "/home/nathanael/.cache/pants/named_caches/pex_root/installed_wheels/9fb4bc59f7085c6133bed415fd8806a166d6f472798f2350158f7f0a710ec0f6/pex-2.1.71-py2.py3-none-any.whl/pex/pex_builder.py", line 305, in add
    raise self.InvalidDistribution(
pex.pex_builder.InvalidDistribution: Distribution things_distributed-0-py3-none-any.whl at /home/nathanael/.pex/installed_wheels/e7319265d6a68d1d1ba6897359445c1d7dff195de8918039997ad45753e3a0ce/things_distributed-0-py3-none-any.whl had hash d4b41bda9c587befeb3c85e32af094a88c4623ea, expected e7319265d6a68d1d1ba6897359445c1d7dff195de8918039997ad45753e3a0ce