Skip to content

Commit e524000

Browse files
Preserve name of conda exe (#1090)
* Fix issue with hardcoded conda exe * Fix formatting * Add quotes and test adjustments * Add missing quotes * Adjust osxpkg handling of _conda * Update macOS test, conda.exe instead of _conda * add news * Update test to account for CONSTRUCTOR_CONDA_EXE * Fix formatting and update the news * adjust setting of conda_exe_name and unify sh and pkg installers * Rename news file * Update news * Apply suggestion from @marcoesters --------- Co-authored-by: Marco Esters <[email protected]>
1 parent 7af5983 commit e524000

File tree

10 files changed

+77
-9
lines changed

10 files changed

+77
-9
lines changed

constructor/header.sh

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -495,9 +495,15 @@ unset PYTHON_SYSCONFIGDATA_NAME _CONDA_PYTHON_SYSCONFIGDATA_NAME
495495
496496
# the first binary payload: the standalone conda executable
497497
printf "Unpacking bootstrapper...\n"
498-
CONDA_EXEC="$PREFIX/_conda"
498+
CONDA_EXEC="$PREFIX/{{ conda_exe_name }}"
499499
extract_range "${boundary0}" "${boundary1}" > "$CONDA_EXEC"
500500
chmod +x "$CONDA_EXEC"
501+
502+
{%- if conda_exe_name != "_conda" %}
503+
# In case there are packages that depend on _conda
504+
ln -s "$CONDA_EXEC" "$PREFIX"/_conda
505+
{%- endif %}
506+
501507
{%- for filename, (start, end, executable) in conda_exe_payloads|items %}
502508
mkdir -p "$(dirname "$PREFIX/{{ filename }}")"
503509
{%- if start == end %}

constructor/osx/prepare_installation.sh

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,19 @@ PREFIX="$2/{{ pkg_name_lower }}"
2222
PREFIX=$(cd "$PREFIX"; pwd)
2323
export PREFIX
2424
echo "PREFIX=$PREFIX"
25-
CONDA_EXEC="$PREFIX/_conda"
25+
CONDA_EXEC="$PREFIX/{{ conda_exe_name }}"
2626
# Installers should ignore pre-existing configuration files.
2727
unset CONDARC
2828
unset MAMBARC
2929
# /COMMON UTILS
3030

3131
chmod +x "$CONDA_EXEC"
3232

33+
{%- if conda_exe_name != "_conda" %}
34+
# In case there are packages that depend on _conda
35+
ln -s "$CONDA_EXEC" "$PREFIX"/_conda
36+
{%- endif %}
37+
3338
# Create a blank history file so conda thinks this is an existing env
3439
mkdir -p "$PREFIX/conda-meta"
3540
touch "$PREFIX/conda-meta/history"

constructor/osx/run_installation.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ PREFIX="$2/{{ pkg_name_lower }}"
2626
PREFIX=$(cd "$PREFIX"; pwd)
2727
export PREFIX
2828
echo "PREFIX=$PREFIX"
29-
CONDA_EXEC="$PREFIX/_conda"
29+
CONDA_EXEC="$PREFIX/{{ conda_exe_name }}"
3030
# Installers should ignore pre-existing configuration files.
3131
unset CONDARC
3232
unset MAMBARC

constructor/osx/run_user_script.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ PREFIX="$2/{{ pkg_name_lower }}"
2222
PREFIX=$(cd "$PREFIX"; pwd)
2323
export PREFIX
2424
echo "PREFIX=$PREFIX"
25-
CONDA_EXEC="$PREFIX/_conda"
25+
CONDA_EXEC="$PREFIX/{{ conda_exe_name }}"
2626
# /COMMON UTILS
2727

2828
# Expose these to user scripts as well

constructor/osxpkg.py

Lines changed: 6 additions & 3 deletions
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,6 +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")
368+
variables["conda_exe_name"] = format_conda_exe_name(info["_conda_exe"])
367369

368370
data = render_template(data, **variables)
369371

@@ -556,7 +558,7 @@ def create(info, verbose=False):
556558

557559
# 1. Prepare installation
558560
# The 'prepare_installation' package contains the prepopulated package cache, the modified
559-
# conda-meta metadata staged into pkgs/conda-meta, _conda (conda-standalone),
561+
# conda-meta metadata staged into pkgs/conda-meta, _conda (conda-standalone, [--conda-exe]),
560562
# Optionally, extra files and the user-provided scripts.
561563
# We first populate PACKAGE_ROOT with everything needed, and then run pkg build on that dir
562564
fresh_dir(PACKAGE_ROOT)
@@ -593,7 +595,8 @@ def create(info, verbose=False):
593595
for dist in all_dists:
594596
os.link(join(CACHE_DIR, dist), join(pkgs_dir, dist))
595597

596-
copy_conda_exe(prefix, "_conda", info["_conda_exe"])
598+
exe_name = format_conda_exe_name(info["_conda_exe"])
599+
copy_conda_exe(prefix, exe_name, info["_conda_exe"])
597600

598601
# Sign conda-standalone so it can pass notarization
599602
codesigner = None
@@ -608,7 +611,7 @@ def create(info, verbose=False):
608611
"com.apple.security.cs.disable-library-validation": True,
609612
"com.apple.security.cs.allow-dyld-environment-variables": True,
610613
}
611-
codesigner.sign_bundle(join(prefix, "_conda"), entitlements=entitlements)
614+
codesigner.sign_bundle(join(prefix, exe_name), entitlements=entitlements)
612615

