Skip to content

xonsh: refactor - #305316

Closed
AndersonTorres wants to merge 3 commits into
NixOS:masterfrom
atorres1985-contrib:xonsh
Closed

AndersonTorres wants to merge 3 commits into
NixOS:masterfrom
atorres1985-contrib:xonsh

Conversation

@AndersonTorres

Copy link
Copy Markdown
Member

Description of changes

Closes #301670 (by incorporation)

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
AndersonTorres marked this pull request as ready for review April 19, 2024 14:07
@ofborg ofborg Bot added the 2.status: merge conflict This PR has merge conflicts with the target branch label Apr 19, 2024
Comment thread pkgs/by-name/xo/xonsh/unwrapped.nix Resolved
@github-actions github-actions Bot added 6.topic: nixos Issues or PRs affecting NixOS modules, or package usability issues specific to NixOS 8.has: module (update) This PR changes an existing module in `nixos/` labels Apr 19, 2024
@ofborg ofborg Bot added 11.by: package-maintainer This PR was created by a maintainer of all the package it changes. 10.rebuild-darwin: 1-10 This PR causes between 1 and 10 packages to rebuild on Darwin. 10.rebuild-darwin: 1 This PR causes 1 package to rebuild on Darwin. 10.rebuild-linux: 1-10 This PR causes between 1 and 10 packages to rebuild on Linux. and removed 2.status: merge conflict This PR has merge conflicts with the target branch labels Apr 19, 2024
@AndersonTorres
AndersonTorres requested a review from wegank April 19, 2024 19:53
Comment thread pkgs/by-name/xo/xonsh/package.nix Resolved
@wegank wegank added the 12.approvals: 1 This PR was reviewed and approved by one person. label May 6, 2024

@GrimmTheShrimp GrimmTheShrimp left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I didn't do too much python packaging, but as i daily-drive xonsh here are a couple of my thoughts on the changes.

Comment thread nixos/modules/programs/xonsh.nix Resolved
Comment thread pkgs/by-name/xo/xonsh/wrapper.nix Outdated

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Does this approach allow overriding the python version (not the packages), i.e. using xonsh with e.g. python 3.12 despite python 3.11.9 being the current python3 version?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

It uses the same Python provided by xonsh.passthru.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

ah so i can override python with e.g. xonsh.override {python3 = pkgs.python312; } and it'll eat it? Incredible, ty :)

Comment thread pkgs/by-name/xo/xonsh/package.nix Resolved
Comment thread pkgs/by-name/xo/xonsh/package.nix Resolved
@FlyingWombat

Copy link
Copy Markdown
Contributor

Maybe this would be better to do in a separate pull request, but I think xonsh should be added to pythonPackages. Xonsh is meant to be used as both a library and an application

Comment thread pkgs/by-name/xo/xonsh/package.nix Resolved
Comment thread pkgs/by-name/xo/xonsh/package.nix Resolved
@AndersonTorres

Copy link
Copy Markdown
Member Author

So we need a complete overhaul?

  • xonsh as Python library (and application too)
  • version update
  • support to loading Python libraries and Xonsh scripts

This will be wild.

@FlyingWombat

Copy link
Copy Markdown
Contributor

So we need a complete overhaul?

I think so.

This pull request is already a big improvement, though, since now overrides can be made on xonsh. If you want to go ahead and get this merged, and leave the library+application changes to another PR, that's a good choice too.

@github-actions github-actions Bot added the 6.topic: python Python is a high-level, general-purpose programming language. label May 10, 2024
@AndersonTorres

Copy link
Copy Markdown
Member Author

Now I need testers!

@ofborg ofborg Bot added 8.has: package (new) This PR adds a new package and removed 10.rebuild-darwin: 1 This PR causes 1 package to rebuild on Darwin. labels May 10, 2024

@GrimmTheShrimp GrimmTheShrimp left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Alright, i did some testing and this is what i found:
you can indeed override the python version and libraries, though a bit awkward:

programs.xonsh.package = let xonsh = pkgs.xonsh.override { python3Packages = pkgs.python312Packages; }; in xonsh.wrapper.override {
          inherit xonsh;
          extraPackages =
            ps: with ps; [
              requests
              matplotlib
              numpy
              scipy
              pygobject3
            ];
        };

the used python version can be checked by import sys; print(sys.executable), it'll print the store path of the used python.

Keep in mind the prompt toolkit that was pinned here does not yet fully support python 3.12, this is more a PoC and test whether it is possible rather than a serious suggestion.

