22
33import argparse
44import os
5+ import platform
56import shlex
67import shutil
78import subprocess
89import sys
910from pathlib import Path
1011
12+ CONDA_PLATFORM_MAP = {
13+ ('linux' , 'x86_64' ): 'linux-64' ,
14+ ('linux' , 'aarch64' ): 'linux-aarch64' ,
15+ ('linux' , 'ppc64le' ): 'linux-ppc64le' ,
16+ ('osx' , 'x86_64' ): 'osx-64' ,
17+ ('osx' , 'arm64' ): 'osx-arm64' ,
18+ }
19+
20+ LOCAL_MACHE_SOURCE_ENV = 'MACHE_LOCAL_SOURCE_PATH'
21+ PIXI_ENV_VARS_TO_UNSET = (
22+ 'PIXI_PROJECT_MANIFEST' ,
23+ 'PIXI_PROJECT_ROOT' ,
24+ 'PIXI_ENVIRONMENT_NAME' ,
25+ 'PIXI_IN_SHELL' ,
26+ )
27+
1128
1229def check_call (
1330 commands ,
@@ -197,7 +214,7 @@ def build_pixi_shell_hook_prefix(*, pixi_exe: str, pixi_toml: str) -> str:
197214 running a nested shell process.
198215 """
199216 hook_cmd = (
200- 'env -u PIXI_PROJECT_MANIFEST -u PIXI_PROJECT_ROOT '
217+ f' { build_pixi_env_unset_prefix () } '
201218 f'{ shlex .quote (pixi_exe )} shell-hook -s bash -m '
202219 f'{ shlex .quote (pixi_toml )} '
203220 )
@@ -353,7 +370,7 @@ def _run(log_filename):
353370
354371 cmd_install = (
355372 f'cd "{ bootstrap_dir } " && '
356- 'env -u PIXI_PROJECT_MANIFEST -u PIXI_PROJECT_ROOT '
373+ f' { build_pixi_env_unset_prefix () } '
357374 f'"{ pixi_exe } " install'
358375 )
359376 check_call (cmd_install , log_filename , quiet )
@@ -380,7 +397,7 @@ def _run(log_filename):
380397
381398 cmd_install = (
382399 f'cd "{ bootstrap_dir } " && '
383- 'env -u PIXI_PROJECT_MANIFEST -u PIXI_PROJECT_ROOT '
400+ f' { build_pixi_env_unset_prefix () } '
384401 f'"{ pixi_exe } " install'
385402 )
386403 check_call (cmd_install , log_filename , quiet )
@@ -569,6 +586,23 @@ def _default_pixi_path():
569586 return os .path .join (home , '.pixi' , 'bin' , 'pixi' )
570587
571588
589+ def build_pixi_env_unset_prefix ():
590+ return 'env ' + ' ' .join (f'-u { name } ' for name in PIXI_ENV_VARS_TO_UNSET )
591+
592+
593+ def _get_pixi_platform ():
594+ system = platform .system ().lower ()
595+ if system == 'darwin' :
596+ system = 'osx'
597+ machine = platform .machine ().lower ()
598+ try :
599+ return CONDA_PLATFORM_MAP [(system , machine )]
600+ except KeyError as exc :
601+ raise ValueError (
602+ f'Unsupported platform for pixi bootstrap: { system } { machine } '
603+ ) from exc
604+
605+
572606def _install_pixi (* , log_filename , quiet , pixi_bin_dir = None ):
573607 env_prefix_parts = [
574608 # Avoid modifying shell rc files during bootstrap.
@@ -672,6 +706,7 @@ def _write_bootstrap_pixi_toml_with_mache(
672706 '[workspace]' ,
673707 f'name = "{ name } "' ,
674708 'channels = ["conda-forge"]' ,
709+ f'platforms = ["{ _get_pixi_platform ()} "]' ,
675710 'channel-priority = "strict"' ,
676711 '' ,
677712 '[dependencies]' ,
@@ -712,6 +747,32 @@ def _clone_mache_repo(
712747
713748 build_root .mkdir (parents = True , exist_ok = True )
714749
750+ local_source = os .environ .get (LOCAL_MACHE_SOURCE_ENV )
751+ if local_source :
752+ source_repo = Path (
753+ os .path .abspath (os .path .expanduser (local_source ))
754+ ).resolve ()
755+ if not source_repo .is_dir ():
756+ raise RuntimeError (
757+ f'Local mache source override does not exist: { source_repo } '
758+ )
759+
760+ try :
761+ os .symlink (source_repo , repo_dir , target_is_directory = True )
762+ except OSError :
763+ shutil .copytree (
764+ source_repo ,
765+ repo_dir ,
766+ ignore = shutil .ignore_patterns (
767+ '.git' ,
768+ '.pixi' ,
769+ 'deploy_tmp' ,
770+ '__pycache__' ,
771+ '*.pyc' ,
772+ ),
773+ )
774+ return
775+
715776 commands = (
716777 f'cd "{ build_root !s} " && '
717778 + "GIT_SSH_COMMAND='ssh -oBatchMode=yes' git clone "
0 commit comments