613616
# This script checks to see if the install location already exists and/or contains spaces
614617
# Not to be confused with the user-provided pre_install!

constructor/shar.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
approx_size_kb,
3131
copy_conda_exe,
3232
filename_dist,
33+
format_conda_exe_name,
3334
get_final_channels,
3435
hash_files,
3536
parse_virtual_specs,
@@ -110,6 +111,7 @@ def get_header(conda_exec, tarball, info):
110111
virtual_specs = parse_virtual_specs(info)
111112
min_osx_version = virtual_specs.get("__osx", {}).get("min") or ""
112113
variables["min_osx_version"] = min_osx_version
114+
variables["conda_exe_name"] = format_conda_exe_name(info["_conda_exe"])
113115
min_glibc_version = virtual_specs.get("__glibc", {}).get("min") or ""
114116
variables["min_glibc_version"] = min_glibc_version
115117

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,

news/1090-mamba-standalone-fix

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
### Enhancements
2+
3+
* <news item>
4+
5+
### Bug fixes
6+
7+
* Rename mamba-based standalone binaries to `micromamba` and create a symbolic link to `_conda` for backwards compatibility. (#1033 via #1090)
8+
9+
### Deprecations
10+
11+
* <news item>
12+
13+
### Docs
14+
15+
* <news item>
16+
17+
### Other
18+
19+
* <news item>

tests/test_examples.py

Lines changed: 8 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,8 +668,9 @@ 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)
671+
conda_exe_name = format_conda_exe_name(CONSTRUCTOR_CONDA_EXE)
666672
components = [
667-
Path(expanded_path, "prepare_installation.pkg", "Payload", "osx-pkg-test", "_conda"),
673+
Path(expanded_path, "prepare_installation.pkg", "Payload", "osx-pkg-test", conda_exe_name),
668674
Path(expanded_path, "Plugins", "ExtraPage.bundle"),
669675
]
670676
validated_signatures = []

tests/test_header.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ def test_osxpkg_scripts_shellcheck(arch, check_path_spaces, script):
7070
no_rcs_arg="",
7171
script_env_variables={},
7272
initialize_conda="condabin",
73+
conda_exe_name="_conda",
7374
)
7475

7576
findings, returncode = run_shellcheck(processed)
@@ -162,6 +163,7 @@ def test_template_shellcheck(
162163
"write_condarc": "",
163164
"conda_exe_payloads": conda_exe_payloads_and_size[0],
164165
"conda_exe_payloads_size": conda_exe_payloads_and_size[1],
166+
"conda_exe_name": "_conda",
165167
},
166168
)
167169

0 commit comments

Comments
 (0)