Skip to content

Commit

Permalink
Merge branch 'main' of github.com:conda/constructor into jinja
Browse files Browse the repository at this point in the history
  • Loading branch information
jaimergp committed Nov 11, 2024
2 parents 90fb73c + f8cc8d1 commit 93cd75b
Show file tree
Hide file tree
Showing 11 changed files with 94 additions and 17 deletions.
6 changes: 4 additions & 2 deletions CONSTRUCT.md
Original file line number Diff line number Diff line change
Expand Up @@ -122,8 +122,10 @@ A list of virtual packages that must be satisfied at install time. Virtual
packages must start with `__`. For example, `__osx>=11` or `__glibc>=2.24`.
These specs are dry-run solved offline by the bundled `--conda-exe` binary.
In SH installers, `__glibc>=x.y` and `__osx>=x.y` specs can be checked with
Bash only. In PKG installers, `__osx` specs can be checked natively without
the solver being involved as long as only `>=`, `<` or `,` are used.
Bash only. The detected version can be overriden with environment variables
`CONDA_OVERRIDE_GLIBC` and `CONDA_OVERRIDE_OSX`, respectively. In PKG
installers, `__osx` specs can be checked natively without the solver being
involved as long as only `>=`, `<` or `,` are used.

### `exclude`

Expand Down
3 changes: 1 addition & 2 deletions HOW_WE_USE_GITHUB.md
Original file line number Diff line number Diff line change
Expand Up @@ -267,8 +267,7 @@ In order to not have to manually type or copy/paste the above repeatedly, note t

## Commit Signing

For all conda maintainers, we require commit signing and strongly recommend it for all others wishing to contribute to conda
related projects. More information about how to set this up within GitHub can be found here:
For all maintainers, we require commit signing and strongly recommend it for all others wishing to contribute. More information about how to set this up within GitHub can be found here:

