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

Add pixi global list and pixi global remove commands #318

Merged
merged 6 commits into from
Sep 11, 2023

Conversation

cjfuller
Copy link
Contributor

@cjfuller cjfuller commented Sep 2, 2023

This fixes #314 and #50 by adding two new global commands global list and global remove for inspecting and removing the globally installed packages.

In order to avoid having to try to map back the installed binaries to their source packages via parsing the shell scripts or something, the general approach I took here was to add a dry run option to the function that generates the binary scripts, such that we can re-run the script generation on list or remove to see what files would be generated for a given package and thus belong to that package. (This strategy has at least two small flaws: it's not very backwards compatible if pixi decides to change the names of the generated files at some point, and it's not robust to two different packages installing a binary with the same name. The former could perhaps be fixed later by writing some kind of manifest into the env instead that persists the list of generates files? The latter could be fixed by refusing to install two binaries with the same name at install time?)

I didn't see a test harness that can run automated tests of the global commands, so I tested manually using the following steps. (Happy to go back and add automated tests if there is such a harness and I just missed it.)

Manual test steps:

# test an add/remove cycle:
pixi (global_remove_and_list) $ cargo run -- global install starship
    Finished dev [unoptimized + debuginfo] target(s) in 0.14s
     Running `target/debug/pixi global install starship`
✔ Installed package starship 1.16.0 h725e511_0 from conda-forge
  These apps are now globally available:
   -  starship
pixi (global_remove_and_list) $ ls ~/.pixi/bin
starship
pixi (global_remove_and_list) $ ls ~/.pixi/envs
starship
pixi (global_remove_and_list) $ cargo run -- global remove starship
    Finished dev [unoptimized + debuginfo] target(s) in 0.17s
     Running `target/debug/pixi global remove starship`
✔ Successfully removed global package starship
pixi (global_remove_and_list) $ ls ~/.pixi/bin
pixi (global_remove_and_list) $ ls ~/.pixi/envs
pixi (global_remove_and_list) $ cargo run -- global remove starship
    Finished dev [unoptimized + debuginfo] target(s) in 0.17s
     Running `target/debug/pixi global remove starship`
  × could not find environment for package starship

# test an add/remove cycle with `--verbose` for remove:
pixi (global_remove_and_list) $ cargo run -- global install starship
    Finished dev [unoptimized + debuginfo] target(s) in 0.15s
     Running `target/debug/pixi global install starship`
✔ Installed package starship 1.16.0 h725e511_0 from conda-forge
  These apps are now globally available:
   -  starship
pixi (global_remove_and_list) $ ls ~/.pixi/bin
starship
pixi (global_remove_and_list) $ ls ~/.pixi/envs
starship
pixi (global_remove_and_list) $ cargo run -- global remove starship --verbose
    Finished dev [unoptimized + debuginfo] target(s) in 0.14s
     Running `target/debug/pixi global remove starship --verbose`
! Removing the following files and directories:
   -  /home/colin/.pixi/envs/starship
   -  /home/colin/.pixi/bin/starship
✔ Successfully removed global package starship
pixi (global_remove_and_list) $ ls ~/.pixi/bin
pixi (global_remove_and_list) $ ls ~/.pixi/envs
pixi (global_remove_and_list) $ cargo run -- global remove starship
    Finished dev [unoptimized + debuginfo] target(s) in 0.17s
     Running `target/debug/pixi global remove starship`
  × could not find environment for package starship

# Test list for both python, which has multiple binaries, and starship, which has one
pixi (global_remove_and_list) $ cargo run -- global list
    Finished dev [unoptimized + debuginfo] target(s) in 0.10s
     Running `target/debug/pixi global list`
! No globally installed binaries found
pixi (global_remove_and_list) $ cargo run -- global install python==3.11
    Finished dev [unoptimized + debuginfo] target(s) in 0.17s
     Running `target/debug/pixi global install python==3.11`
✔ Installed package python 3.11.0 he550d4f_1_cpython from conda-forge
  These apps are now globally available:
   -  2to3
   -  2to3-3
   -  idle3
   -  idle3
   -  pydoc
   -  pydoc3
   -  pydoc3
   -  python
   -  python3
   -  python3-config
   -  python3
   -  python3
   -  python3
pixi (global_remove_and_list) $ cargo run -- global list
    Finished dev [unoptimized + debuginfo] target(s) in 0.15s
     Running `target/debug/pixi global list`
Globally installed binary packages:
  -  [package] python
     -  [bin] idle3
     -  [bin] python
     -  [bin] pydoc3
     -  [bin] python3-config
     -  [bin] 2to3-3
     -  [bin] 2to3
     -  [bin] python3
     -  [bin] pydoc
pixi (global_remove_and_list) $ cargo run -- global install starship
    Finished dev [unoptimized + debuginfo] target(s) in 0.16s
     Running `target/debug/pixi global install starship`
✔ Installed package starship 1.16.0 h725e511_0 from conda-forge
  These apps are now globally available:
   -  starship
pixi (global_remove_and_list) $ cargo run -- global list
    Finished dev [unoptimized + debuginfo] target(s) in 0.10s
     Running `target/debug/pixi global list`
Globally installed binary packages:
  -  [package] python
     -  [bin] 2to3-3
     -  [bin] python3
     -  [bin] pydoc
     -  [bin] python
     -  [bin] 2to3
     -  [bin] idle3
     -  [bin] pydoc3
     -  [bin] python3-config
  -  [package] starship
     -  [bin] starship
pixi (global_remove_and_list) $ cargo run -- global remove python --verbose
    Finished dev [unoptimized + debuginfo] target(s) in 0.15s
     Running `target/debug/pixi global remove python --verbose`
! Removing the following files and directories:
   -  /home/colin/.pixi/envs/python
   -  /home/colin/.pixi/bin/pydoc3
   -  /home/colin/.pixi/bin/python3-config
   -  /home/colin/.pixi/bin/pydoc
   -  /home/colin/.pixi/bin/python3
   -  /home/colin/.pixi/bin/idle3
   -  /home/colin/.pixi/bin/2to3-3
   -  /home/colin/.pixi/bin/python
   -  /home/colin/.pixi/bin/2to3
✔ Successfully removed global package python
pixi (global_remove_and_list) $ cargo run -- global list
    Finished dev [unoptimized + debuginfo] target(s) in 0.10s
     Running `target/debug/pixi global list`
Globally installed binary packages:
  -  [package] starship
     -  [bin] starship
pixi (global_remove_and_list) $ cargo run -- global remove starship
    Finished dev [unoptimized + debuginfo] target(s) in 0.14s
     Running `target/debug/pixi global remove starship`
✔ Successfully removed global package starship
pixi (global_remove_and_list) $ cargo run -- global list
    Finished dev [unoptimized + debuginfo] target(s) in 0.16s
     Running `target/debug/pixi global list`
! No globally installed binaries found

src/cli/global/remove.rs Outdated Show resolved Hide resolved
@Wackyator
Copy link
Contributor

Wackyator commented Sep 4, 2023

Hey @cjfuller, thanks alot for contributing, it looks good to me. Just had a few small nits.

Copy link
Contributor

@baszalmstra baszalmstra left a comment

Choose a reason for hiding this comment

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

Thanks for this contribution!

I see some room for improvement with regards to the architecture. Specifically I think it would be good to split the different responsibilities of finding the executables, creating executables scripts and writing those to disk. That will make them easier to reuse without requiring dryrunning.

src/cli/global/install.rs Show resolved Hide resolved
src/cli/global/install.rs Show resolved Hide resolved
@cjfuller
Copy link
Contributor Author

cjfuller commented Sep 9, 2023

Sorry for the delay! (Didn't have much spare time during the work week this week.) Should be ready for another look.

I did the split, though along slightly different lines than you suggested. There's now one part that does the path construction and mapping from the binaries in the environment to the globally installed binaries, and another that builds the script content and writes it to the global binary location. (We only needed the path part for remove/list, not the actual content, so I just split out the shared parts.)

@baszalmstra
Copy link
Contributor

This looks great now @cjfuller ! I'm just waiting for CI and then I'll merge. Thank you!

@baszalmstra baszalmstra merged commit 40b479e into prefix-dev:main Sep 11, 2023
9 checks passed
@cjfuller cjfuller deleted the global_remove_and_list branch September 11, 2023 14:11
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.

pixi global: list and uninstall
3 participants