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

Split buildPythonPackage into setup hooks #64997

Closed
wants to merge 3 commits into from
Closed

Conversation

FRidh
Copy link
Member

@FRidh FRidh commented Jul 17, 2019

This commit splits the buildPythonPackage into multiple setup hooks.

Generally, Python packages are built from source to wheels using setuptools.
The wheels are then installed with pip. Tests were often called with
python setup.py test but this is less common nowadays. Most projects
now use a different entry point for running tests, typically pytest
or nosetests.

Since the wheel format was introduced more tools were built to generate these,
e.g. flit. Since PEP 517 is provisionally accepted, defining a build-system
independent format (pyproject.toml), pip can now use that format to
execute the correct build-system.

In the past I've added support for PEP 517 (pyproject) to the Python
builder, resulting in a now rather large builder. Furthermore, it was not possible
to reuse components elsewhere. Therefore, the builder is now split into multiple
setup hooks.

The setuptoolsCheckHook is included now by default but in time it should
be removed from buildPythonPackage to make it easier to use another hook
(curently one has to pass in dontUseSetuptoolsCheck).

# No tests in archive
doCheck = false;

# We add this flag to ignore the copy installed by bootstrapped-pip
installFlags = [ "--ignore-installed" ];
pipInstallFlags = [ "--ignore-installed" ];
Copy link
Member Author

Choose a reason for hiding this comment

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

renaming is related to #64812

@FRidh
Copy link
Member Author

FRidh commented Jul 17, 2019

Not sure whether the naming of the various phases (prefixed with the package providing them) makes it easier.

@FRidh
Copy link
Member Author

FRidh commented Jul 18, 2019

cc @copumpkin have not seen you around in a while, but I recall you requested this once.

@FRidh FRidh force-pushed the hooks branch 2 times, most recently from 25966d0 to 102b558 Compare July 18, 2019 16:06
@FRidh FRidh force-pushed the hooks branch 2 times, most recently from 7e2a567 to 7bce3af Compare July 22, 2019 12:12
@FRidh FRidh changed the base branch from master to staging July 22, 2019 12:13
@FRidh FRidh changed the title WIP: spit buildPythonPackage into setup hooks Split buildPythonPackage into setup hooks Jul 22, 2019
@FRidh FRidh requested review from dotlambda and removed request for madjar, domenkozar, lovek323, lsix and primeos July 22, 2019 12:14
@FRidh
Copy link
Member Author

FRidh commented Jul 22, 2019

Need to consider also the naming of the flags that can be passed to setuptools and pip.
#64812

@FRidh FRidh changed the title Split buildPythonPackage into setup hooks WIP: Split buildPythonPackage into setup hooks Jul 22, 2019

args=" -m pytest"
if ! [ -z "$disabledTests" ]; then
args="$args -k disabledTests"
Copy link
Member

Choose a reason for hiding this comment

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

I like this one. We should have the same for nosetest.

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes. Note it's not yet correct. Need to implement the "and not " bit. Here I dislike having to write these things in bash.

Copy link
Contributor

Choose a reason for hiding this comment

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

Wasn't there a similar implementation but in nix for this?
Something like having an attribute disabledTests but as an argument to buildPython*.

Copy link
Member Author

Choose a reason for hiding this comment

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

That was #53142
I prefer to do as much as possible in Nix, however, that does not always work. In this case, the problem was that the generated value (a string) cannot be overridden.

@@ -8,8 +8,6 @@ buildPythonPackage rec {
sha256 = "52ab47715fa0fc7d8e6cd15168d1a69ba995feb1505131c3e814eb7087b57358";
};

buildInputs = [ pip ];
Copy link
Member Author

Choose a reason for hiding this comment

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

separate commit

Copy link
Member

@abbradar abbradar left a comment

Choose a reason for hiding this comment

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

Nice cleanup! Did only a cursory glance to get the general idea for now.

@@ -0,0 +1,15 @@
# Setup hook for flit
echo "Sourcing flit-build-hook"
Copy link
Member

Choose a reason for hiding this comment

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

These are for debugging I think?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes, they are. I think it would be good if the stdenv would output a bit more what it is doing.

This commit splits the `buildPythonPackage` into multiple setup hooks.

Generally, Python packages are built from source to wheels using `setuptools`.
The wheels are then installed with `pip`. Tests were often called with
`python setup.py test` but this is less common nowadays. Most projects
now use a different entry point for running tests, typically `pytest`
or `nosetests`.

Since the wheel format was introduced more tools were built to generate these,
e.g. `flit`. Since PEP 517 is provisionally accepted, defining a build-system
independent format (`pyproject.toml`), `pip` can now use that format to
execute the correct build-system.

In the past I've added support for PEP 517 (`pyproject`) to the Python
builder, resulting in a now rather large builder. Furthermore, it was not possible
to reuse components elsewhere. Therefore, the builder is now split into multiple
setup hooks.

The `setuptoolsCheckHook` is included now by default but in time it should
be removed from `buildPythonPackage` to make it easier to use another hook
(curently one has to pass in `dontUseSetuptoolsCheck`).
@FRidh FRidh changed the title WIP: Split buildPythonPackage into setup hooks Split buildPythonPackage into setup hooks Aug 31, 2019
@FRidh
Copy link
Member Author

FRidh commented Aug 31, 2019

I intend to include this in the upcoming staging-next cycle.

@FRidh
Copy link
Member Author

FRidh commented Sep 6, 2019

Pushed this to staging.

@nixos-discourse
Copy link

This pull request has been mentioned on NixOS Discourse. There might be relevant details there:

https://discourse.nixos.org/t/updating-python-projects-nix-shell-requirements-nix/4505/1

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

5 participants