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

python3Packages.relaxBuildSystemRequiresHook: init #331315

Draft
wants to merge 6 commits into
base: master
Choose a base branch
from

Conversation

natsukium
Copy link
Member

Description of changes

relaxBuildSystemRequiresHook has the same function as pythonRelaxDepsHook, but it affects build-system instead of dependencies.

This hook is executed in the preBuild phase and modifies pyproject.toml using relaxBuildSystem and removeBuildSystem.

This hook avoids manual patching and reduces build failures due to old patches when updating.

Things done

  • Built on platform(s)
    • x86_64-linux
    • aarch64-linux
    • x86_64-darwin
    • aarch64-darwin
  • For non-Linux: Is sandboxing enabled in nix.conf? (See Nix manual)
    • sandbox = relaxed
    • sandbox = true
  • 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/)
  • 24.11 Release Notes (or backporting 23.11 and 24.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
  • Fits CONTRIBUTING.md.

Add a 👍 reaction to pull requests you find important.

relaxBuildSystemRequiresHook = callPackage ({ makePythonHook, packaging, tomlkit }:
makePythonHook {
name = "relax-build-system-requires-hook";
propagatedBuildInputs = [ packaging tomlkit ];
Copy link
Member

@pbsds pbsds Jul 31, 2024

Choose a reason for hiding this comment

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

FTR, tomlkit in turn depends on pyyaml, pytest and poetry-core, which now risks being load-bearing for the majority of python3Packages. This is far better than introducing tomlq or dasel. 👍

Copy link
Member

Choose a reason for hiding this comment

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

Could we maybe use the inbuilt tomli and tomli-w? THen we only need poetry-core. For pytest we could disable tests.

Copy link
Member

Choose a reason for hiding this comment

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

I feel it is way more safe to use the tool that preserves whitespace and comments

Copy link
Member Author

Choose a reason for hiding this comment

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

tomlkit is recommended for editing existing toml.
Also, poetry-core is the only dependency when tests are disabled.

The TOML Kit package is a style-preserving TOML library with both read and write capability. It is a recommended replacement for this module for editing already existing TOML files.

https://docs.python.org/3/library/tomllib.html

Comment on lines +1408 to +1426
In general you should always use `relaxBuildSystem`, because `removeBuildSystem`
will cause silent build errors. However `removeBuildSystem` may
still be useful in exceptional cases, and also to remove dependencies wrongly
declared by upstream (for example, declaring `pytest` as a build dependency
instead of a test dependency).
Copy link
Member

Choose a reason for hiding this comment

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

I think also mentioning numpy_2 here is a good idea, since they explicitly reccomend that you add numpy>=2 to requires even when compatible with v1

@pbsds
Copy link
Member

pbsds commented Jul 31, 2024

This should also be backported to stable, since fixes that make use of this is also bound to get backported

@pbsbot
Copy link

pbsbot commented Aug 8, 2024

Result of nixpkgs-review pr 331315 run on x86_64-linux 1

17 packages built:
  • nixpkgs-manual
  • python311Packages.ipyparallel
  • python311Packages.ipyparallel.dist
  • python311Packages.ipytablewidgets
  • python311Packages.ipytablewidgets.dist
  • python311Packages.pygmo
  • python311Packages.relaxBuildSystemRequiresHook
  • python311Packages.vega
  • python311Packages.vega.dist
  • python312Packages.ipyparallel
  • python312Packages.ipyparallel.dist
  • python312Packages.ipytablewidgets
  • python312Packages.ipytablewidgets.dist
  • python312Packages.pygmo
  • python312Packages.relaxBuildSystemRequiresHook
  • python312Packages.vega
  • python312Packages.vega.dist

@pbsds
Copy link
Member

pbsds commented Aug 8, 2024

The ofborg darwin failure is already present on hydra https://hydra.nixos.org/build/267900625

@SuperSandro2000
Copy link
Member

relaxBuildSystemRequiresHook has the same function as pythonRelaxDepsHook, but it affects build-system instead of dependencies.

Do we actually care from where the dependency is? Can't we combine those by default?

@natsukium
Copy link
Member Author

I have no strong opinion about adding new attributes.
I'm willing to use pythonRelaxDeps for convenience if there are no significant side effects.

@natsukium
Copy link
Member Author

Regarding setup.py and setup.cfg, we could use ast and configparser to modify install_requires and tests_require.

@pbsds
Copy link
Member

pbsds commented Aug 9, 2024

Regarding setup.py and setup.cfg, we could use ast and configparser to modify install_requires and tests_require.

A ast solution would likely assume the requirements are expressed as a literal, I think it is better to shim setup instead

@pbsds
Copy link
Member

pbsds commented Aug 9, 2024

I have no strong opinion about adding new attributes.
I'm willing to use pythonRelaxDeps for convenience if there are no significant side effects.

I'm in favor of the separation. It's cleaner, easier to understand and document, and might afford maintainers to navigate more packaging edge cases

@natsukium natsukium marked this pull request as draft September 1, 2024 06:04
@natsukium natsukium force-pushed the relax-build-system-requires-hook branch from 96aa7f8 to 91451e0 Compare September 1, 2024 06:05
@nixos-discourse
Copy link

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

https://discourse.nixos.org/t/several-comments-about-priorities-and-new-policies-in-the-python-ecosystem/51790/2

Copy link
Contributor

@doronbehar doronbehar left a comment

Choose a reason for hiding this comment

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

I support adding this hook :) Just a few comments about the attributes names chosen, not something fundamental.

@@ -489,6 +489,7 @@ are used in [`buildPythonPackage`](#buildpythonpackage-function).
- `pythonRelaxDepsHook` will relax Python dependencies restrictions for the package.
See [example usage](#using-pythonrelaxdepshook).
- `pythonRemoveBinBytecode` to remove bytecode from the `/bin` folder.
- `relaxBuildSystemRequiresHook` to relax build-system restrictions defined in PEP518 for the package.
Copy link
Contributor

Choose a reason for hiding this comment

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

Hmm most people are not familiar with the different PEPs, so how about:

Suggested change
- `relaxBuildSystemRequiresHook` to relax build-system restrictions defined in PEP518 for the package.
- `relaxBuildSystemRequiresHook` to relax build-system restrictions defined in projects' `pyproject.toml`.

@@ -1376,8 +1377,53 @@ work with any of the [existing hooks](#setup-hooks).

The `pythonRelaxDepsHook` has no effect on build time dependencies, such as
those specified in `build-system`. If a package requires incompatible build
time dependencies, they should be removed in `postPatch` through
`substituteInPlace` or similar.
time dependencies, consider using `relaxBuildSystem` or `removeBuildSystem`.
Copy link
Contributor

Choose a reason for hiding this comment

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

The Deps suffix missing is confusing IMO, how about naming these attributes:

Suggested change
time dependencies, consider using `relaxBuildSystem` or `removeBuildSystem`.
time dependencies, consider using `pythonRelaxBuildDeps` or `pythonRemoveBuildDeps`.


#### Using relaxBuildSystemRequiresHook {#using-relaxbuildsystemrequireshook}

`relaxBuildSystemRequiresHook` has the same function as `pythonRelaxDepsHook`,
Copy link
Contributor

Choose a reason for hiding this comment

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

Similarly, I'd suggest a different name, analogue to the existing attributes:

Suggested change
`relaxBuildSystemRequiresHook` has the same function as `pythonRelaxDepsHook`,
`pythonRelaxBuildDepsHook` has the same function as `pythonRelaxDepsHook`,

@@ -2008,7 +2054,8 @@ The following rules are desired to be respected:
* Only unversioned attributes (e.g. `pydantic`, but not `pypdantic_1`) can be included in `dependencies`,
since due to `PYTHONPATH` limitations we can only ever support a single version for libraries
without running into duplicate module name conflicts.
* The version restrictions of `dependencies` can be relaxed by [`pythonRelaxDepsHook`](#using-pythonrelaxdepshook).
* The version restrictions of `dependencies` can be relaxed by [`pythonRelaxDepsHook`](#using-pythonrelaxdepshook)
and of `build-system` can be relaxed by [`relaxBuildSystemRequiresHook`](#using-relaxbuildsystemrequireshook).
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
and of `build-system` can be relaxed by [`relaxBuildSystemRequiresHook`](#using-relaxbuildsystemrequireshook).
and of `build-system` can be relaxed by [`pythonRelaxBuildDepsHook`](#using-pythonRelaxBuildDepsHook).

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.

6 participants