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

README.md: be more specific withDefaults application order #1877

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

spinus
Copy link

@spinus spinus commented Dec 8, 2024

Contribution checklist (recommended but not always applicable/required):

  • There's an automated test for this change
  • Commit messages or code include references to related issues or PRs (including third parties)
  • Commit messages are conventional - examples from the log include "feat: add changelog files to fixup hook", "fix(contourpy): allow wheel usage", and "test: add sqlalchemy2 test"

@spinus
Copy link
Author

spinus commented Dec 8, 2024

In relation to #1519

Copy link
Contributor

@Nebucatnetzer Nebucatnetzer left a comment

Choose a reason for hiding this comment

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

In general it looks good, some minor things and a few typos.

@@ -142,7 +142,7 @@ The _poetry2nix_ public API consists of the following attributes:
- [mkPoetryScriptsPackage](#mkpoetryscriptspackage): Creates a package containing the scripts from `tool.poetry.scripts` of the `pyproject.toml`.
- [mkPoetryEditablePackage](#mkpoetryeditablepackage): Creates a package containing editable sources. Changes in the specified paths will be reflected in an interactive nix-shell session without the need to restart it.
- [defaultPoetryOverrides](#defaultpoetryoverrides): A set of bundled overrides fixing problems with Python packages.
- [overrides.withDefaults](#overrideswithdefaults): A convenience function for specifying overrides on top of the defaults.
- [overrides.withDefaults](#overrideswithdefaults): A convenience function for specifying overrides on top of the defaults (it applies user overrides and then applies defaults after).
Copy link
Contributor

Choose a reason for hiding this comment

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

"it applies user overrides first and then applies defaults"

@@ -592,6 +592,15 @@ poetry2nix.mkPoetryApplication {
}
```

Please remember that `withDefaults` function, applies user overrides first, and than applies `defaults`. If you want to change package
Copy link
Contributor

Choose a reason for hiding this comment

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

Please remember that the withDefaults function

Missing the

and then

Then instead of than.

If you want to change a package

Missing a.

@@ -592,6 +592,15 @@ poetry2nix.mkPoetryApplication {
}
```

Please remember that `withDefaults` function, applies user overrides first, and than applies `defaults`. If you want to change package
that already is overriden by `defaults` you may need to do
Copy link
Contributor

Choose a reason for hiding this comment

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

Can you rewrite it like this?
The text and the code are separated by an empty line.

you can use the a snippet like the following which then puts your changes on top of the defaults:

```nix

@Nebucatnetzer
Copy link
Contributor

@elikoga Can you explain to me the difference between the code snippet in this merge request and the way it is done here? jwpconsulting/projectify@5aef755

@elikoga
Copy link
Contributor

elikoga commented Dec 27, 2024

@elikoga Can you explain to me the difference between the code snippet in this merge request and the way it is done here? jwpconsulting/projectify@5aef755

I believe it's just like justuswilhelm said in #1519 :

My overrides are created with

    overrides = defaultPoetryOverrides.extend (self: super: {

based off the poetry2nix flake guide, and just like @sigprof here recommended as well -- so perhaps that made a difference?

where extend is defined by https://noogle.dev/f/lib/makeExtensible

Compared to overrides.withDefaults, which is simply defined in poetry2nix and whose behaviour was changed in f36ad45

@sigprof
Copy link
Contributor

sigprof commented Jan 3, 2025

The real problem is that some overrides work only when applied before defaultPoetryOverrides, but some other overrides work only when applied after defaultPoetryOverrides. So in the end I needed to resort to code like this:

    overrides = [
      # Some overrides (e.g., the ones which set preferWheel) must be applied
      # before the default overrides:
      # https://github.com/nix-community/poetry2nix/pull/899
      (self: super: {
        attrs = super.attrs.override {
          # attrs >= 24.3.0 requires hatchling >= 1.26.0 to build from source:
          #   https://github.com/python-attrs/attrs/pull/1377
          #   https://github.com/pypa/hatch/issues/1715
          preferWheel = true;
        };
      })

      poetry2nix.defaultPoetryOverrides

      # Apply most overrides after the default overrides, so that things like
      # overriding cargoDeps work even when the default overrides also do that:
      # https://github.com/nix-community/poetry2nix/issues/1519
      (self: super: {
        rpds-py = let
          getCargoHash = version: {
            "0.22.3" = "sha256-m01OB4CqDowlTAiDQx6tJ7SeP3t+EtS9UZ7Jad6Ccvc=";
          }.${version} or (
            lib.warn "Unknown rpds-py version: '${version}'. Please update getCargoHash." lib.fakeHash
          );
        in
          super.rpds-py.overridePythonAttrs(old: {
            cargoDeps = pkgs.rustPlatform.fetchCargoTarball {
              inherit (old) src;
              name = "${old.pname}-${old.version}";
              hash = getCargoHash old.version;
            };
          });
        });
      })
    ];

@elikoga
Copy link
Contributor

elikoga commented Jan 8, 2025

From #899

why then have overrides.withDefaults if it can't be used sanely?

Since we already have poetry2nix.defaultPoetryOverrides why not deprecate the old function with a warning, then later removal or similar (in 2 nixos release cycles?)

If the api of the function can be changed to break for some users anyways, why not for all users?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants