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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

doc: update toPythonApplication section according to RFC 140 #294988

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

Conversation

AndersonTorres
Copy link
Member

The advent of pkgs/by-name hierarchy created an interesting alternative: instead of cluttering all-packages.nix with more lines and more merge conflicts, the creation of toPythonApplication expressions can be made at pkgs/by-name.

Description of changes

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.05 Release Notes (or backporting 23.05 and 23.11 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.

@AndersonTorres
Copy link
Member Author

Marking

@lolbinarycat
Copy link
Contributor

calling it an alternative doesn't seem right, isn't by-name the preferred way of doing things now?

@ShamrockLee
Copy link
Contributor

ShamrockLee commented Mar 11, 2024

This format provides a more robust way to override dependent python packages, and also make the dependent toPythonPackage overridable.

calling it an alternative doesn't seem right, isn't by-name the preferred way of doing things now?

I also think this should be considered the preferred way, while the current hard-coded one-liners in all-packages.nix the obsolete way.

However, we do hope to maintain a consistent overriding interface.

Considering the following scenario:
Let's say that we have pkgs.youtube-dl packaged in this format:

{ python3Packages }:
with python3Packages; toPythonApplication youtube-dl

where python3Packages is python311Packages. If, for some reason, python3Packages.youtube-dl breaks, and the maintainers decide to switch to python310Packages.youtube-dl, should we add a line in all-packages.nix and specify youtube-dl = callPackage pkgs/by-name/yo/youtube-dl/package.nix { python3Packages = python310Packages; }, or should we just change the argument from python3Packages to python310Packages?

@lolbinarycat
Copy link
Contributor

i don't actually know python, so i'm not much help here, but if such a fundamental issue as "how do we package for different python versions" isn't solved yet, then it sounds like this packaging method isn't ready.

@ShamrockLee
Copy link
Contributor

BTW, why do we prefer python3*Packages over python3*.pkgs while we have to override it by overriding python3* and then access python3*.pkgs? After the adoption of this pattern, we'll need to do such kind of overriding often, and it's necessary to have a sensible way of overriding.

@ShamrockLee
Copy link
Contributor

ShamrockLee commented Mar 11, 2024

i don't actually know python, so i'm not much help here, but if such a fundamental issue as "how do we package for different python versions" isn't solved yet, then it sounds like this packaging method isn't ready.

I personally prefer the second approach, i.e. pin the version in all-packages.nix and remove the line to un-pin it. My point is that when it comes to the choice between keeping overriding interface consistent and avoiding all-packages.nix, the overriding interface consistency wins.

@infinisil
Copy link
Member

I think using toPythonApplication like this is great! The only thing to watch out for is whether this causes a change in the .override interface when you switch from a toPythonApplication in all-packages.nix to one in package.nix. I believe it does, so to prevent breakages you'd have to only use this for new packages or so.

where python3Packages is python311Packages. If, for some reason, python3Packages.youtube-dl breaks, and the maintainers decide to switch to python310Packages.youtube-dl, should we add a line in all-packages.nix and specify youtube-dl = callPackage pkgs/by-name/yo/youtube-dl/package.nix { python3Packages = python310Packages; }, or should we just change the argument from python3Packages to python310Packages?

This is indeed a concern, and I agree with your conclusion:

I personally prefer the second approach, i.e. pin the version in all-packages.nix and remove the line to un-pin it. My point is that when it comes to the choice between keeping overriding interface consistent and avoiding all-packages.nix, the overriding interface consistency wins.

This is also what is recommended in pkgs/by-name/README.md.

@infinisil infinisil added the architecture Relating to code and API architecture of Nixpkgs label Mar 12, 2024
@AndersonTorres
Copy link
Member Author

AndersonTorres commented Mar 12, 2024

calling it an alternative doesn't seem right, isn't by-name the preferred way of doing things now?

toPythonApplication cals are currently inlined at all-packages.nix.

BTW, why do we prefer python3*Packages over python3*.pkgs while we have to override it by overriding python3* and then access python3*.pkgs? After the adoption of this pattern, we'll need to do such kind of overriding often, and it's necessary to have a sensible way of overriding.

Splicing dark Magick.

@AndersonTorres
Copy link
Member Author

Ops, my failure!

@AndersonTorres AndersonTorres mentioned this pull request Mar 13, 2024
13 tasks
@infinisil
Copy link
Member

(Discussed in the docs team meeting today)

calling it an alternative doesn't seem right, isn't by-name the preferred way of doing things now?

toPythonApplication cals are currently inlined at all-packages.nix.

I think it's fine for something to be recommended even if older instances don't use the pattern (yet).

@nixos-discourse
Copy link

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

https://discourse.nixos.org/t/2024-03-14-documentation-team-meeting-notes-113/41462/1

Comment on lines 347 to 355
Since the advent of `pkgs/by-name` hierarchy, there is an extra alternative:
instead of writing the code above in `all-packages.nix`, the corresponding code
Copy link
Member

Choose a reason for hiding this comment

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

Given the agreement that this is the preferred way to declare these types of packages going forward, can you reword this to fit in the previous paragraph (instead of "A reference shall be created...", reword to fit this text there instead)?

And then we can ellaborate on:

  • Existing packages and why they must remain in all-packages.nix. I'd go with a note first (:::{.note}), but if the text becomes too large, can be a subsection.
  • What to do in cases we need to override the package

Copy link
Member Author

Choose a reason for hiding this comment

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

  1. Unfortunately the override can be a bit complicated, since the "library" is accessed behind python3Packages. But it happens in both scenarios, so nothing was lost.
  2. I am sprint-removing the ones in top-level.

That being said, I believe I will need to rewrite this whole text, showing the new vs the legacy method or something similar.

@AndersonTorres AndersonTorres force-pushed the topythonapp-update-docs branch 2 times, most recently from 3fed991 to f2021fd Compare March 31, 2024 01:54
@AndersonTorres
Copy link
Member Author

@DanielSidhion please review again.

Copy link
Member

@DanielSidhion DanielSidhion left a comment

Choose a reason for hiding this comment

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

Thanks! Made a suggestion to avoid some potential confusion in the future.

doc/languages-frameworks/python.section.md Outdated Show resolved Hide resolved
Copy link
Member

@DanielSidhion DanielSidhion left a comment

Choose a reason for hiding this comment

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

Made some suggestions to fix the syntax of the note blocks and fix a typo.

doc/languages-frameworks/python.section.md Outdated Show resolved Hide resolved
doc/languages-frameworks/python.section.md Outdated Show resolved Hide resolved

with python3Packages; toPythonApplication youtube-dl
```

Copy link
Contributor

Choose a reason for hiding this comment

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

Document the way to ping the Python version of a Python application exposed this way for override interface consistency. (Feel free to rephrase it.)

Suggested change
In case the top-level Python application requires a specific interpreter version, specify the canonical `python3Packages` to use in `all-packages.nix`, instead of hard-coding the desired `python3*Packages`, to keep the [override](#sec-pkg-override) interface consistent.
::: {.example #ex-topythonapplication-by-name-ping}
# Ping the interpreter version of a Python application exposed in `pkgs/by-name`.
```nix
{
youtube-dl = callPackage ../by-name/yo/youtube-dl/package.nix {
python3Packages = python312Packages;
};
}
```
:::

Copy link
Member

Choose a reason for hiding this comment

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

This is already documented in the pkgs/by-name readme. I thought about making the same suggestion, but IMO it's better to have that information deduplicated. Perhaps add a pointer to the readme instead?

Copy link
Contributor

Choose a reason for hiding this comment

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

How about

Suggested change
In case the top-level Python application requires a specific interpreter version, [change the implicit default value](https://github.com/NixOS/nixpkgs/tree/master/pkgs/by-name#changing-implicit-attribute-defaults) of argument `python3Packages` to the desired package set, instead of hard-coding `python3*Packages` as an argument. This ensures consistent interpreter version overriding via [`<pkg>.override](#sec-pkg-override) and argument `python3Package`.

Copy link
Contributor

@ShamrockLee ShamrockLee left a comment

Choose a reason for hiding this comment

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

Some minor suggestions here:

  • We should probably avoid prone-to-irrelevance naming like "legacy method" and "new method", especially for document anchors, which are hard to change without breaking hyperlinks.
  • Use example blocks to make the examples more discoverable and linkable.

hierarchy, in a `callPackage` fashion. Taking the above `youtube-dl` as an
example, the reference is registered at
`pkgs/by-name/yo/youtube-dl/package.nix`:

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
::: {.example #ex-topythonapplication-function-by-name}
# Convert to a Python application and register in `pkgs/by-name`

{ python3Packages }:

with python3Packages; toPythonApplication youtube-dl
```
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
```
```
:::

the new method instead.
:::

##### New Method {#topythonapplication-function-new-method}
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
##### New Method {#topythonapplication-function-new-method}
##### Convert and register under name-based package directories {#topythonapplication-function-by-name}

@AndersonTorres
Copy link
Member Author

Some minor suggestions here:

  • We should probably avoid prone-to-irrelevance naming like "legacy method" and "new method",

My intention is to remove the legacy reference as soon as possible (right after converting the code), however it requires some testing.

especially for document anchors, which are hard to change without breaking hyperlinks.

Good point.
What do you think about removing the session marks and rewording?

@ShamrockLee
Copy link
Contributor

What do you think about removing the session marks and rewording?

Sounds great! How about introducing the new method directly, with a note block talking about the migration?

The existing approach could be mentioned as

Prior to the [name-based package directories](https://github.com/NixOS/nixpkgs/blob/master/pkgs/by-name/README.md),
the Python-application reference to a Python module was placed inside `all-packages.nix`.

@AndersonTorres AndersonTorres force-pushed the topythonapp-update-docs branch 2 times, most recently from 226316f to 4a38344 Compare April 15, 2024 15:47
@AndersonTorres AndersonTorres changed the title doc: An alternative to writing toPythonApplication s doc: update toPythonApplication section according to RFC 140 Apr 15, 2024
@AndersonTorres AndersonTorres force-pushed the topythonapp-update-docs branch 2 times, most recently from b631b85 to 445f2a4 Compare April 17, 2024 19:43
@ShamrockLee
Copy link
Contributor

My laptop is awaiting repair, and I might be slow to response until setting up the machine I borrowed. Thank you for your patience.

Some minor suggestions here

We should probably avoid prone-to-irrelevance naming like "legacy method" and "new method",

My intention is to remove the legacy reference as soon as possible (right after converting the code), however it requires some testing.

Does that mean there will be a bulk migration from the legacy reference approach to the new one?

@AndersonTorres
Copy link
Member Author

Does that mean there will be a bulk migration from the legacy reference approach to the new one?

Yes:

#295499

The advent of `pkgs/by-name` hierarchy created an interesting method:
instead of cluttering `all-packages.nix` with more lines and more merge
conflicts, the creation of `toPythonApplication` expressions can be made at
`pkgs/by-name`.

This method should be the default for new packages, while the old one should be
phased out.
@ShamrockLee
Copy link
Contributor

The new "note about migration" looks great!

Do we need to remind people to follow the "changing the implicit default value" guide of name-based package directory when using a specific Python version?

with python3Packages; toPythonApplication youtube-dl
```

Sometimes, the top-level Python application requires a specific Python
Copy link
Member Author

Choose a reason for hiding this comment

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

@ShamrockLee

Do we need to remind people to follow the "changing the implicit default value" guide of name-based package directory when using a specific Python version?

I have done it here, line 377

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

6 participants