mirror of
https://github.com/astral-sh/uv.git
synced 2025-07-07 13:25:00 +00:00
Add a --system
flag for opt-in non-virtualenv installs (#2046)
## Summary This is essentially a wrapper around something like `--python $(which python3)`, but gives users a portable and streamlined way to solve the common pain point of using `uv` in GitHub Actions or a Docker container. See: https://github.com/astral-sh/uv/issues/1526.
This commit is contained in:
parent
b873e3e991
commit
9328b3c2ab
8 changed files with 285 additions and 8 deletions
74
scripts/check_system_python.py
Executable file
74
scripts/check_system_python.py
Executable file
|
@ -0,0 +1,74 @@
|
|||
#!/usr/bin/env python3
|
||||
|
||||
"""Install `pylint` into the system Python."""
|
||||
|
||||
import argparse
|
||||
import logging
|
||||
import os
|
||||
import subprocess
|
||||
import sys
|
||||
import tempfile
|
||||
|
||||
if __name__ == "__main__":
|
||||
logging.basicConfig(level=logging.INFO, format="%(levelname)s: %(message)s")
|
||||
|
||||
print("sys.executable:: %s" % sys.executable)
|
||||
|
||||
parser = argparse.ArgumentParser(description="Check a Python interpreter.")
|
||||
parser.add_argument("--uv", help="Path to a uv binary.")
|
||||
args = parser.parse_args()
|
||||
|
||||
uv: str = os.path.abspath(args.uv) if args.uv else "uv"
|
||||
|
||||
# Create a temporary directory.
|
||||
with tempfile.TemporaryDirectory() as temp_dir:
|
||||
# Ensure that the package (`pylint`) isn't installed.
|
||||
logging.info("Checking that `pylint` isn't installed.")
|
||||
code = subprocess.run(
|
||||
[sys.executable, "-m", "pip", "show", "pylint"],
|
||||
cwd=temp_dir,
|
||||
)
|
||||
if code.returncode == 0:
|
||||
raise Exception("The package `pylint` is installed.")
|
||||
|
||||
# Install the package (`pylint`).
|
||||
logging.info("Installing the package `pylint`.")
|
||||
subprocess.run(
|
||||
[uv, "pip", "install", "pylint", "--system", "--verbose"],
|
||||
cwd=temp_dir,
|
||||
check=True,
|
||||
)
|
||||
|
||||
# Ensure that the package (`pylint`) isn't installed.
|
||||
logging.info("Checking that `pylint` is installed.")
|
||||
code = subprocess.run(
|
||||
[sys.executable, "-m", "pip", "show", "pylint"],
|
||||
cwd=temp_dir,
|
||||
)
|
||||
if code.returncode != 0:
|
||||
raise Exception("The package `pylint` isn't installed.")
|
||||
|
||||
# TODO(charlie): Windows is failing to find the `pylint` binary, despite
|
||||
# confirmation that it's being written to the intended location.
|
||||
if os.name != "nt":
|
||||
logging.info("Checking that `pylint` is in the path.")
|
||||
code = subprocess.run(["which", "pylint"], cwd=temp_dir)
|
||||
if code.returncode != 0:
|
||||
raise Exception("The package `pylint` isn't in the path.")
|
||||
|
||||
# Uninstall the package (`pylint`).
|
||||
logging.info("Uninstalling the package `pylint`.")
|
||||
subprocess.run(
|
||||
[uv, "pip", "uninstall", "pylint", "--system", "--verbose"],
|
||||
cwd=temp_dir,
|
||||
check=True,
|
||||
)
|
||||
|
||||
# Ensure that the package (`pylint`) isn't installed.
|
||||
logging.info("Checking that `pylint` isn't installed.")
|
||||
code = subprocess.run(
|
||||
[sys.executable, "-m", "pip", "show", "pylint"],
|
||||
cwd=temp_dir,
|
||||
)
|
||||
if code.returncode == 0:
|
||||
raise Exception("The package `pylint` is installed.")
|
Loading…
Add table
Add a link
Reference in a new issue