Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

pythonPackages.pex: 1.2.7 -> 1.4.5 #45497

Closed
wants to merge 4 commits into from
Closed

Conversation

mgeisler
Copy link

Motivation for this change

This packages a new version of pex and moves it to a top-level tool, similarly to how Pipenv is packaged.

I'm not sure what the impact is of the move from pkgs/top-level/python-packages.nix to pkgs/top-level/all-packages.nix, but since pex is more of a command line tool than a Python library, the change makes sense to me :-) Please advice if this is bad for some reason or if there is followup work to be done!

The packaging was tested locally on a MacOS machine and a Ubuntu VM. The packaging was also executed on a Hydra installation with the sandbox enabled.

Things done
  • Tested using sandboxing (nix.useSandbox on NixOS, or option sandbox in nix.conf on non-NixOS)
  • Built on platform(s)
    • NixOS
    • macOS
    • Ubuntu
  • Tested via one or more NixOS test(s) if existing and applicable for the change (look inside nixos/tests)
  • Tested compilation of all pkgs that depend on this change using nix-shell -p nox --run "nox-review wip"
  • Tested execution of all binary files (usually in ./result/bin/)
  • Determined the impact on package closure size (by running nix path-info -S before and after)
  • Fits CONTRIBUTING.md.

@mgeisler
Copy link
Author

undefined variable 'pex' at /var/lib/ofborg/checkout/repo/38dca4e3aa6bca43ea96d2fcc04e8229/mr-est/eval-2-shlevy.ewr1.nix.ci/pkgs/development/tools/build-managers/pants/default.nix:28:61

Okay... I guess this is a hint that moving pex does have an impact :-)

@Mic92
Copy link
Member

Mic92 commented Aug 23, 2018

Do you know if it is used as an executable or as a library in pantsbuild? This is were the evaluation error is currently coming from.

@@ -0,0 +1,29 @@
{ stdenv, python3Packages }:
with python3Packages; buildPythonApplication rec {
name = "${pname}-${version}";
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Drop this line

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay, thanks -- is it computed automatically from pname and version?

@@ -7620,6 +7620,7 @@ with pkgs;

pew = callPackage ../development/tools/pew {};
pipenv = callPackage ../development/tools/pipenv {};
pex = callPackage ../development/tools/pex {};
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

alphabetic order and blank lines

Copy link
Author

@mgeisler mgeisler Aug 24, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, I've inserted the package between pew and pipenv now.

patches = [ ./set-source-date-epoch.patch ];

# A few more dependencies I don't want to handle right now...
doCheck = false;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did you check whether these dependencies have been packaged in the meantime?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, I just copied the existing definition. Removing the line seems to work fine -- though no tests are run.

Please let me know how you like to see changes made in response to review comments: as follow-up commits, or by me immediately fixing the broken commit and force pushing?

@mgeisler
Copy link
Author

Do you know if it is used as an executable or as a library in pantsbuild?

@Mic92, I looked it up and Pants do use PEX as a Python library.

So I guess that means that I should not be moving from buildPythonPackage to buildPythonApplication like I originally thought?

@Mic92
Copy link
Member

Mic92 commented Aug 24, 2018

Yes otherwise pantsbuild might break because no dependencies from pex to pantsbuild are propagated: https://github.com/NixOS/nixpkgs/blob/master/pkgs/top-level/python-packages.nix#L66

@FRidh would it make sense to have also a buildPythonApplication variant of the same package that does not propagate dependencies?

@FRidh
Copy link
Member

FRidh commented Aug 25, 2018

I don't really see the value in having a buildPythonApplication variant. How does it deal with multiple interpreter versions?

@mgeisler
Copy link
Author

I don't really see the value in having a buildPythonApplication variant.

Oh, I don't know if there's any value in it either :-) I just saw that Pipenv was packaged that way and since PEX is also a command line too, I thought that using buildPythonApplication would be a little more correct somehow.

I'll try updating it back to buildPythonPackage and see if that works better. Thanks for the tips!

propagatedBuildInputs = [ setuptools wheel requests ];

prePatch = ''
substituteInPlace setup.py --replace 'SETUPTOOLS_REQUIREMENT,' '"setuptools",'
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm a little worried about this line -- which was part of the original derivation. The setup.py file from pex includes a pex/version.py file, which says:

# NB: If we upgrade to setuptools>=34 pex's bootstrap code in `PEXBuilder` will need an update to
# include the `packaging` package in the `.bootstrap/` code since we use
# `packaging.specifiers.SpecifierSet` - indirectly - through `pkg_resources.Requirement.specifier`.
SETUPTOOLS_REQUIREMENT = 'setuptools>=20.3,<34.0'

WHEEL_REQUIREMENT = 'wheel>=0.26.0,<0.32.0'