- [GitHub's signing commits docs][docs-commit-signing]

Expand Down
6 changes: 4 additions & 2 deletions constructor/construct.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,10 @@
packages must start with `__`. For example, `__osx>=11` or `__glibc>=2.24`.
These specs are dry-run solved offline by the bundled `--conda-exe` binary.
In SH installers, `__glibc>=x.y` and `__osx>=x.y` specs can be checked with
Bash only. In PKG installers, `__osx` specs can be checked natively without
the solver being involved as long as only `>=`, `<` or `,` are used.
Bash only. The detected version can be overriden with environment variables
`CONDA_OVERRIDE_GLIBC` and `CONDA_OVERRIDE_OSX`, respectively. In PKG
installers, `__osx` specs can be checked natively without the solver being
involved as long as only `>=`, `<` or `,` are used.
'''),

('exclude', False, list, '''
Expand Down
11 changes: 6 additions & 5 deletions constructor/header.sh
Original file line number Diff line number Diff line change
Expand Up @@ -23,17 +23,18 @@ fi

{%- if osx and min_osx_version %}
min_osx_version="{{ min_osx_version }}"
system_osx_version=$(SYSTEM_VERSION_COMPAT=0 sw_vers -productVersion)
system_osx_version="${CONDA_OVERRIDE_OSX:-$(SYSTEM_VERSION_COMPAT=0 sw_vers -productVersion)}"
# shellcheck disable=SC2183 disable=SC2046
int_min_osx_version="$(printf "%02d%02d%02d" $(echo "$min_osx_version" | sed 's/\./ /g'))"
# shellcheck disable=SC2183 disable=SC2046
int_system_osx_version="$(printf "%02d%02d%02d" $(echo "$system_osx_version" | sed 's/\./ /g'))"
if [ "$int_system_osx_version" -lt "$int_min_osx_version" ]; then
if [ "$int_system_osx_version" -lt "$int_min_osx_version" ]; then
echo "Installer requires macOS >=${min_osx_version}, but system has ${system_osx_version}."
exit 1
fi
{%- elif linux and min_glibc_version %}
min_glibc_version="{{ min_glibc_version }}"
system_glibc_version="${CONDA_OVERRIDE_GLIBC:-}"
case "$(ldd --version 2>&1)" in
*musl*)
# musl ldd will report musl version; call libc.so directly
Expand All @@ -45,7 +46,7 @@ case "$(ldd --version 2>&1)" in
if [ -z "${libc_so}" ]; then
echo "Warning: Couldn't find libc.so; won't be able to determine GLIBC version!" >&2
echo "Override by setting CONDA_OVERRIDE_GLIBC" >&2
system_glibc_version="${CONDA_OVERRIDE_GLIBC:-0.0}"
system_glibc_version="0.0"
else
system_glibc_version=$("${libc_so}" --version | awk 'NR==1{ sub(/\.$/, ""); print $NF}')
fi
Expand All @@ -59,7 +60,7 @@ esac
int_min_glibc_version="$(printf "%02d%02d%02d" $(echo "$min_glibc_version" | sed 's/\./ /g'))"
# shellcheck disable=SC2183 disable=SC2046
int_system_glibc_version="$(printf "%02d%02d%02d" $(echo "$system_glibc_version" | sed 's/\./ /g'))"
if [ "$int_system_glibc_version" -lt "$int_min_glibc_version" ]; then
if [ "$int_system_glibc_version" -lt "$int_min_glibc_version" ]; then
echo "Installer requires GLIBC >=${min_glibc_version}, but system has ${system_glibc_version}."
exit 1
fi
Expand Down Expand Up @@ -462,7 +463,7 @@ mkdir -p "$TMP"
# but we haven't created $PREFIX/pkgs yet... give it a temp location
# shellcheck disable=SC2050
{%- if virtual_specs %}
echo 'Checking virtual specs compatibility: {{ virtual_specs }}'
echo 'Checking virtual specs compatibility:" {{ virtual_specs }}
CONDA_QUIET="$BATCH" \
CONDA_SOLVER="classic" \
CONDA_PKGS_DIRS="$(mktemp -d)" \
Expand Down
5 changes: 4 additions & 1 deletion constructor/osx/prepare_installation.sh
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,13 @@ touch "$PREFIX/conda-meta/history"
# micromamba needs an existing pkgs_dir to operate even offline,
# but we haven't created $PREFIX/pkgs yet... do it in a temporary location
# shellcheck disable=SC2050
notify 'Checking virtual specs compatibility: {{ virtual_specs }}'
{%- if virtual_specs %}
notify "Checking virtual specs compatibility: {{ virtual_specs }}"
CONDA_SOLVER="classic" \
CONDA_PKGS_DIRS="$(mktemp -d)" \
SYSTEM_VERSION_COMPAT=0 \
"$CONDA_EXEC" create --dry-run --prefix "$PREFIX/envs/_virtual_specs_checks" --offline {{ virtual_specs }} {{ no_rcs_arg }}
{%- endif %}