Overriding python libraries still works, though obviously you have to override on the wrapper. That is honestly completely fine, its documented in the example. It might however break users config, so whether this can be merged before 24.05 is released is questionable.

Importing xonsh as a python library works, thoguh i never used xonsh as a python library so i can't say i tested that much.

Xonsh itself starts entirely fine, reports as version 0.16.0 and builds xonsh and prompt toolkit 3.0.39 just fine.

Built and tested on x86-64_linux.

@AndersonTorres

Copy link
Copy Markdown
Member Author

Well, let's wait the branch off.

@FlyingWombat

Copy link
Copy Markdown
Contributor

The new changes are working for me. And I'm able to use the same override pattern that @LordGrimmauld mentioned to override xonsh src and wrapper extraPackages. I'm haven't used xonsh as a python library; while I've run some basic examples importing xonsh with python, I haven't tested that thoroughly.

package = let xonsh = pkgs.xonsh.overridePythonAttrs (old: {
  src = pkgs.fetchgit { ... };
}); in xonsh.wrapper.override {
  inherit xonsh;
  extraPackages = ps: [ 
    ... 
  ];
};

And a complete overhaul!

- xonsh now refers to the unwrapped derivation
- the wrapper is now called xonsh.wrapper
- use a self-referent argset
  - Avoiding rec at all costs - until the day finalAttrs design pattern becomes
    ubiquitous :)
- pin prompt-toolkit (upstream-upstream bug workaround)
@wegank wegank removed the 12.approvals: 1 This PR was reviewed and approved by one person. label May 12, 2024
@wegank wegank added the 2.status: merge conflict This PR has merge conflicts with the target branch label May 22, 2024
@SamLukeYes

Copy link
Copy Markdown
Member

Upstream has unpinned prompt-toolkit after xonsh/xonsh#5437, and worked out a fix for #206062 in xonsh/xonsh#5440. Would you like to apply those fixes in your PR?

@GrimmTheShrimp

Copy link
Copy Markdown
Contributor

I am not exactly keen on the idea on wildly patching our packets on nix with fixes that are available upstream already and will soon be part of a release. Imo there is three options:

  • just release 0.16.0 as-is, and bump it once the next xonsh version releases
  • wait for the next xonsh release (though this would push this PR back even further...)
  • use unstable-2024-05-23 version and pull raw git source instead of tagged/released version

@AndersonTorres

Copy link
Copy Markdown
Member Author

Let's close this, then.

@AndersonTorres
AndersonTorres deleted the xonsh branch May 25, 2024 14:08
@GrimmTheShrimp

Copy link
Copy Markdown
Contributor

huh? But what happens to all the nice refactors then? Having this closed wasn't my intention!

@AndersonTorres

AndersonTorres commented May 25, 2024 •

Copy link
Copy Markdown
Member Author

Short answer: my brain cells are (in the sense of "now") too dumb to deal with merge conflicts that came from nowhere.
Plus a month of changes on Nixpkgs codebase.
Plus a month of changes on upstream codebase.
Plus a new upstream release in an unknown future.
Plus a new Nixpkgs release in a too near future.

Times three.

Relevant XKCD.

@GrimmTheShrimp

GrimmTheShrimp commented May 25, 2024 •

Copy link
Copy Markdown
Contributor

You feel like opening a new PR once things have settled down? I can help too if need be, feels a bit cheap telling you what is or isn't a good idea and then not do anything.
And fwiw 24.05 branchoff has happened wednesday, so unstable is open for breaking changes again. The way i see it, i'd probably just end up packaging the unstable-2024-05-25 xonsh version and be done with it until a proper upstream release comes that contains the nix fixes, while keeping/cherry-picking your nice module improvements.

@SamLukeYes SamLukeYes mentioned this pull request May 26, 2024
3 of 13 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

2.status: merge conflict This PR has merge conflicts with the target branch 6.topic: nixos Issues or PRs affecting NixOS modules, or package usability issues specific to NixOS 6.topic: python Python is a high-level, general-purpose programming language. 8.has: module (update) This PR changes an existing module in `nixos/` 8.has: package (new) This PR adds a new package 10.rebuild-darwin: 1-10 This PR causes between 1 and 10 packages to rebuild on Darwin. 10.rebuild-linux: 1-10 This PR causes between 1 and 10 packages to rebuild on Linux. 11.by: package-maintainer This PR was created by a maintainer of all the package it changes.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants