-
Notifications
You must be signed in to change notification settings - Fork 359
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 Nushell activation support #2693
Conversation
Your implementation of |
libmamba/data/mamba.nu
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@jonashaag it does (see below). I will write some unit tests. I pushed this when I had to leave, and didn't do extensive testing.
@jonashaag is there a documented environment for development listed somewhere (perhaps private). Yesterday, I was able to build the application but today I'm scratching my head at unresolved dependencies that libmamba cannot find even though they are installed. In particular, it refers to
|
There is documentation on setting up a build environment. If something doesn't work please report a bug. |
I am still piecing together all the parts but made some nice progress so far. I will further test this next week, and will come back here when all tests pass. |
@jonashaag tests with pytest pass now except the ones that fail to find the included added data ({mamba_root_prefix}/etc/profile.d/mamba.nu). To make this file available I added
However my mamba path is not seeing this change. Is this outlined process correct? Thanks in advance! |
We are actually planning to get rid of those files entirely and always only use |
libmamba/data/mamba.nu
Outdated
let argv = arg[1] | ||
|
||
if ($cmd in [ activate deactivate ]){ | ||
$env.MAMBA_EXE $cmd $argv |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't understand how this works. For the other shells we use source
here because we want to change the current shell environment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah I believe you are right. I took this from the fish shell code. I am not too familiar with fish but I believe there it is handled a bit differently. I do some more testing this weekend.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I had a closer look at your earlier remark. The file above makes the micromamba function available to the path. There are some changes to nushell that now deprecates the let-env
command. I have fixed this with the latest commit.
I am having a bit trouble understanding how the shell gets initiated. The PR currently makes micromamba available to to shells. For example micromamba env list
however when I attempt to create a new env or activate it, it generates errors: mamba activate mamba-dev
The shell init command does finish however micromamba shell init nu
~/.config/nushell/config.nu
|
I fumbled a bit around with nushell but I got it working now. It took a bit longer than expected to fully comprehend what the activation function was doing. I was initially thinking the paths were handled internally. I was wrong! |
50ed169
to
a76cc6e
Compare
For posterity's sake, if you want the current environment to be visible in nu shell you need to edit or wrap the left prompt function in
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks a lot for your work on this!
This was a baptism by fire (new to nushell) but I think this is ready to merge @jonashaag. |
@cvanelteren it looks like you're still making improvements to this PR, which is great! Can you please ping me for review once you think this is ready? |
@jonashaag It is done. I was thinking about adding mamba to a separate PR, but adding it was less work. All tests pass here locally except for some windows related ones in micromamba. |
Hm, lots of build failures |
Not sure how the namespace was handled before, but I merged the main branch to fix the errors. Should be fixed now. I am getting some pytest errors relating to bash; 7 fail 2214 pass. |
fca3e69
to
f152113
Compare
@jonashaag should be good now ;-)! |
libmamba/src/core/activation.cpp
Outdated
return ""; | ||
} | ||
|
||
// TODO: check this |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ping
libmamba/src/core/activation.cpp
Outdated
return { "", "" }; | ||
} | ||
|
||
// TODO: check this |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ping
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I replaced a few things with fmt::format but the ternary operator is a big uggly in my opinion. Is this a bit better @jonashaag?
libmamba/src/core/shell_init.cpp
Outdated
content << "$env.MAMBA_ROOT_PREFIX = " << env_prefix << "\n"; | ||
content << "$env.PATH = ($env.PATH | prepend ([$env.MAMBA_ROOT_PREFIX bin] | path join) | uniq)\n"; | ||
content << R""""( | ||
def-env "micromamba activate" [name: string] { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why not do it the way it's done for the other shells? Namely, use shell hook
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The other shell hooks still linked to the data subfolder, I thought you mentioned this was obsolete?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hm, maybe I'm missing something here. For bash, this is part of the shell init
generated code:
__mamba_setup="$("$MAMBA_EXE" shell hook --shell bash --root-prefix "$MAMBA_ROOT_PREFIX" 2> /dev/null)"
This calls into shell hook
which outputs the equivalent of what you inlined here.
libmamba/src/core/activation.cpp
Outdated
possible otherwise returns the command as a string*/ | ||
std::string new_command = command; | ||
std::size_t idx = 0; | ||
bool add = false; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add what?
libmamba/src/core/activation.cpp
Outdated
/*Checks shell variable being set and converts shell lists to nushell lists if | ||
possible otherwise returns the command as a string*/ | ||
std::string new_command = command; | ||
std::size_t idx = 0; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Index of what?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I will clean up the variable names a bit.
libmamba/src/core/activation.cpp
Outdated
std::stringstream out; | ||
auto convert_to_nulist = [](std::string command) | ||
{ | ||
/*Checks shell variable being set and converts shell lists to nushell lists if |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I still have no clue what this function does.
The name indicates it converts something (what?) to a nu list.
The signature indicates it converts a command to a nu list.
The caller indicates it converts an environment variable value to a nu list.
What does it mean to "check shell variable being set"? Are you talking about $SHELL
here? If so I don't find any reference to $SHELL
in the function body. Are you talking about something else?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There is, however, an edge case that this does not consider. Namely if for some reason the evar
being set contains a path with a colon. I am open to suggestion to handle this differently. Edit: I believe in practice this is mutual exclusive as I have never seen paths with colons (except under windows).
libmamba/src/core/activation.cpp
Outdated
|
||
for (const auto& [ekey, evar] : env_transform.export_vars) | ||
{ | ||
// escape parenthesis if present otherwise checks if @evar can be converted to nushell |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Rather than commenting on what is being done here (I can read that much myself!) it would be very helpful to have an explanation of why we are doing it.
Why are we quoting evar
if and only if it contains a (
?
Why are we converting it to something else otherwise?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am pushing my (for now) final changes. Without dedicated source files, it is hard for nu to neatly run dynamically generated code (see here and here). The present setup, therefore, would be a "good enough" approach for it to work. If, however, the profile.d files are not removed, nushell's overlays could be used to neatly package the set environments. As @jonashaag commented, the goal is to remove these files, which makes it difficult to support nu without the ugly code block that is written to the config.nu file. otherwise it works fine. EDIT: although the above is true, I figured out a way around it that is cleaner. Last thing is to integrate the prompt command properly. Currently it is set crudely by editing the existing command. |
Can you please rebase or merge. There are unrelated changes to the CI workflows |
cebdaf8
to
407d5ab
Compare
Cleaned it up @jonashaag ! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for your perseverance, this finally looks good to merge!
<3
libmamba/src/core/shell_init.cpp
Outdated
$env.PATH = ($env.PATH | prepend $"($env.MAMBA_ROOT_PREFIX)/condabin") | ||
} | ||
#ask mamba how to setup the environment and set the environment | ||
(micromamba shell activate --shell nu $name |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should be using $MAMBA_EXE
here?
Happy to help ;-)! Thanks for the reviews and strict look over my shoulder.
See you in a future commit
…On Wed, 13 Sept 2023 at 19:40, Jonas Haag ***@***.***> wrote:
***@***.**** approved this pull request.
Thank you for your perseverance, this finally looks good to merge!
<3
------------------------------
In libmamba/src/core/shell_init.cpp
<#2693 (comment)>:
> + s_mamba_exe = mamba_exe.string();
+ }
+
+ content << "\n# >>> mamba initialize >>>\n";
+ content << "# !! Contents within this block are managed by 'mamba init' !!\n";
+ content << "$env.MAMBA_EXE = " << mamba_exe << "\n";
+ content << "$env.MAMBA_ROOT_PREFIX = " << env_prefix << "\n";
+ content << "$env.PATH = ($env.PATH | prepend ([$env.MAMBA_ROOT_PREFIX bin] | path join) | uniq)\n";
+ content << R"###(def-env "micromamba activate" [name: string] {
+ #add condabin when root
+ if $env.MAMBA_SHLVL? == null {
+ $env.MAMBA_SHLVL = 0
+ $env.PATH = ($env.PATH | prepend $"($env.MAMBA_ROOT_PREFIX)/condabin")
+ }
+ #ask mamba how to setup the environment and set the environment
+ (micromamba shell activate --shell nu $name
Should be using $MAMBA_EXE here?
—
Reply to this email directly, view it on GitHub
<#2693 (review)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AEUVDVYYOUMXKZHGUIQJE73X2HVZVANCNFSM6AAAAAA2RU2UMI>
.
You are receiving this because you were mentioned.Message ID:
***@***.***>
--
- Checkout my website <https://cvanelteren.github.io/> for contact info
and current projects!
|
Looking forward to using this in my shell! Thanks for implementing it! |
No worries @zacharyburnett. For posterity please use #284, until this gets merged this PR has a deactivation bug. |
Hi all,
I made a stat on the nu shell integration ( #2687 ). I will post the commits now for code review and write some unittests later. I was browsing in the unittest directory and saw they were not complete, is this intentional? Looking forward to your thoughts/notes.
Sincerely,
C