# Create $PREFIX/.nonadmin if the installation didn't require superuser permissions
if [ "$(id -u)" -ne 0 ]; then
Expand Down
4 changes: 3 additions & 1 deletion constructor/osxpkg.py
Original file line number Diff line number Diff line change
Expand Up @@ -329,6 +329,8 @@ def move_script(src, dst, info, ensure_shebang=False, user_script_type=None):
path_exists_error_text = info.get(
"install_path_exists_error_text", default_path_exists_error_text
).format(CHOSEN_PATH=f"$2/{pkg_name_lower}")
# __osx is tested by the PKG metadata directly, no need to repeat
virtual_specs = [spec for spec in info.get("virtual_specs", ()) if "__osx" not in spec]
variables["pkg_name_lower"] = pkg_name_lower
variables["installer_name"] = info['name']
variables["installer_version"] = info['version']
Expand All @@ -342,7 +344,7 @@ def move_script(src, dst, info, ensure_shebang=False, user_script_type=None):
variables["shortcuts"] = shortcuts_flags(info)
variables["enable_shortcuts"] = str(info['_enable_shortcuts']).lower()
variables["register_envs"] = str(info.get("register_envs", True)).lower()
variables["virtual_specs"] = shlex.join(info.get("virtual_specs", ()))
variables["virtual_specs"] = shlex.join(virtual_specs)
variables["no_rcs_arg"] = info.get('_ignore_condarcs_arg', '')
variables["script_env_variables"] = '\n'.join(
[f"export {key}='{value}'" for key, value in info.get('script_env_variables', {}).items()])
Expand Down
8 changes: 7 additions & 1 deletion constructor/shar.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,12 @@ def get_header(conda_exec, tarball, info):
variables['enable_shortcuts'] = str(info['_enable_shortcuts']).lower()
variables['check_path_spaces'] = info.get("check_path_spaces", True)
install_lines = list(add_condarc(info))
# Omit __osx and __glibc because those are tested with shell code direcly
virtual_specs = [
spec
for spec in info.get("virtual_specs", ())
if "__osx" not in spec and "__glibc" not in spec
]
variables['installer_name'] = name
variables['installer_version'] = info['version']
variables['installer_platform'] = info['_platform']
Expand All @@ -88,7 +94,7 @@ def get_header(conda_exec, tarball, info):
variables['shortcuts'] = shortcuts_flags(info)
variables['register_envs'] = str(info.get("register_envs", True)).lower()
variables['total_installation_size_kb'] = str(approx_size_kb(info, "total"))
variables['virtual_specs'] = shlex.join(info.get("virtual_specs", ()))
variables['virtual_specs'] = shlex.join(virtual_specs)
variables['no_rcs_arg'] = info.get('_ignore_condarcs_arg', '')
if has_license:
variables['license'] = read_ascii_only(info['license_file'])
Expand Down
6 changes: 4 additions & 2 deletions docs/source/construct-yaml.md
Original file line number Diff line number Diff line change
Expand Up @@ -122,8 +122,10 @@ A list of virtual packages that must be satisfied at install time. Virtual
packages must start with `__`. For example, `__osx>=11` or `__glibc>=2.24`.
These specs are dry-run solved offline by the bundled `--conda-exe` binary.
In SH installers, `__glibc>=x.y` and `__osx>=x.y` specs can be checked with
Bash only. In PKG installers, `__osx` specs can be checked natively without
the solver being involved as long as only `>=`, `<` or `,` are used.
Bash only. The detected version can be overriden with environment variables
`CONDA_OVERRIDE_GLIBC` and `CONDA_OVERRIDE_OSX`, respectively. In PKG
installers, `__osx` specs can be checked natively without the solver being
involved as long as only `>=`, `<` or `,` are used.

### `exclude`

Expand Down
19 changes: 19 additions & 0 deletions news/887-vspecs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
### Enhancements

* Do not run conda-based virtual specs tests for `__glibc` and `__osx`. These are already tested by the installation script in an earlier step. (#868 via #887)

### Bug fixes

* Address quoting issue that created unneeded files in installation directory. (#865 via #887)

### Deprecations

* <news item>

### Docs

* <news item>

### Other

* <news item>
19 changes: 19 additions & 0 deletions news/888-overrides-vpkgs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
### Enhancements

* Allow `__glibc` and `__osx` overrides with `CONDA_OVERRIDE_GLIBC` and `CONDA_OVERRIDE_OSX` environment variables, respectively (`.sh` installers only). (#888)

### Bug fixes

* <news item>

### Deprecations

* <news item>

### Docs

* <news item>

### Other

* <news item>
24 changes: 23 additions & 1 deletion tests/test_examples.py
Original file line number Diff line number Diff line change
Expand Up @@ -339,7 +339,11 @@ def _sort_by_extension(path):
)
yield installer, install_dir
if KEEP_ARTIFACTS_PATH:
shutil.move(str(installer), str(KEEP_ARTIFACTS_PATH))
try:
shutil.move(str(installer), str(KEEP_ARTIFACTS_PATH))
except shutil.Error:
# Some tests reuse the examples for different checks; ignore errors
pass


@lru_cache(maxsize=None)
Expand Down Expand Up @@ -844,6 +848,24 @@ def test_virtual_specs_ok(tmp_path, request):
)


@pytest.mark.skipif(sys.platform.startswith("win"), reason="Unix only")
def test_virtual_specs_override(tmp_path, request, monkeypatch):
input_path = _example_path("virtual_specs_failed")
for installer, install_dir in create_installer(input_path, tmp_path):
if installer.name.endswith(".pkg"):
continue
monkeypatch.setenv("CONDA_OVERRIDE_GLIBC", "20")
monkeypatch.setenv("CONDA_OVERRIDE_OSX", "30")
_run_installer(
input_path,
installer,
install_dir,
request=request,
check_subprocess=True,
uninstall=True,
)


@pytest.mark.xfail(
CONDA_EXE == StandaloneExe.CONDA and CONDA_EXE_VERSION < Version("24.9.0"),
reason="Pre-existing .condarc breaks installation",
Expand Down

0 comments on commit 93cd75b

Please sign in to comment.