MCPcopy Create free account
hub / github.com/conda/constructor / move_script

Function move_script

constructor/osxpkg.py:368–423  ·  view source on GitHub ↗

Fill template scripts checks_before_install.sh, prepare_installation.sh and others, and move them to the installer workspace.

(src, dst, info, ensure_shebang=False, user_script_type=None)

Source from the content-addressed store, hash-verified

366
367
368def move_script(src, dst, info, ensure_shebang=False, user_script_type=None):
369 """
370 Fill template scripts checks_before_install.sh, prepare_installation.sh and others,
371 and move them to the installer workspace.
372 """
373 assert user_script_type in (None, "pre_install", "post_install")
374 with open(src) as fi:
375 data = fi.read()
376
377 # ppd hosts the conditions for the #if/#else/#endif preprocessors on scripts
378 variables = ns_platform(info["_platform"])
379 variables["check_path_spaces"] = bool(info.get("check_path_spaces", True))
380
381 # This is necessary for when installing on case-sensitive macOS filesystems.
382 pkg_name_lower = info.get("pkg_name", info["name"]).lower()
383 default_path_exists_error_text = (
384 "'{CHOSEN_PATH}' already exists. Please, relaunch the installer and "
385 "choose another location in the Destination Select step."
386 )
387 path_exists_error_text = info.get(
388 "install_path_exists_error_text", default_path_exists_error_text
389 ).format(CHOSEN_PATH=f"$2/{pkg_name_lower}")
390 # __osx is tested by the PKG metadata directly, no need to repeat
391 virtual_specs = [spec for spec in info.get("virtual_specs", ()) if "__osx" not in spec]
392 variables["pkg_name_lower"] = pkg_name_lower
393 variables["installer_name"] = info["name"]
394 variables["installer_version"] = info["version"]
395 variables["installer_platform"] = info["_platform"]
396 variables["final_channels"] = get_final_channels(info)
397 variables["path_exists_error_text"] = path_exists_error_text
398 variables["progress_notifications"] = info.get("progress_notifications", False)
399 variables["pre_or_post"] = user_script_type or "__PRE_OR_POST__"
400 variables["constructor_version"] = info["CONSTRUCTOR_VERSION"]
401 variables["shortcuts"] = shortcuts_flags(info)
402 variables["enable_shortcuts"] = str(info["_enable_shortcuts"]).lower()
403 variables["register_envs"] = str(info.get("register_envs", True)).lower()
404 variables["virtual_specs"] = shlex.join(virtual_specs)
405 variables["no_rcs_arg"] = info.get("_ignore_condarcs_arg", "")
406 variables["script_env_variables"] = info.get("script_env_variables", {})
407 variables["initialize_conda"] = info.get("initialize_conda", "classic")
408 variables["conda_exe_name"] = format_conda_exe_name(info["_conda_exe"])
409
410 data = render_template(data, **variables)
411
412 with open(dst, "w") as fo:
413 if (
414 ensure_shebang
415 and os.path.splitext(dst)[1] in ("", ".sh")
416 and not data.startswith(("#!/bin/bash", "#!/bin/sh"))
417 ):
418 # Shell scripts provided by the user require a shebang, otherwise it
419 # will fail to start with error posix_spawn 8
420 # We only handle shell scripts this way
421 fo.write("#!/bin/bash\n")
422 fo.write(data)
423 os.chmod(dst, 0o755)
424
425

Callers 2

pkgbuild_scriptFunction · 0.85
createFunction · 0.85

Calls 6

ns_platformFunction · 0.85
get_final_channelsFunction · 0.85
shortcuts_flagsFunction · 0.85
format_conda_exe_nameFunction · 0.85
render_templateFunction · 0.85
getMethod · 0.80

Tested by

no test coverage detected