Skip to content

Various Python package fixes after the migration to unittestCheckHook#187778

Merged
vcunat merged 2 commits intoNixOS:staging-nextfrom
winterqt:unittest-hook-fixes
Aug 24, 2022
Merged

Various Python package fixes after the migration to unittestCheckHook#187778
vcunat merged 2 commits intoNixOS:staging-nextfrom
winterqt:unittest-hook-fixes

Conversation

@winterqt
Copy link
Copy Markdown
Member

Description of changes
Things done
  • Built on platform(s)
    • x86_64-linux
    • aarch64-linux
    • x86_64-darwin
    • aarch64-darwin
  • For non-Linux: Is sandbox = true set in nix.conf? (See Nix manual)
  • Tested, as applicable:
  • Tested compilation of all packages that depend on this change using nix-shell -p nixpkgs-review --run "nixpkgs-review rev HEAD". Note: all changes have to be committed, also see nixpkgs-review usage
  • Tested basic functionality of all binary files (usually in ./result/bin/)
  • 22.11 Release Notes (or backporting 22.05 Release notes)
    • (Package updates) Added a release notes entry if the change is major or breaking
    • (Module updates) Added a release notes entry if the change is significant
    • (Module addition) Added a release notes entry if adding a new NixOS module
    • (Release notes changes) Ran nixos/doc/manual/md-to-db.sh to update generated release notes
  • Fits CONTRIBUTING.md.

@github-actions github-actions bot added the 6.topic: python Python is a high-level, general-purpose programming language. label Aug 21, 2022
@ofborg ofborg bot added 10.rebuild-darwin: 11-100 This PR causes between 11 and 100 packages to rebuild on Darwin. 10.rebuild-linux: 11-100 This PR causes between 11 and 100 packages to rebuild on Linux. labels Aug 21, 2022
@vcunat
Copy link
Copy Markdown
Member

vcunat commented Aug 21, 2022

I confirm that these two packages were failing and they now succeed with this PR.

@winterqt winterqt marked this pull request as ready for review August 21, 2022 22:10
@winterqt
Copy link
Copy Markdown
Member Author

@FRidh Do you mind taking a look at cymem? They use pytest in CI (which is why I switched to it, let me know if I should revert) but unittest and pytest both throw that same error, when that doesn't happen in their CI. Thanks.

@winterqt winterqt force-pushed the unittest-hook-fixes branch from 91df9a2 to 9f659b6 Compare August 21, 2022 23:13
@winterqt
Copy link
Copy Markdown
Member Author

I tried bumping to the latest version, to no avail.

Looks like these were probably broken the entire time, it's just that they were never ran until this hook was added (Hydra build, it ran 0 tests).

No clue what's going on here, considering it passes in upstream CI, and we run the same command.

substituteInPlace setup.py \
--replace "wheel>=0.32.0,<0.33.0" "wheel>=0.31.0"
'';
# ModuleNotFoundError: No module named 'cymem.cymem'
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

We should probably improve our check hooks by moving out of the source directory. Following is a work-around, but it works because I am using the absolute path to the source here.

diff --git a/pkgs/development/python-modules/cymem/default.nix b/pkgs/development/python-modules/cymem/default.nix
index 88e25720109..83f0ae05595 100644
--- a/pkgs/development/python-modules/cymem/default.nix
+++ b/pkgs/development/python-modules/cymem/default.nix
@@ -20,12 +20,12 @@ buildPythonPackage rec {
     cython
   ];
 
-  # ModuleNotFoundError: No module named 'cymem.cymem'
-  doCheck = false;
-
+  preCheck = ''
+    cd $out
+  '';
   checkInputs = [ pytestCheckHook ];
 
-  pytestFlagsArray = [ "cymem" ];
+  pytestFlagsArray = [ "/build/source" ];
 
   meta = with lib; {
     description = "Cython memory pool for RAII-style memory management";

Copy link
Copy Markdown
Member

@vcunat vcunat Aug 22, 2022

Choose a reason for hiding this comment

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

I'm not sure if we can afford to assume /build. At least without sandboxing it won't work, I think.

Copy link
Copy Markdown
Member Author

@winterqt winterqt Aug 22, 2022

Choose a reason for hiding this comment

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

@FRidh Why does this fix the issue? Upstream does what we do (execute pytest from the source directory) in CI, and it passes just fine, so I'm confused as to why we need to do that. Note that I've tried with and without the cymem argument, and get the same result.

@vcunat We can't assume it, no, for exactly that reason.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Absolute path to the root is in some variable defined by nix, for sure, but that might be a bit more complicated to get expanded correctly.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I think that can be worked around pretty easily (not to say it'll be clean, but it'll work), but I'd like to understand why we have to deviate from upstream (and other packages that use pytest) before implementing it.

Copy link
Copy Markdown
Member Author

@winterqt winterqt Aug 22, 2022

Choose a reason for hiding this comment

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

So if I cd into cymem in preCheck, everything works fine (without the cymem argument to pytest).

I just don't understand why this doesn't happen upstream... unless it's because they install the package before running the tests -- which I guess is only required because this is a Cython module (otherwise pytest would fixup sys.path so the sources could be imported).

So since we also install it in the test environment (by adding it to PYTHONPATH), why is moving into that directory required? Clearly the tests are discovered just fine, and the package is installed whether we run the cd or not... so upstream's execution method should work fine, considering we install it just like they do.

Maybe pytest's sys.path modifying is conflicting with our installed copy when we're in the root dir, so it doesn't happen when we go one level down, or something??

why is this so confusing

Copy link
Copy Markdown
Member

@FRidh FRidh Aug 23, 2022

Choose a reason for hiding this comment

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

@FRidh Why does this fix the issue? Upstream does what we do (execute pytest from the source directory) in CI, and it passes just fine, so I'm confused as to why we need to do that. Note that I've tried with and without the cymem argument, and get the same result.

That's because they build in place. Bad practice.

python setup.py build_ext --inplace

We need to move out of the directory because Python adds the current working directory to sys.path and so the source version without extension module gets seen and imported first.

@bobby285271 bobby285271 added the 12.approvals: 1 This PR was reviewed and approved by one person. label Aug 22, 2022
@vcunat vcunat merged commit 4b41fff into NixOS:staging-next Aug 24, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

6.topic: python Python is a high-level, general-purpose programming language. 10.rebuild-darwin: 11-100 This PR causes between 11 and 100 packages to rebuild on Darwin. 10.rebuild-linux: 11-100 This PR causes between 11 and 100 packages to rebuild on Linux. 12.approvals: 1 This PR was reviewed and approved by one person.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants