Commit Graph

79 Commits

Author SHA1 Message Date
Doron Behar
6560d0086c python3.pkgs.pypaBuildHook: init 2023-07-28 12:13:25 +02:00
Doron Behar
1298c367b1 pip-build-hook.sh: Support $pipBuildFlags 2023-07-28 12:13:25 +02:00
Karel Kočí
9d663f7fcd
setuptools-rust: fix cross compilation
The setuptools-rust requires some environment variables to really
perform cross build, otherwise it just builds for build platform.

This adds setup hook that introduces these environment variables.

There are three variables.
The PYO3_CROSS_LIB_DIR has to point to the target's Python library
directory. This has to be directory for the target not for the build or
host. We have to choose the correct target Python. I am unsure how to do
that simply in nixpkgs and this this implementations just delays this
and waits for the correct Python when package using this hook is build.
The CARGO_BUILD_TARGET triggers cross compilation in setuptools-rust.
This is simply the Rust target specification.
The CARGO_TARGET_*_LINKER variable should not be essentially required
but setuptools-rust probably mangles the Rust build environment somewhat
and that results to the missing linker. By explicitly specifying it
using the environment variable we force the correct linker.
2023-06-30 14:52:25 +02:00
Frederik Rietdijk
f04278458b Revert "python.pipInstallHook: avoid producing wrong direct_url.json file"
Certain packages were failing since this was merged.
https://github.com/NixOS/nixpkgs/pull/229472#issuecomment-1544410416

This reverts commit bff6c67911.
2023-05-17 12:19:52 +02:00
Jairo Llopis
bff6c67911 python.pipInstallHook: avoid producing wrong direct_url.json file
When installing many python packages, a `direct_url.json` file appeared in the lib directory. Example:

```sh
➤ nix build nixpkgs/29755fec55e58a315b517d431b2be261772f2b80#python3Packages.flask

➤ cat result/lib/python3.10/site-packages/Flask-2.2.3.dist-info/direct_url.json
{"archive_info": {}, "url": "file:///build/Flask-2.2.3/dist/Flask-2.2.3-py3-none-any.whl"}⏎
```

As you can see, that file contains a wrong reference to `/build`.

In https://discuss.python.org/t/pep-610-usage-guidelines-for-linux-distributions/4012/4 there's an explanation on how to avoid this. Here, I'm implementing that change for nixpkgs.

@moduon MT-1075
2023-05-11 09:15:48 +02:00
Artturin
4e3dcf364e treewide: makeSetupHook deps -> propagatedBuildInputs 2023-02-07 21:02:00 +02:00
Martin Weinelt
e464bde9ba
Merge pull request #208962 from KAction/patch/v1/python3.pkgs.sphinxHook 2023-01-04 02:38:53 +01:00
Dmitry Bogatov
82ae2e8f06 python3.pkgs.sphinxHook: fix co-installability of generated documentation
Include full $name of the derivation into docdir, so documentation for
python package "foo" is installed into $out/share/doc/python3.10-foo-1.2.3
instead of just $out/share/doc/foo, where it may conflict with some
other package named "foo" and not-coinstallable with different
versions of the same python package.

Change from $name to $pname was introduced in [1ee5fca], probably as
unindented side-effect of adding support for formats other than html.
2023-01-03 20:28:48 -05:00
Robert Schütz
fa3feb9f65 python3Packages.pythonImportsCheck: set $PYTHONPATH
Don't rely on the installPhase doing so.
2022-12-29 04:11:02 -08:00
Jörg Thalheim
7eccc4973c
Merge pull request #195055 from Mic92/buildPythonPackage
buildPythonPackage: fix regression if no setuptools is used
2022-11-06 20:37:18 +01:00
Pierre Bourdon
1f197e240e
pythonRelaxDepsHook: improve Requires-Dist parsing
Prior to this commit, pythonRelaxDeps would only support removing
version constraints from "Requires-Dist" lines formatted in a particular
way ("foo (>= 1.2.3)"). This way is deprecated as per PyPA Core Metadata
Specs v2.1 [1]:

> Tools parsing the format should accept optional parentheses around
> this, but tools generating it should not use parentheses.

Additionally, a "Requires-Dist" dependency specification can contain
other metadata than just package name and version (extra names,
environment marker). These were being silently dropped by the prior
version of pythonRelaxDeps, or the version could not be relaxed.

The actual grammar is defined in PEP 508 [2]. Our tool of choice here is
sed extended regexps, so there's only so much we can do to be correct
with this parser. The regexp implemented in this commit makes an attempt
at supporting [extra] names, ; env_markers, as well as version specs
without parentheses. There are still unsupported features (URL specs) as
well as unhandled edge cases, but at some point trying to make the
regexp better is bound to awake ZALGO [3].

[1] https://packaging.python.org/en/latest/specifications/core-metadata/#requires-dist-multiple-use
[2] https://peps.python.org/pep-0508/#grammar
[3] https://stackoverflow.com/a/1732454/179806
2022-10-31 17:05:12 +01:00
Frederik Rietdijk
33d12e5f0b pythonPackages: ensure all derivations provide python modules
This adds a test to ensure no new uses of `buildPythonApplication` can
be added to `python-packages.nix`.

