Repository navigation
Expand file tree
/
Copy pathinstall_pixi.py
More file actions
executable file
·153 lines (136 loc) · 5.02 KB
/
Copy pathinstall_pixi.py
File metadata and controls
executable file
·153 lines (136 loc) · 5.02 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
#!/usr/bin/env python3
import os
from pathlib import Path
from wheel_builder_utils import detect_platform, run_commandLine_subprocess
def download_and_install_pixi(
binary_ext: str, os_name: str, pixi_home: Path, platform_env: str = "default"
) -> Path:
"""Download pixi (if not already present) and install a platform environment.
Parameters
----------
binary_ext : str
Executable extension (``'.exe'`` on Windows, ``''`` elsewhere).
os_name : str
Operating system name (``'windows'``, ``'linux'``, ``'darwin'``).
pixi_home : Path
Directory where pixi is (or will be) installed.
platform_env : str, optional
Pixi environment name to install (default ``'default'``).
Returns
-------
pixi_exec_path : Path
Path to the pixi executable.
Raises
------
RuntimeError
If the download, installation, or environment setup fails.
"""
pixi_bin_name: str = "pixi" + binary_ext
# Attempt to find an existing pixi binary on the system first (cross-platform)
pixi_exec_path: Path = Path(pixi_home) / "bin" / pixi_bin_name
pixi_install_env = os.environ.copy()
pixi_install_env["PIXI_NO_PATH_UPDATE"] = "1"
pixi_install_env["PIXI_HOME"] = str(pixi_home)
# If not found, we will install into the local build .pixi
if pixi_exec_path.is_file():
print(f"Previous install of pixi will be used {pixi_exec_path}.")
else:
if os_name == "windows":
# Use PowerShell to install pixi on Windows
result = run_commandLine_subprocess(
[
"powershell",
"-NoProfile",
"-ExecutionPolicy",
"Bypass",
"-Command",
"irm -UseBasicParsing https://pixi.sh/install.ps1 | iex",
],
env=pixi_install_env,
)
if result.returncode != 0:
raise RuntimeError(f"Failed to install pixi: {result.stderr}")
else:
pixi_install_script: Path = pixi_home / "pixi_install.sh"
result = run_commandLine_subprocess(
[
"curl",
"-fsSL",
"https://pixi.sh/install.sh",
"-o",
str(pixi_install_script),
]
)
if result.returncode != 0:
raise RuntimeError(
f"Failed to download {pixi_install_script}: {result.stderr}"
)
result = run_commandLine_subprocess(
[
"/bin/sh",
str(pixi_install_script),
],
env=pixi_install_env,
)
if result.returncode != 0:
raise RuntimeError(f"Failed to install pixi: {result.stderr}")
del pixi_install_script
if not pixi_exec_path.exists():
raise RuntimeError(
f"Failed to install {pixi_exec_path} pixi into {pixi_exec_path}"
)
# Now install the desired platform
if (pixi_home.parent / "pixi.toml").exists():
result = run_commandLine_subprocess(
[pixi_exec_path, "install", "--environment", platform_env],
cwd=pixi_home.parent,
env=pixi_install_env,
)
if result.returncode != 0:
raise RuntimeError(
f"Failed to install environment {platform_env}: {result.stderr}"
)
else:
print(
f"pixi.toml not found {pixi_home.parent / 'pixi.toml'}, skipping environment install."
)
return pixi_exec_path
def install_pixi_tools(platform_env: str = "default"):
"""High-level helper: detect the platform, install pixi, and set up *platform_env*.
Parameters
----------
platform_env : str, optional
Pixi environment name to install (default ``'default'``).
"""
_ipp_dir_path: Path = Path(__file__).resolve().parent.parent
os_name, arch = detect_platform()
binary_ext: str = ".exe" if os_name == "windows" else ""
pixi_home: Path = Path(
os.environ.get("PIXI_HOME")
if "PIXI_HOME" in os.environ
else _ipp_dir_path / ".pixi"
)
pixi_home.mkdir(parents=True, exist_ok=True)
pixi_exec_path = Path(
download_and_install_pixi(binary_ext, os_name, pixi_home, platform_env)
)
print(f"Installed pixi locally to {pixi_home} with binary of {pixi_exec_path}")
if __name__ == "__main__":
import argparse
parser = argparse.ArgumentParser(
description="Driver script to build ITK Python wheels."
)
parser.add_argument(
"--platform-env",
default="default",
help=(
"""A platform environment name or path:
linux-py310, linux-py311,
manylinux228-py310, manylinux228-py311,
windows-py310, windows-py311,
macosx-py310, macosx-py311
"""
),
)
args = parser.parse_args()
install_pixi_tools(args.platform_env)