diff --git a/CONSTRUCT.md b/CONSTRUCT.md index 13d88f78d..7440b3967 100644 --- a/CONSTRUCT.md +++ b/CONSTRUCT.md @@ -230,6 +230,14 @@ Notes: thrown if the excluded package is not found in the packages required by the extra environment. To override the global `exclude` value, use an empty list `[]`. +### `register_envs` + +_required:_ no
+_type:_ boolean
+ +Whether to register the environments created by the installer (both `base` and `extra_envs`) +in `~/.conda/environments.txt`. Only compatible with conda-standalone >=23.9. Defaults to `True`. + ### `installer_filename` _required:_ no
diff --git a/constructor/construct.py b/constructor/construct.py index 26e3f91aa..ea246d400 100644 --- a/constructor/construct.py +++ b/constructor/construct.py @@ -163,6 +163,11 @@ To override the global `exclude` value, use an empty list `[]`. '''), + ('register_envs', False, bool, ''' +Whether to register the environments created by the installer (both `base` and `extra_envs`) +in `~/.conda/environments.txt`. Only compatible with conda-standalone >=23.9. Defaults to `True`. +'''), + ('installer_filename', False, str, ''' The filename of the installer being created. If not supplied, a reasonable default will determined by the `name`, `version`, platform, and installer type. diff --git a/constructor/header.sh b/constructor/header.sh index b21a5403a..48db69a8f 100644 --- a/constructor/header.sh +++ b/constructor/header.sh @@ -445,6 +445,7 @@ test -d ~/.conda || mkdir -p ~/.conda >/dev/null 2>/dev/null || test -d ~/.conda printf "\nInstalling base environment...\n\n" +CONDA_REGISTER_ENVS="__REGISTER_ENVS__" \ CONDA_SAFETY_CHECKS=disabled \ CONDA_EXTRA_SAFETY_CHECKS=no \ CONDA_CHANNELS="__CHANNELS__" \ @@ -470,6 +471,7 @@ for env_pkgs in "${PREFIX}"/pkgs/envs/*/; do fi # TODO: custom shortcuts per env? + CONDA_REGISTER_ENVS="__REGISTER_ENVS__" \ CONDA_SAFETY_CHECKS=disabled \ CONDA_EXTRA_SAFETY_CHECKS=no \ CONDA_CHANNELS="$env_channels" \ diff --git a/constructor/osx/run_installation.sh b/constructor/osx/run_installation.sh index 5e770fcf3..b1f562884 100644 --- a/constructor/osx/run_installation.sh +++ b/constructor/osx/run_installation.sh @@ -29,7 +29,8 @@ CONDA_EXEC="$PREFIX/conda.exe" # Perform the conda install notify "Installing packages. This might take a few minutes." -if ! CONDA_SAFETY_CHECKS=disabled \ +if ! CONDA_REGISTER_ENVS="__REGISTER_ENVS__" \ +CONDA_SAFETY_CHECKS=disabled \ CONDA_EXTRA_SAFETY_CHECKS=no \ CONDA_CHANNELS=__CHANNELS__ \ CONDA_PKGS_DIRS="$PREFIX/pkgs" \ @@ -64,6 +65,7 @@ for env_pkgs in "${PREFIX}"/pkgs/envs/*/; do fi # TODO: custom channels per env? # TODO: custom shortcuts per env? + CONDA_REGISTER_ENVS="__REGISTER_ENVS__" \ CONDA_SAFETY_CHECKS=disabled \ CONDA_EXTRA_SAFETY_CHECKS=no \ CONDA_CHANNELS="$env_channels" \ diff --git a/constructor/osxpkg.py b/constructor/osxpkg.py index 22213a596..8c72638c7 100644 --- a/constructor/osxpkg.py +++ b/constructor/osxpkg.py @@ -306,6 +306,7 @@ def move_script(src, dst, info, ensure_shebang=False, user_script_type=None): 'PROGRESS_NOTIFICATIONS': str(info.get('progress_notifications', False)), 'PRE_OR_POST': user_script_type or '__PRE_OR_POST__', 'CONSTRUCTOR_VERSION': info['CONSTRUCTOR_VERSION'], + 'REGISTER_ENVS': str(info.get("register_envs", True)).lower(), } data = preprocess(data, ppd) custom_variables = info.get('script_env_variables', {}) diff --git a/constructor/shar.py b/constructor/shar.py index 178372075..513c6bbf4 100644 --- a/constructor/shar.py +++ b/constructor/shar.py @@ -86,6 +86,7 @@ def get_header(conda_exec, tarball, info): 'CHANNELS': ','.join(get_final_channels(info)), 'CONCLUSION_TEXT': info.get("conclusion_text", "installation finished."), 'pycache': '__pycache__', + 'REGISTER_ENVS': str(info.get("register_envs", True)).lower(), } if has_license: replace['LICENSE'] = read_ascii_only(info['license_file']) diff --git a/constructor/winexe.py b/constructor/winexe.py index 3e22a9485..3ea7c47b8 100644 --- a/constructor/winexe.py +++ b/constructor/winexe.py @@ -132,6 +132,8 @@ def setup_envs_commands(info, dir_path): File "{history_abspath}" # Set channels System::Call 'kernel32::SetEnvironmentVariable(t,t)i("CONDA_CHANNELS", "{channels}").r0' + # Set register_envs + System::Call 'kernel32::SetEnvironmentVariable(t,t)i("CONDA_REGISTER_ENVS", "{register_envs}").r0' # Run conda SetDetailsPrint TextOnly nsExec::ExecToLog '"$INSTDIR\_conda.exe" install --offline -yp "{prefix}" --file "{env_txt}" {shortcuts}' @@ -160,7 +162,8 @@ def setup_envs_commands(info, dir_path): conda_meta=r"$INSTDIR\conda-meta", history_abspath=join(dir_path, "conda-meta", "history"), channels=','.join(get_final_channels(info)), - shortcuts="--no-shortcuts" + shortcuts="--no-shortcuts", + register_envs=str(info.get("register_envs", True)).lower(), ).splitlines() # now we generate one more block per extra env, if present for env_name in info.get("_extra_envs_info", {}): @@ -180,6 +183,7 @@ def setup_envs_commands(info, dir_path): history_abspath=join(dir_path, "envs", env_name, "conda-meta", "history"), channels=",".join(get_final_channels(channel_info)), shortcuts="", + register_envs=str(info.get("register_envs", True)).lower(), ).splitlines() return [line.strip() for line in lines] diff --git a/docs/source/construct-yaml.md b/docs/source/construct-yaml.md index 13d88f78d..7440b3967 100644 --- a/docs/source/construct-yaml.md +++ b/docs/source/construct-yaml.md @@ -230,6 +230,14 @@ Notes: thrown if the excluded package is not found in the packages required by the extra environment. To override the global `exclude` value, use an empty list `[]`. +### `register_envs` + +_required:_ no
+_type:_ boolean
+ +Whether to register the environments created by the installer (both `base` and `extra_envs`) +in `~/.conda/environments.txt`. Only compatible with conda-standalone >=23.9. Defaults to `True`. + ### `installer_filename` _required:_ no
diff --git a/examples/register_envs/construct.yaml b/examples/register_envs/construct.yaml new file mode 100644 index 000000000..5db921d2f --- /dev/null +++ b/examples/register_envs/construct.yaml @@ -0,0 +1,8 @@ +name: RegisterEnvs +version: X +installer_type: all +channels: + - http://repo.anaconda.com/pkgs/main/ +specs: + - python +register_envs: false diff --git a/news/716-register-envs b/news/716-register-envs new file mode 100644 index 000000000..46b22473b --- /dev/null +++ b/news/716-register-envs @@ -0,0 +1,19 @@ +### Enhancements + +* Add support for the `register_envs` option. (#705 via #716) + +### Bug fixes + +* + +### Deprecations + +* + +### Docs + +* + +### Other + +* diff --git a/tests/test_examples.py b/tests/test_examples.py index 0fb9cf4f7..55f3b27d2 100644 --- a/tests/test_examples.py +++ b/tests/test_examples.py @@ -444,3 +444,11 @@ def test_example_from_explicit(tmp_path, request): text=True, ) assert out == (input_path / "explicit_linux-64.txt").read_text() + + +def test_register_envs(tmp_path, request): + input_path = _example_path("register_envs") + for installer, install_dir in create_installer(input_path, tmp_path): + _run_installer(input_path, installer, install_dir, request=request) + environments_txt = Path("~/.conda/environments.txt").expanduser().read_text() + assert str(install_dir) not in environments_txt