Skip to content

Commit 298b32f

Browse files
committed
adjust setting of conda_exe_name and unify over installer types
1 parent 14bb8d1 commit 298b32f

File tree

6 files changed

+38
-7
lines changed

6 files changed

+38
-7
lines changed

constructor/header.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -496,7 +496,7 @@ CONDA_EXEC="$PREFIX/{{ conda_exe_name }}"
496496
extract_range "${boundary0}" "${boundary1}" > "$CONDA_EXEC"
497497
chmod +x "$CONDA_EXEC"
498498
499-
{%- if conda_exe_name != "_conda" or conda_exe_name != "conda.exe" %}
499+
{%- if conda_exe_name != "_conda" %}
500500
# In case there are packages that depend on _conda
501501
ln -s "$CONDA_EXEC" "$PREFIX"/_conda
502502
{%- endif %}

constructor/osx/prepare_installation.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ unset MAMBARC
3030

3131
chmod +x "$CONDA_EXEC"
3232

33-
{%- if conda_exe_name != "_conda" or conda_exe_name != "conda.exe" %}
33+
{%- if conda_exe_name != "_conda" %}
3434
# In case there are packages that depend on _conda
3535
ln -s "$CONDA_EXEC" "$PREFIX"/_conda
3636
{%- endif %}

constructor/osxpkg.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
approx_size_kb,
2626
copy_conda_exe,
2727
explained_check_call,
28+
format_conda_exe_name,
2829
get_final_channels,
2930
parse_virtual_specs,
3031
rm_rf,
@@ -364,7 +365,7 @@ def move_script(src, dst, info, ensure_shebang=False, user_script_type=None):
364365
variables["no_rcs_arg"] = info.get("_ignore_condarcs_arg", "")
365366
variables["script_env_variables"] = info.get("script_env_variables", {})
366367
variables["initialize_conda"] = info.get("initialize_conda", "classic")
367-
variables["conda_exe_name"] = Path(info["_conda_exe"]).name
368+
variables["conda_exe_name"] = format_conda_exe_name(info["_conda_exe"])
368369

369370
data = render_template(data, **variables)
370371

constructor/shar.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919
from contextlib import nullcontext
2020
from io import BytesIO
2121
from os.path import basename, dirname, getsize, isdir, join, relpath
22-
from pathlib import Path
2322

2423
from .construct import ns_platform
2524
from .jinja import render_template
@@ -31,6 +30,7 @@
3130
approx_size_kb,
3231
copy_conda_exe,
3332
filename_dist,
33+
format_conda_exe_name,
3434
get_final_channels,
3535
hash_files,
3636
parse_virtual_specs,
@@ -111,7 +111,7 @@ def get_header(conda_exec, tarball, info):
111111
virtual_specs = parse_virtual_specs(info)
112112
min_osx_version = virtual_specs.get("__osx", {}).get("min") or ""
113113
variables["min_osx_version"] = min_osx_version
114-
variables["conda_exe_name"] = Path(info["_conda_exe"]).name
114+
variables["conda_exe_name"] = format_conda_exe_name(info["_conda_exe"])
115115
min_glibc_version = virtual_specs.get("__glibc", {}).get("min") or ""
116116
variables["min_glibc_version"] = min_glibc_version
117117

constructor/utils.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -344,6 +344,31 @@ def identify_conda_exe(conda_exe: str | Path | None = None) -> tuple[StandaloneE
344344
return None, None
345345

346346

347+
def format_conda_exe_name(conda_exe: str | Path) -> str:
348+
"""Return a formatted alias for given stand-alone executable.
349+
350+
- If given executable cannot be identified, returns the basename of given executable.
351+
- If stand-alone conda is identified, returns '_conda'.
352+
- If stand-alone mamba/micromamba is identified, returns 'micromamba'.
353+
354+
Parameters::
355+
- conda_exe: str | Path
356+
Path to the conda executable to be accounted for.
357+
"""
358+
conda_exe_name, _ = identify_conda_exe(conda_exe)
359+
if conda_exe_name is None:
360+
# This implies that identify_conda_exe failed
361+
return Path(conda_exe).name
362+
if conda_exe_name == StandaloneExe.CONDA:
363+
return "_conda"
364+
elif conda_exe_name == StandaloneExe.MAMBA:
365+
return "micromamba"
366+
else:
367+
# This should never happen, but as a safe-guard in case `identify_conda_exe` is changed without
368+
# accounting for this function.
369+
raise RuntimeError("Unable to format conda exe name")
370+
371+
347372
def check_version(
348373
exe_version: str | VersionOrder | None = None,
349374
min_version: str | None = None,

tests/test_examples.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,12 @@
2121
from conda.models.version import VersionOrder as Version
2222
from ruamel.yaml import YAML
2323

24-
from constructor.utils import StandaloneExe, check_version, identify_conda_exe
24+
from constructor.utils import (
25+
StandaloneExe,
26+
check_version,
27+
format_conda_exe_name,
28+
identify_conda_exe,
29+
)
2530

2631
if TYPE_CHECKING:
2732
from collections.abc import Generator, Iterable
@@ -663,7 +668,7 @@ def test_macos_signing(tmp_path, self_signed_application_certificate_macos):
663668
# including binary archives like the PlugIns file
664669
cmd = ["pkgutil", "--expand-full", installer, expanded_path]
665670
_execute(cmd)
666-
conda_exe_name = "micromamba" if _is_micromamba(CONSTRUCTOR_CONDA_EXE) else "conda.exe"
671+
conda_exe_name = format_conda_exe_name(CONSTRUCTOR_CONDA_EXE)
667672
components = [
668673
Path(expanded_path, "prepare_installation.pkg", "Payload", "osx-pkg-test", conda_exe_name),
669674
Path(expanded_path, "Plugins", "ExtraPage.bundle"),

0 commit comments

Comments
 (0)