Skip to content

Python: reduce closure sizes by not installing tests #12379

@FRidh

Description

@FRidh

Often Python packages also install their tests. After the check phase we have no use for them and so there is no need to actually copy them to $out. In certain cases the closure size can be reduced dramatically by excluding the tests, like with matplotlib as shown in #12218 for example, although in general the difference is likely not significant.

I propose we enable an option which by default removes the tests and would like to discuss here how to implement this.

Interface

We need an option with which we can enable/disable this for a specific package. Furthermore, it would be nice if this option would take not just a boolean, but a list with paths to use instead as well, so true, false or [].

Implementation

Which directories to remove? Python tests can be anywhere. Test runners for example search all packages for modules matching test_*.py or test_*.py. I suggest we do the same and delete those files.

Where to implement this in buildPythonPackage then? According to the manual:

buildPythonPackage mainly does four things:

  1. In the buildPhase, it calls ${python.interpreter} setup.py bdist_wheel to build a wheel binary zipfile.
  2. In the installPhase, it installs the wheel file using pip install *.whl.
  3. In the postFixup phase, wrapPythonPrograms bash function is called to wrap all programs in $out/bin/* directory to include $PYTHONPATH and $PATH environment variables.
  4. In the installCheckPhase,${python.interpreter} setup.py test` is ran.

Clearly it won't be possible to remove the tests until after installCheckPhase.
Should we add another phase after installCheckPhase for this?

Metadata

Metadata

Assignees

No one assigned

    Labels

    0.kind: enhancementAdd something new or improve an existing system.2.status: stalehttps://github.com/NixOS/nixpkgs/blob/master/.github/STALE-BOT.md6.topic: pythonPython is a high-level, general-purpose programming language.9.needs: reporter feedbackThis issue needs the person who filed it to respond

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions