Navigation Menu

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

[staging] python: add pythonRemoveTestsDirHook #81538

Merged
merged 1 commit into from Mar 3, 2020

Conversation

jonringer
Copy link
Contributor

@jonringer jonringer commented Mar 2, 2020

Motivation for this change

closes: #81482

Some packages do not have an explicit
find_packages(...,exclude=["tests"]) in thier
setup.py. This causes a tests module to be
installed, and can collide with other packages
which fail to filter it out as well.

This could potentially create problems if there ever was a "tests" package. But I don't think that will ever be the case with how prevalent a "tests" directory is.

Things done
  • Tested using sandboxing (nix.useSandbox on NixOS, or option sandbox in nix.conf on non-NixOS linux)
  • Built on platform(s)
    • NixOS
    • macOS
    • other Linux distributions
  • 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 nixpkgs-review --run "nixpkgs-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)
  • Ensured that relevant documentation is up to date
  • Fits CONTRIBUTING.md.

@jonringer jonringer added the 9.needs: port to stable A PR needs a backport to the stable release. label Mar 2, 2020
@jonringer jonringer requested a review from FRidh as a code owner March 2, 2020 16:51
@jonringer
Copy link
Contributor Author

@GrahamcOfBorg build python38Packages.poetry

@jonringer
Copy link
Contributor Author

actually, i need ofborg to evaluate python38.withPackages(ps: with ps; [poetry]), not sure how to do that

@adisbladis
Copy link
Member

@jonringer I recently implemented the same fix for poetry2nix as a hook: https://github.com/nix-community/poetry2nix/blob/master/hooks/fixup-hook.sh.

It's better as a hook in regards to overrides.

@FRidh
Copy link
Member

FRidh commented Mar 2, 2020

I used to just build a sdist first, as I needed that anyway when distributing source code. IMO that's how we should do it when building from git.

@jonringer
Copy link
Contributor Author

this does solve the related issue:

[09:15:33] jon@jon-desktop /home/jon/projects/nixpkgs (avoid-test-dir)
$ nix-shell -p "with import ./. {}; python38.withPackages(ps: with ps; [poetry])"

[nix-shell:/home/jon/projects/nixpkgs]$

@jonringer
Copy link
Contributor Author

I used to just build a sdist first, as I needed that anyway when distributing source code. IMO that's how we should do it when building from git.

I don't think we have a good mechanism to determine this, as both will hand us a tar.gz. I think going the hook route is fine if you want me to refactor to something similar to what @adisbladis posted

@FRidh
Copy link
Member

FRidh commented Mar 2, 2020

I don't think we have a good mechanism to determine this, as both will hand us a tar.gz.

Right, it would be a Nix function building a derivation, e.g. buildSetuptoolsSdist.

@jonringer
Copy link
Contributor Author

I changed it to being a hook

Seeing as the "tests" package on pypi https://pypi.org/project/tests/ is defunct, I think it's safe that you will never want a top-level "tests" package

@jonringer
Copy link
Contributor Author

jonringer commented Mar 2, 2020

Right, it would be a Nix function building a derivation, e.g. buildSetuptoolsSdist.

or use the pre-existing format switch, and just have format = "sdist"; in an expression. The other options flit, pyproject, wheel, egg, other are all mutually exclusive with building from sdist

This will automatically remove a top-level "tests"
directory from being installed.
@FRidh
Copy link
Member

FRidh commented Mar 2, 2020

Now that we're talking about hooks, I started off a hook that would remove requirements from a wheel master...FRidh:python-deps-hook, that way it should work regardless of where the dependency is listed. It's not functioning (need to look further into zipfile class) but it shows the idea.

@FRidh FRidh added this to WIP in Staging via automation Mar 2, 2020
@jonringer
Copy link
Contributor Author

jonringer commented Mar 2, 2020

Now that we're talking about hooks, I started off a hook that would remove requirements from a wheel master...FRidh:python-deps-hook, that way it should work regardless of where the dependency is listed. It's not functioning (need to look further into zipfile class) but it shows the idea.

For packages that over-pin, I think this is great, but it still leans more on having tests to verify that a package set is still valid. (Overall, this is still needed. Testing is mostly orthogonal)

It would remove a lot of pain around use-cases where substituteInPlace/sed is used to do exactly this

@ofborg ofborg bot requested a review from FRidh March 2, 2020 18:48
@jonringer jonringer changed the title [staging] python: remove top-level tests site-package [staging] @jonringer python: add pythonRemoveTestsDirHook Mar 2, 2020
@jonringer jonringer changed the title [staging] @jonringer python: add pythonRemoveTestsDirHook [staging] python: add pythonRemoveTestsDirHook Mar 2, 2020
@jonringer
Copy link
Contributor Author

with current changes, this has the expected behavior:

[11:00:19] jon@jon-desktop /home/jon/projects/nixpkgs (avoid-test-dir)
$ NIX_PATH=nixpkgs=$PWD nix-shell -p "python38.withPackages(ps: with ps; [poetry])"

[nix-shell:/home/jon/projects/nixpkgs]$ poetry --version
Poetry version 1.0.3

[nix-shell:/home/jon/projects/nixpkgs]$ cat pkgs/development/python-modules/poetry/default.nix | grep version
  version = "1.0.3";

Staging automation moved this from WIP to Ready Mar 2, 2020
@jonringer
Copy link
Contributor Author

@FRidh does this look good to you? I know that the python ecosystem is mostly your baby

@FRidh
Copy link
Member

FRidh commented Mar 3, 2020

I hope we could fix it at the source side instead of fixing up but I think we may have to do it this anyway.

Something I quickly gave a try. So far the issue have been the packages for which an sdist was built using poetry. Rebuilding an sdist for those requires poetry resulting in recursion. The main issue is with those packages built using poetry so I prefer to look at that deeper before using the hammer.
https://github.com/NixOS/nixpkgs/compare/master...FRidh:sdist?expand=1

@FRidh FRidh merged commit 3973a3c into NixOS:staging Mar 3, 2020
Staging automation moved this from Ready to Done Mar 3, 2020
@FRidh
Copy link
Member

FRidh commented Mar 3, 2020

Actually I do not want to spend time on this, let's merge.

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

Successfully merging this pull request may close these issues.

None yet

3 participants