Skip to content

Commit

Permalink
Add option for the new register_envs (#716)
Browse files Browse the repository at this point in the history
* Add option for the new `register_envs`

* not required, but default is indeed True

* update docs

* add test

* add news

* sync docs
  • Loading branch information
jaimergp authored Oct 10, 2023
1 parent 2302872 commit 05c1022
Show file tree
Hide file tree
Showing 11 changed files with 68 additions and 2 deletions.
8 changes: 8 additions & 0 deletions CONSTRUCT.md
Original file line number Diff line number Diff line change
Expand Up @@ -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<br/>
_type:_ boolean<br/>

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<br/>
Expand Down
5 changes: 5 additions & 0 deletions constructor/construct.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
2 changes: 2 additions & 0 deletions constructor/header.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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__" \
Expand All @@ -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" \
Expand Down
4 changes: 3 additions & 1 deletion constructor/osx/run_installation.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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" \
Expand Down Expand Up @@ -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" \
Expand Down
1 change: 1 addition & 0 deletions constructor/osxpkg.py
Original file line number Diff line number Diff line change
Expand Up @@ -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', {})
Expand Down
1 change: 1 addition & 0 deletions constructor/shar.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'])
Expand Down
6 changes: 5 additions & 1 deletion constructor/winexe.py
Original file line number Diff line number Diff line change
Expand Up @@ -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}'
Expand Down Expand Up @@ -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", {}):
Expand All @@ -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]
Expand Down
8 changes: 8 additions & 0 deletions docs/source/construct-yaml.md
Original file line number Diff line number Diff line change
Expand Up @@ -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<br/>
_type:_ boolean<br/>

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<br/>
Expand Down
8 changes: 8 additions & 0 deletions examples/register_envs/construct.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
name: RegisterEnvs
version: X
installer_type: all
channels:
- http://repo.anaconda.com/pkgs/main/
specs:
- python
register_envs: false
19 changes: 19 additions & 0 deletions news/716-register-envs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
### Enhancements

* Add support for the `register_envs` option. (#705 via #716)

### Bug fixes

* <news item>

### Deprecations

* <news item>

### Docs

* <news item>

### Other

* <news item>
8 changes: 8 additions & 0 deletions tests/test_examples.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 05c1022

Please sign in to comment.