pygradle icon indicating copy to clipboard operation
pygradle copied to clipboard

python-pex - Usage example?

Open gcscaglia opened this issue 7 years ago • 1 comments

Currently there is no usage example for python-pex plugin.

I've being trying to use it without success; A ./gradlew build outputs the following error:

> Task :buildPex FAILED
Processing /root/git/pex-example-tentative
Building wheels for collected packages: pex-example-tentative
  Running setup.py bdist_wheel for pex-example-tentative: started
  Running setup.py bdist_wheel for pex-example-tentative: finished with status 'done'
  Stored in directory: /root/git/pex-example-tentative/build/wheel-cache
Successfully built pex-example-tentative
/root/git/pex-example-tentative/build/deployable/bin/pex-example-tentative.pex
Traceback (most recent call last):
  File "/root/git/pex-example-tentative/build/venv/bin/pex", line 11, in <module>
    sys.exit(main())
  File "/root/git/pex-example-tentative/build/venv/lib/python2.7/site-packages/pex/bin/pex.py", line 620, in main
    pex_builder = build_pex(reqs, options, resolver_options_builder)
  File "/root/git/pex-example-tentative/build/venv/lib/python2.7/site-packages/pex/bin/pex.py", line 573, in build_pex
    pex_builder.add_distribution(dist)
  File "/root/git/pex-example-tentative/build/venv/lib/python2.7/site-packages/pex/pex_builder.py", line 317, in add_distribution
    dist_hash = self._add_dist_zip(dist.location, dist_name)
  File "/root/git/pex-example-tentative/build/venv/lib/python2.7/site-packages/pex/pex_builder.py", line 280, in _add_dist_zip
    wf.install(overrides=self._get_installer_paths(whltmp), force=True)
  File "/root/git/pex-example-tentative/build/venv/lib/python2.7/site-packages/wheel/install.py", line 268, in install
    if self.parsed_wheel_info['Root-Is-Purelib'] == 'true':
  File "/root/git/pex-example-tentative/build/venv/lib/python2.7/site-packages/wheel/decorator.py", line 17, in __get__
    val = self.wrapped(inst)
  File "/root/git/pex-example-tentative/build/venv/lib/python2.7/site-packages/wheel/install.py", line 238, in parsed_wheel_info
    return read_pkg_info_bytes(self.zipfile.read(self.wheelinfo_name))
  File "/root/git/pex-example-tentative/build/venv/lib/python2.7/site-packages/wheel/decorator.py", line 17, in __get__
    val = self.wrapped(inst)
  File "/root/git/pex-example-tentative/build/venv/lib/python2.7/site-packages/wheel/install.py", line 232, in zipfile
    self.verify(vzf)
  File "/root/git/pex-example-tentative/build/venv/lib/python2.7/site-packages/wheel/install.py", line 385, in verify
    record = zipfile.read(record_name)
  File "/usr/lib64/python2.7/zipfile.py", line 931, in read
    return self.open(name, "r", pwd).read()
  File "/root/git/pex-example-tentative/build/venv/lib/python2.7/site-packages/wheel/install.py", line 437, in open
    ef = zipfile.ZipFile.open(self, name_or_info, mode, pwd)
  File "/usr/lib64/python2.7/zipfile.py", line 957, in open
    zinfo = self.getinfo(name)
  File "/usr/lib64/python2.7/zipfile.py", line 905, in getinfo
    'There is no item named %r in the archive' % name)
KeyError: "There is no item named 'pex_example_tentative.dist-info/RECORD' in the archive"

Since there is no info on google or issue here about this message I assume this is a configuration problem rather than a bug. But I'm unable to troubleshot this any further without help; I'm willing to submit a PR with an fully working example once I've figured this out.

I'm attaching below the full project I've used to reproduce the issue above.

pex-example-tentative.zip

Any pointers to a solution or further troubleshoot steps are appreciated.

gcscaglia avatar Dec 06 '17 14:12 gcscaglia

That's because we need a version to produce the deployable artifact. Simply add version = '0.0.1' below the applied plugin in build.gradle and it will work. :-)

We also recommend using python-cli plugin, instead of plain python-pex. The pex plugin is the engine under the hood of all other plugins that produce deployable artifacts (cli, web-app, ...), but is rarely used in its direct form. There are exceptions of course, but if you need a command line tool, it's best to use the cli plugin. You can always define your own wrapper for it (the small program that calls pex with right entry points) if the default one doesn't suit you. Let us know if you need further help with customizations.

I agree, we need to put more substantial examples as a part of documentation here.

zvezdan avatar Dec 15 '17 01:12 zvezdan