The SETUPTOOLS_REQUIREMENT and WHEEL_REQUIREMENT variables are then used in setup.py. When we change the requirement to just "setuptools", we get whatever version is in Nix -- version 40.0.0 at the moment. This sounds dangerous in light of the above comment.

Is there a normal approach in Nix to handle situations like this? I imagine one could package setuptools version 33 and have pex use that specific version?

Copy link
Member

@Mic92 Mic92 Aug 27, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

With python we are more bound to having only a single version in nixpkgs because of dependency propagation. However it seems that master also support setuptools newer then 34: https://github.com/pantsbuild/pex/blob/f125317bb6001ccbb56f68168bc45f947d274405/pex/version.py#L8

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, cool! The new version.py file says:

# Versions 34.0.0 through 35.0.2 (last pre-36.0.0) de-vendored dependencies which
# causes problems for pex code so we exclude that range.
SETUPTOOLS_REQUIREMENT = 'setuptools>=20.3,<41,!=34.*,!=35.*'

which means that using version 40.0.0 should be fine. Thanks for looking this up!

@mgeisler mgeisler changed the title pex: 1.2.7 -> 1.4.5 pythonPackages.pex: 1.2.7 -> 1.4.5 Aug 27, 2018
@Mic92
Copy link
Member

Mic92 commented Aug 27, 2018

@GrahamcOfBorg build pythonPackages.pex python3Packages.pex

@GrahamcOfBorg
Copy link

Success on x86_64-darwin (full log)

Attempted: pythonPackages.pex, python3Packages.pex

Partial log (click to expand)

warning: no previously-included files matching '*~' found under directory '*'
writing manifest file 'pex.egg-info/SOURCES.txt'
running build_ext

----------------------------------------------------------------------
Ran 0 tests in 0.000s

OK
/nix/store/izc6s44r6y1kpq5l1fs01f98s6b0x7db-python2.7-pex-1.4.5
/nix/store/cn7ismrgfib91vbpkqqx5y33l6m2h514-python3.6-pex-1.4.5

@GrahamcOfBorg
Copy link

Failure on aarch64-linux (full log)

Attempted: pythonPackages.pex, python3Packages.pex

Partial log (click to expand)

Reading https://pypi.org/simple/pytest/
Download error on https://pypi.org/simple/pytest/: [Errno -2] Name or service not known -- Some packages may not be found!
Couldn't find index page for 'pytest' (maybe misspelled?)
Scanning index of all packages (this may take a while)
Reading https://pypi.org/simple/
Download error on https://pypi.org/simple/: [Errno -2] Name or service not known -- Some packages may not be found!
No local packages or working download links found for pytest
error: Could not find suitable distribution for Requirement.parse('pytest')
builder for '/nix/store/7j76m6x2l1r6942adavm7c6ry73q4fil-python3.6-pex-1.4.5.drv' failed with exit code 1
error: build of '/nix/store/7j76m6x2l1r6942adavm7c6ry73q4fil-python3.6-pex-1.4.5.drv', '/nix/store/kbvirbswfdhjjffmhx8dzmwf65cmwk8z-python2.7-pex-1.4.5.drv' failed

@GrahamcOfBorg
Copy link

Failure on x86_64-linux (full log)

Attempted: pythonPackages.pex, python3Packages.pex

Partial log (click to expand)

Reading https://pypi.org/simple/pytest/
Download error on https://pypi.org/simple/pytest/: [Errno -2] Name or service not known -- Some packages may not be found!
Couldn't find index page for 'pytest' (maybe misspelled?)
Scanning index of all packages (this may take a while)
Reading https://pypi.org/simple/
Download error on https://pypi.org/simple/: [Errno -2] Name or service not known -- Some packages may not be found!
No local packages or working download links found for pytest
error: Could not find suitable distribution for Requirement.parse('pytest')
builder for '/nix/store/m4rnfxhryrd36ccsih9sqmd7hg1cn3f4-python3.6-pex-1.4.5.drv' failed with exit code 1
error: build of '/nix/store/24xkcyzzxnkj4d81404c5bqngw5dvlw0-python2.7-pex-1.4.5.drv', '/nix/store/m4rnfxhryrd36ccsih9sqmd7hg1cn3f4-python3.6-pex-1.4.5.drv' failed

};

propagatedBuildInputs = [ setuptools wheel requests ];

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Blind guess:

checkInputs = [ pytest ];

to fix the build issues:

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, I'll give it a try..

The install_requires have changed from version 1.2.7 to 1.4.5 and now
also include the wheel package. So this and setuptools have been added
to propagatedBuildInputs.
The files in /nix/store are all back-dated to 1970, and this breaks
pex when it tries to generate wheels: wheels are really zip files, and
the zip file format does not support dates before 1980.

