Commit Graph

94 Commits

Author SHA1 Message Date
Adam Joseph
bc2d598878 treewide: change pythonForBuild to pythonOnBuildForHost 2023-11-05 17:42:12 -08:00
github-actions[bot]
3e52e5929d
Merge master into staging-next 2023-09-25 12:01:02 +00:00
Peder Bergebakken Sundt
bdda7b0a53 python3Packages.flitBuildHook: remove 2023-09-22 21:11:24 +02:00
DavHau
c57e6b692a python3.pkgs.pypaBuildHook: fix conflicts
This modifies the pypaBuildHook to not propagate its own python dependencies into the build environment. This prevents package conflicts.

- modify pypa-build-hook.sh to call pyproject-build via an absolute path. This removes the need of putting the dependencies inside the hook's propagatedBuildInputs
- remove the hook's dependencies from propagatedBuildInputs
- add a passthru test to the hook testing for the fix
2023-09-12 21:04:26 +02:00
Leandro Reina
a391639845 python3Packages.sphinxHook: Fix cross compilation
Failed due to using host sphinx instead of build one.
2023-09-09 21:34:33 +02:00
Theodore Ni
130e063a3d
pypaInstallHook: enter "dist" directory before installing (#250464) 2023-08-21 08:45:47 +02:00
Theodore Ni
dd1256d2ca python3.pkgs.pythonRelaxDepsHook: don't propagate wheel
The usage of wheel should be restricted to the hook. I discovered this
when trying to remove wheel from the Python bootstrap. Some packages
that needed wheel did not need it added explicitly because they use this
hook. This implicit change to the dependency tree shouldn't happen (even
though it is mostly harmless).
2023-08-20 11:00:51 +02:00
Theodore Ni
93d25dda84 python3.pkgs.pypaBuildHook: switch to pyproject-build
Upstream's recommended "python -m build" way of invoking build fails
when the working directory contains a file named "build.py". This is
common for poetry projects that build C extensions.
2023-08-20 10:59:46 +02:00
Theodore Ni
a4d66bcc5f python3.pkgs.pypaInstallHook: init 2023-08-20 10:59:46 +02:00
Theodore Ni
ece0953571
Merge branch 'staging-next' into staging 2023-08-18 16:02:27 -07:00
github-actions[bot]
03146a5454
Merge master into staging-next 2023-08-18 06:01:01 +00:00
Nick Cao
e19e2222d7
python3Packages.pythonNamespacesHook: use findutils from buildPackages (#249864) 2023-08-18 07:39:36 +02:00
Thiago Kenji Okada
5dda73a162
Merge pull request #248516 from thiagokokada/remove-version-from-python-relax-deps-hook
pythonRelaxDepsHook: remove version from pkg_name
2023-08-12 00:57:55 +00:00
Thiago Kenji Okada
98de48fc8f pythonRelaxDepsHook: remove version from pkg_name
Since the wheel file name is based on the package metadata instead of
what we set in the derivation, if you set the version as `unstable-YYYYMMDD`,
for example, the hook would silently fail. We will ignore the version
now and just use a glob instead to match anything that has the package
name in its path.

Fixes #248185.
2023-08-11 14:56:14 +01:00
Artturin
8eff2eea8c Revert "Revert "python3: splice python within python3Packages.callPackage""
This reverts commit 2ffca30cde.

`793cc9d982415b71cdba729cf779bfc49e9d2ae7` `python3: splice python within python3Packages.callPackage`
Was reverted because it broke
`pkgsCross.aarch64-multiplatform.python3Packages.cryptography`

But by reverting the revert `pkgsCross.aarch64-multiplatform.python3Packages.cryptography` still builds.

I tried reverting the 2 cryptography update commits, and it still
worked, so I do not know why this would work now.
2023-08-05 02:37:16 +03:00
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