Python packages can be grouped into two groups: 1) applications and 2)
packages providing importable modules. In `python-packages.nix` we only
want to have 2). 1) should be in the top-level package set.

To achieve this, all setup hooks need to be marked as being a setup hook.
For the setup hooks in the Python packages set this is done by creating
a new builder, `makePythonHook`.

Because there were issues with splicing, the file importing all the hooks
is converted to an extension. All non-packages were moved out of `python-packages.nix`
into `python-packages-base.nix`. The `keep` argument to `makeScopeWithSplicing
was cleaned up as well; there is no need to keep this one manually in sync
reducing the risk of breaking cross-compilation.
2022-10-27 10:03:16 +02:00
Jörg Thalheim
12f9d8e730 buildPythonPackage: better error message if no setuptools is used.
Before packages did not had to set `format = "other";` if had a custom
installPhase and would not produce a dist folder.
The current error message is hard to understand by new users:

> Executing pythonOutputDistPhase
> mv: cannot stat 'dist': No such file or directory

This commit improves the error message.
2022-10-17 10:12:34 +02:00
Frederik Rietdijk
de5951f3c2 pythonPackages.pythonRelaxDepsHook: cleanup unpacked folder
or it will end up in the dist output.
2022-10-04 15:34:46 +02:00
Martin Weinelt
68c0ca4416 Merge remote-tracking branch 'origin/master' into staging-next 2022-09-25 21:36:31 +02:00
Frederik Rietdijk
7a41be7b2a Python hooks: use spliced packages in hooks
This fixes issues when cross-compiling.
2022-09-23 22:19:52 +03:00
Frederik Rietdijk
86ab83260f Revert "Revert "buildPython*: store dist (wheel/sdist) in dist output""
Most packages were fixed on python-unstable.

This reverts commit 0a4898c21a.
2022-09-20 09:49:55 +02:00
Frederik Rietdijk
8895944c57 Revert "Revert "buildPython*: wrap setuptools in hook for catching conflicts""
Most packages were fixed up on python-unstable branch.

This reverts commit 3ff2d9362c.
2022-09-20 09:49:27 +02:00
Frederik Rietdijk
3ff2d9362c Revert "buildPython*: wrap setuptools in hook for catching conflicts"
Revert for now and fix on python-unstable branch.

This reverts commit 13bb0f49f7.
2022-09-19 10:01:25 +02:00
Frederik Rietdijk
0a4898c21a Revert "buildPython*: store dist (wheel/sdist) in dist output"
Revert for now and fix on python-unstable branch.

This reverts commit adbc59c9d3.
2022-09-19 10:00:42 +02:00
Frederik Rietdijk
13bb0f49f7 buildPython*: wrap setuptools in hook for catching conflicts
By default buildPython* runs a hook for detecting conflicting packages.
This hook needs pkg_resources which is part of setuptools.

Before this commit, setuptools was simply added to the build. This meant
that when setuptools was forgotten to be added to the build, the build
and installation would still succeed because of this package from the
hook. During runtime (and cross-compilation) one would notice the
missing package.
2022-09-13 18:48:08 +02:00
Frederik Rietdijk
adbc59c9d3 buildPython*: store dist (wheel/sdist) in dist output
Store the intermediate artifacts. In time, we should build, install and
test in separate derivations as that reduces circular dependencies,
avoids rebuilds when fixing tests, and makes it possible to use the
wheels for creating say virtualenv's.
2022-09-12 22:15:39 +02:00
Martin Weinelt
19f4e14dcf
python3Packages.sphinxHook: run install phase in predist
Run the installSphinxPhase earlier, so install errors are caught early,
before long and expensive test are started.
2022-08-24 23:02:27 +02:00
Martin Weinelt
caf2d010ed
python3Packages.sphinxHook: Rename loop var in source root detection
The loop variable to find the documentation source root was
unnecessarily short, rename it to something meaningful.
2022-08-24 23:02:26 +02:00
Martin Weinelt
8a26deba06
doc/python: integrate sphinxHook docs
Improve the documentation by moving it from the hook script into the
Python section in the manual and adding code examples.
2022-08-24 23:02:24 +02:00
Martin Weinelt
1ee5fcaf0c
python3Packages.sphinxHook: Add support for multiple builders
Removes the up until now unused option to specify a `sphinxOutdir` in
favor of allowing to specify multiple builders, which is for example
useful for generating both documentation and manpages using the hook.

Since the output path cannot be determined from within the package we
automatically generate it and add a diversion for manpages, so they land
in the correct output and path.
2022-08-24 23:00:41 +02:00
Winter
e8fbb38a51 pythonPackages.unittestCheckHook: init 2022-08-13 14:09:43 -04:00
Martin Weinelt
c7dbac1666 python3Packages.sphinxHook: run post install
This allows importing and inspecting the build result, which is required
for the psycopg (3.x) package.
2022-07-21 22:35:25 +02:00
Thiago Kenji Okada
15491e727d pythonRelaxDepsHook: correct handles multiple wheels 2022-06-12 11:48:52 +01:00
Thiago Kenji Okada
61223d51de pythonRelaxDepsHook: fix usage in packages with - in pname 2022-06-07 21:24:48 +01:00
github-actions[bot]
ee7e3f30f3
Merge staging-next into staging 2022-05-04 00:02:57 +00:00
Frederik Rietdijk
ab62fad9d5
Merge pull request #136100 from KAction/sphinx-hook
New hook: sphinxHook to build documentation into different formats/outputs
2022-05-03 20:07:37 +02:00
Thiago Kenji Okada
e19019fe32 pythonRelaxDepsHook: init
We have a common pattern here in nixpkgs for Python applications: when a
Python package ships with either a requirements.txt or setup.py file, we
generally end up having to modify its version restriction, otherwise we have
build failures since we package only one specific version of each package
normally.

However, this end up being done in a completely ad-hoc way: some people
use substituteInPlace, some others use sed, others uses patches, etc.
In many cases, the code ends up being buggy, so it may work in one
version and breaks on the next one. We can instead implement one
standard way of doing this, and trying to be a correct as possible.

So this is what this commit does: it implements a new build hook, that
when called will automatically patch the wheel file. This is one of the
most generic ways to patch Python dependencies, and should work in
multiple cases.
2022-04-30 13:19:30 +01:00
Dmitry Bogatov
6b8b02cef7
python3.pkgs.sphinxHook: new package
This hook takes care of building and installing html documentation from Sphinx
sources.
2022-04-29 08:45:38 -04:00
Sergei Trofimovich
a649d4f038 python: use whitespace to split possible existing options
Noticed option globbing when tried to enable parallelism by default
locally for most packages by default. python3Packages.yt-dlp failed as:

    python3.9-yt-dlp> /nix/store/5mywvxdjkk1q6srwwwgdkzc37ibla801-python3.9-setuptools-61.2.0/lib/python3.9/site-packages/setuptools/dist.py:516: UserWarning: Normalizing '2022.04.08' to '2022.4.8'
    python3.9-yt-dlp>   warnings.warn(tmpl.format(**locals()))
    python3.9-yt-dlp> invalid command name 'build_lazy_extractors--parallel'

The change adds leading whitespace everywhere where options might
already be present.
2022-04-24 14:28:26 +02:00
Phillip Cloud
52248e4466 python: enable opt-in parallel build_ext builds for setuptools 2022-04-22 18:25:12 +02:00
Jonathan Ringer
ae418d54d3 python.pkgs.pythonNamespacesHook: check parent directory exists before removing child 2021-12-02 17:38:40 -08:00
Jonathan Ringer
a06fe88f75 python/pythonNamespacesSetupHook: add to addtional files to remove 2021-11-29 22:50:15 -08:00
Drew Risinger
30097aeabc
python: pythonRemoveTestsDirHook removes /test
Some packages have their tests installed at ./test, not just ./tests.
This covers that use case by removing both.
2021-06-21 16:48:39 -07:00
github-actions[bot]
f2a2e8f5e9
Merge master into staging-next 2021-05-28 12:48:40 +00:00
DavHau
6c0b85cf3a buildPythonPackage: add support for conda 2021-05-28 14:31:40 +02:00
Eduardo Sánchez Muñoz
4aee58ec96 pythonPackages.buildPythonPackage: enable verbose output with pyproject
This makes the build log more useful
2021-05-19 12:16:15 -07:00
Robert T. McGibbon
2e55b7301b pytestCheckHook: improve disabledTestPaths whitespace handling 2021-05-14 21:59:55 -07:00
Frederik Rietdijk
7a65bb76f1 pythonPackages: fix editable setuptools installations 2021-03-23 11:27:27 +01:00
Martin Weinelt
d6d63aef7d
pytestCheckHook: add support for disabling arbitrary paths
Renames `disabledTestFiles` to the more genereric `disabledTestPaths` to
reflect that change.
2021-02-15 00:34:35 +01:00
Martin Weinelt
0f5743bee2 pytestCheckHook: Fix support for multiple files.
Quoting here will lead to the shell treating them as a single item.
2021-01-24 15:44:45 -08:00
Martin Weinelt
45e5ebfad8 pytestCheckHook: Fix support for spaces in disabled file paths 2021-01-24 15:44:45 -08:00
Sandro Jäckel
6f7f01a244 pytestCheckHook: Add disabledTestFiles option 2021-01-16 09:09:26 -08:00
Frederik Rietdijk
76966f8ddd pythonPackages.pip-install-hook: remove --build option
Pip had the option --build to build in a custom or temporary directory.
Nowadays, pip just listens to TMPDIR, which we already set.

This option was deprecated and is removed in pip 20.3.
2020-12-01 14:44:26 +01:00
Jonathan Ringer
0a4575a1da python/hooks/pythonNamespaces: fix __pycache__ being empty, or not existing 2020-11-26 13:51:05 -08:00