forked from nushell/nu_scripts
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Change conda activation scripts to be a module (nushell#205)
- Loading branch information
Showing
3 changed files
with
114 additions
and
58 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,45 +1,28 @@ | ||
# Virtual environment scripts | ||
|
||
The scripts in this directory activate virtual environments for Conda environments. They follow the pattern described in the [Nushell 0.32 | ||
changelog](https://www.nushell.sh/blog/2021-06-01-nushell_0_32.html#environment-loading-lily-mara): | ||
The scripts in this directory activate virtual environments for Conda environments. | ||
|
||
``` | ||
$ load-env (activate some-env) | ||
``` | ||
|
||
A custom command (`activate`) creates a table with environment variables and | ||
`load-env` is used to load it into the shell's scope. | ||
## Usage | ||
|
||
In most cases, deactivation is a matter of restoring the PATH variable to the | ||
state before activating the env and removing any additional variables. There are | ||
no environment-specific elements to this, which is why the same deactivation | ||
script can be used for deactivating any environment of a specific type. For | ||
example, `source conda_deactivate.nu` will deactivate any Conda env, there are | ||
no input parameters. | ||
The activation and deactivation commands are exported from the `conda` module. | ||
|
||
## Expected Usage | ||
|
||
1. Source an activation script in your `config.nu`. For example, `conda.nu`. | ||
You'll then have the `conda-env` command available. | ||
2. Create an alias for sourcing the appropriate deactivation script: | ||
`alias conda-deactivate = source /path/to/conda_deactivate.nu` | ||
3. Activate with `load-env (conda-env env-name)`. You might want to define some | ||
shorter aliases for both commands, if typing that every time seems like a | ||
hassle. | ||
4. If you're using [Starship](https://starship.rs/), your prompt should reflect the activated env. | ||
5. When done, deactivate with your alias: `conda-deactivate`. | ||
``` | ||
> use conda.nu | ||
> conda activate foo | ||
[foo] > conda deactivate | ||
> | ||
``` | ||
|
||
Look at the script files to find the exact command name for creating an environment table. | ||
Do disable the prompt changes (e.g., to let [Starship](https://starship.rs) include its own), pass a `--no-prompt` flag to `activate`. | ||
The `activate` command includes custom completions for the environment names. | ||
|
||
## `conda.nu` | ||
## Limitations | ||
|
||
Limitations: | ||
_(old text, not tested)_ | ||
|
||
- The "root_prefix" might not actually correspond to the correct path to the Conda envs. You can fix | ||
this for your setup by changing how the root prefix is found in the `conda-env` command. | ||
- Nested envs are not well supported. If you activate a Conda env while another one is | ||
activated, new elements will be appended to the PATH, but the other environment | ||
variables will be overwritten. There's no way to then restore the PATH to the state | ||
it was in before activating the *first* env (at least not with this script directly). | ||
- The prompt is not updated by the script. Consider using [Starship](https://starship.rs/) | ||
with the Python prompt element. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.