Allow explicitly requesting an system interpreter version in check_system_python (#7306)

Needed for #7300
This commit is contained in:
Zanie Blue 2024-09-11 14:41:42 -05:00 committed by GitHub
parent bb0fb8e9bf
commit ebd73d83f8
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 12 additions and 3 deletions

View file

@ -47,12 +47,18 @@ if __name__ == "__main__":
action="store_true",
help="Set if the Python installation has an EXTERNALLY-MANAGED marker.",
)
parser.add_argument(
"--python",
required=False,
help="Set if the system Python version must be explicitly specified, e.g., for prereleases.",
)
args = parser.parse_args()
uv: str = os.path.abspath(args.uv) if args.uv else "uv"
allow_externally_managed = (
["--break-system-packages"] if args.externally_managed else []
)
python = ["--python", args.python] if args.python else []
# Create a temporary directory.
with tempfile.TemporaryDirectory() as temp_dir:
@ -69,7 +75,8 @@ if __name__ == "__main__":
logging.info("Installing the package `pylint`.")
subprocess.run(
[uv, "pip", "install", "pylint", "--system", "--verbose"]
+ allow_externally_managed,
+ allow_externally_managed
+ python,
cwd=temp_dir,
check=True,
)
@ -94,7 +101,9 @@ if __name__ == "__main__":
# Uninstall the package (`pylint`).
logging.info("Uninstalling the package `pylint`.")
subprocess.run(
[uv, "pip", "uninstall", "pylint", "--system"] + allow_externally_managed,
[uv, "pip", "uninstall", "pylint", "--system"]
+ allow_externally_managed
+ python,
cwd=temp_dir,
check=True,
)