This is normally handled by setting SOURCE_DATE_EPOCH when building
the Nix package. However, pex will invoke further Python interpreters
at runtime in calls like this:

  $ python setup.py bdist_wheel

We thus need to ensure that it passes the SOURCE_DATE_EPOCH variable
onto those interpreters. The date of the wheels will be fixed at 1980.
Without requests, pex will emit a number of warnings to the terminal
when building pex files:

  % ./result/bin/pex -v httpie -o http
  pex: Warning, using a UrllibContext which is known to be flaky.
  pex: Please build pex with the requests module for more reliable downloads.
  pex: Warning, using a UrllibContext which is known to be flaky.
  pex: Please build pex with the requests module for more reliable downloads.

This fixes these warnings.
@Mic92
Copy link
Member

Mic92 commented Aug 27, 2018

@GrahamcOfBorg build pythonPackages.pex python3Packages.pex

@GrahamcOfBorg
Copy link

Success on x86_64-darwin (full log)

Attempted: pythonPackages.pex, python3Packages.pex

Partial log (click to expand)

warning: no previously-included files matching '*~' found under directory '*'
writing manifest file 'pex.egg-info/SOURCES.txt'
running build_ext

----------------------------------------------------------------------
Ran 0 tests in 0.000s

OK
/nix/store/7hy485pmia4h6mhfp1fhv4aimxfs72a4-python2.7-pex-1.4.5
/nix/store/0318k83l6lbpznfpxh4qlcmd1p6p9g3l-python3.6-pex-1.4.5

@GrahamcOfBorg
Copy link

Failure on aarch64-linux (full log)

Attempted: pythonPackages.pex, python3Packages.pex

Partial log (click to expand)

Reading https://pypi.org/simple/twitter.common.dirutil/
Download error on https://pypi.org/simple/twitter.common.dirutil/: [Errno -2] Name or service not known -- Some packages may not be found!
Couldn't find index page for 'twitter.common.dirutil' (maybe misspelled?)
Scanning index of all packages (this may take a while)
Reading https://pypi.org/simple/
Download error on https://pypi.org/simple/: [Errno -2] Name or service not known -- Some packages may not be found!
No local packages or working download links found for twitter.common.dirutil<0.4.0,>=0.3.1
error: Could not find suitable distribution for Requirement.parse('twitter.common.dirutil<0.4.0,>=0.3.1')
builder for '/nix/store/1afi9zw1hlbn4mhz81k5b01ybf4291c7-python3.6-pex-1.4.5.drv' failed with exit code 1
error: build of '/nix/store/1afi9zw1hlbn4mhz81k5b01ybf4291c7-python3.6-pex-1.4.5.drv', '/nix/store/6kfijr4ma8gif468arl5v6p13xnw7w8p-python2.7-pex-1.4.5.drv' failed

@GrahamcOfBorg
Copy link

Failure on x86_64-linux (full log)

Attempted: pythonPackages.pex, python3Packages.pex

Partial log (click to expand)

Reading https://pypi.org/simple/twitter.common.dirutil/
Download error on https://pypi.org/simple/twitter.common.dirutil/: [Errno -2] Name or service not known -- Some packages may not be found!
Couldn't find index page for 'twitter.common.dirutil' (maybe misspelled?)
Scanning index of all packages (this may take a while)
Reading https://pypi.org/simple/
Download error on https://pypi.org/simple/: [Errno -2] Name or service not known -- Some packages may not be found!
No local packages or working download links found for twitter.common.dirutil<0.4.0,>=0.3.1
error: Could not find suitable distribution for Requirement.parse('twitter.common.dirutil<0.4.0,>=0.3.1')
builder for '/nix/store/7h3k3y90hywx49s8xdn89pkxqszhxgby-python3.6-pex-1.4.5.drv' failed with exit code 1
error: build of '/nix/store/7h3k3y90hywx49s8xdn89pkxqszhxgby-python3.6-pex-1.4.5.drv', '/nix/store/kw8hpc3pviqwlb0rwp68nw4sdw435qb5-python2.7-pex-1.4.5.drv' failed

@Mic92
Copy link
Member

Mic92 commented Aug 27, 2018

we also have twitter-common-dirutil in nixpkgs.

@Mic92
Copy link
Member

Mic92 commented Aug 28, 2018

You can reproduce these problems locally, when enabling nix's sandbox.

@mgeisler
Copy link
Author

Thanks @Mic92 -- I'll have to experiment a bit more with this offline! You're completely right that I should get my local setup done so that I can find a way to reproduce what you see.

I'll ping you guys later when I have worked out the kinks... thanks for all the feedback until now!

@mgeisler
Copy link
Author

Hi guys -- I no longer work with Nix, so I won't be able to finish this. I hope the PR can be useful to someone else who wants to upgrade PEX.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants