1
Fork 0
mirror of https://github.com/RGBCube/nu_scripts synced 2025-08-01 06:37:46 +00:00
nu_scripts/modules/virtual_environments/auto-venv
Elizabeth eedcd10dbb
Fixed sys usage (#916)
Just as a heads up, I haven't really tested this since a lot of it is
stuff I don't use or know how to set up without some reading up. I have
tested the nu_conda_2 change since I have a python project that I use
that for, and I could look into testing more of it if needed.

I've tried finding (naively using `/sys\W/`) all the usage of the old
plain `sys` calls and replacing them with alternates as appropriate,
which mostly has been to swap a `(sys).host.name` call into a
`$nu.os-info.name` one, since it'll be tad faster and more consistent
across platforms with naming (especially as the value comes from the
[rust stdlib](https://doc.rust-lang.org/std/env/consts/constant.OS.html)
and is very predictable).

Fixes #897
2024-07-24 09:09:31 -05:00
..
venvs Fixed sys usage (#916) 2024-07-24 09:09:31 -05:00
auto-venv.nu Replace use of $nothing with null (#621) 2023-09-26 18:52:49 +02:00
path_extensions.nu Replace use of $nothing with null (#621) 2023-09-26 18:52:49 +02:00
README.md use $env. instead of let-env (#543) 2023-07-01 10:40:16 +02:00
venv_helpers.nu Fixed sys usage (#916) 2024-07-24 09:09:31 -05:00

Auto virtual environment scripts

The scripts in this directory activate virtual environments whenever you cd into a directory with a "trigger" file

Usage

  1. set $env.AUTO_VENV_TRIGGER as the preferred name of a trigger file
  2. import auto-venv into your environment
  3. Create a symlink via ln -s of the script file ./auto-venv/venvs/python-venv.nu to a trigger file in project at /path/to/project/$AUTO_VENV_TRIGGER
  4. cd into /path/to/project/

For example:

# config.nu

export-env {
    $env.AUTO_VENV_TRIGGER = '__auto-venv.nu'

    source-env ~/path/to/nu_scripts/modules/virtual_environments/auto-venv/auto-venv.nu
}

use ~/path/to/nu_scripts/modules/virtual_environments/auto-venv/auto-venv.nu *

When auto-venv detects that a file of that name exists in the folder you cd'ed into (or one of it's parents), it will automatically enable an overlay (as defined by the trigger file).

An example overlay for python venv is in ./venvs

NOTE: the trigger file must export a custom command called auto-venv-on-enter that takes in the $env (this is the environment before the overlay was enabled).

Limitations

  • Due to limitations with overlay naming, you cannot nest auto-venv triggers, even for separate languages / toolchains