mirror of
https://github.com/astral-sh/uv.git
synced 2025-10-01 06:21:13 +00:00
Fix bootstrap install script on windows (#1162)
Windows doesn't support symlinks, doesn't use a `bin` directory and all pythons are called `python.exe`. Note that this is still broken, `.\bin\python3.10.13` is missing its .exe extension and renaming it to `.\bin\python3.10.13.exe` makes it complain about not finding python310.dll.
This commit is contained in:
parent
bc2f8f5b1e
commit
0199ad64bb
1 changed files with 22 additions and 10 deletions
|
@ -1,4 +1,10 @@
|
||||||
#!/usr/bin/env python3
|
#!/usr/bin/env python3
|
||||||
|
# /// script
|
||||||
|
# requires-python = ">=3.11"
|
||||||
|
# dependencies = [
|
||||||
|
# "zstandard==0.22.0",
|
||||||
|
# ]
|
||||||
|
# ///
|
||||||
#
|
#
|
||||||
# Download required Python versions and install to `bin`
|
# Download required Python versions and install to `bin`
|
||||||
# Uses prebuilt Python distributions from indygreg/python-build-standalone
|
# Uses prebuilt Python distributions from indygreg/python-build-standalone
|
||||||
|
@ -13,6 +19,10 @@
|
||||||
#
|
#
|
||||||
# python scripts/bootstrap/install.py
|
# python scripts/bootstrap/install.py
|
||||||
#
|
#
|
||||||
|
# Or
|
||||||
|
#
|
||||||
|
# pipx run scripts/bootstrap/install.py
|
||||||
|
#
|
||||||
# The Python versions are installed from `.python_versions`.
|
# The Python versions are installed from `.python_versions`.
|
||||||
# Python versions are linked in-order such that the _last_ defined version will be the default.
|
# Python versions are linked in-order such that the _last_ defined version will be the default.
|
||||||
#
|
#
|
||||||
|
@ -96,8 +106,8 @@ for version in versions:
|
||||||
print(f"No matching download for {key}")
|
print(f"No matching download for {key}")
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
||||||
|
filename = url.split("/")[-1]
|
||||||
if not install_dir.exists():
|
if not install_dir.exists():
|
||||||
filename = url.split("/")[-1]
|
|
||||||
print(f"Downloading {urllib.parse.unquote(filename)}")
|
print(f"Downloading {urllib.parse.unquote(filename)}")
|
||||||
download_path = THIS_DIR / filename
|
download_path = THIS_DIR / filename
|
||||||
with urllib.request.urlopen(url) as response:
|
with urllib.request.urlopen(url) as response:
|
||||||
|
@ -129,28 +139,30 @@ for version in versions:
|
||||||
already_exists = True
|
already_exists = True
|
||||||
print("Already available, skipping download")
|
print("Already available, skipping download")
|
||||||
|
|
||||||
# Use relative paths for links so if the bin is moved they don't break
|
|
||||||
executable = "." / install_dir.relative_to(BIN_DIR) / "install" / "bin" / "python3"
|
|
||||||
if PLATFORM == "win32":
|
if PLATFORM == "win32":
|
||||||
executable = executable.with_suffix(".exe")
|
executable = install_dir / "install" / "python.exe"
|
||||||
|
else:
|
||||||
|
# Use relative paths for links so if the bin is moved they don't break
|
||||||
|
executable = "." / install_dir.relative_to(BIN_DIR) / "install" / "bin" / "python3"
|
||||||
|
|
||||||
major = versions_metadata[key]["major"]
|
major = versions_metadata[key]["major"]
|
||||||
minor = versions_metadata[key]["minor"]
|
minor = versions_metadata[key]["minor"]
|
||||||
|
|
||||||
# Link as all version tuples, later versions in the file will take precedence
|
# Link as all version tuples, later versions in the file will take precedence
|
||||||
BIN_DIR.mkdir(parents=True, exist_ok=True)
|
BIN_DIR.mkdir(parents=True, exist_ok=True)
|
||||||
targets = (
|
|
||||||
|
targets = [
|
||||||
(BIN_DIR / f"python{version}"),
|
(BIN_DIR / f"python{version}"),
|
||||||
(BIN_DIR / f"python{major}.{minor}"),
|
(BIN_DIR / f"python{major}.{minor}"),
|
||||||
(BIN_DIR / f"python{major}"),
|
(BIN_DIR / f"python{major}"),
|
||||||
(BIN_DIR / "python"),
|
(BIN_DIR / "python"),
|
||||||
)
|
]
|
||||||
for target in targets:
|
for target in targets:
|
||||||
if PLATFORM == "win32":
|
|
||||||
target = target.with_suffix(".exe")
|
|
||||||
|
|
||||||
target.unlink(missing_ok=True)
|
target.unlink(missing_ok=True)
|
||||||
target.symlink_to(executable)
|
if PLATFORM == "win32":
|
||||||
|
target.hardlink_to(executable)
|
||||||
|
else:
|
||||||
|
target.symlink_to(executable)
|
||||||
|
|
||||||
if already_exists:
|
if already_exists:
|
||||||
print(f"Updated executables for python{version}")
|
print(f"Updated executables for python{version}")
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue