setup-python/__tests__/verify_windows_install_path_user.py

57 lines
1.8 KiB
Python
Raw Normal View History

2025-06-06 18:51:53 +05:30
import os
import sys
2025-06-12 11:54:26 +05:30
import re
2025-06-06 18:51:53 +05:30
2025-06-12 11:54:26 +05:30
def build_expected_path(python_version, architecture, freethreaded):
2025-06-13 17:15:00 +05:30
print("Inputs received:")
print(f" Python Version : {python_version}")
print(f" Architecture : {architecture}")
print(f" Freethreaded : {freethreaded}")
# Extract major and minor from version like "3.13.1" or "3.14.0-beta.2"
2025-06-12 11:54:26 +05:30
match = re.match(r"^(\d+)\.(\d+)", python_version)
if not match:
print(f"Invalid python version format: {python_version}")
sys.exit(1)
2025-06-06 18:51:53 +05:30
2025-06-12 11:54:26 +05:30
major, minor = match.groups()
version_suffix = f"{major}{minor}"
2025-06-06 18:51:53 +05:30
if freethreaded == "true":
version_suffix += "t"
if architecture == "x86":
version_suffix += "-32"
elif architecture == "arm64":
version_suffix += "-arm64"
2025-06-12 11:54:26 +05:30
else:
if architecture == "x86":
version_suffix += "-32"
elif architecture == "arm64":
version_suffix += "-arm64"
2025-06-06 18:51:53 +05:30
base_path = os.getenv("APPDATA", "")
2025-06-13 17:15:00 +05:30
full_path = os.path.join(base_path, "Python", f"Python{version_suffix}", "Scripts")
print(f"Constructed expected path: {full_path}")
return full_path
2025-06-06 18:51:53 +05:30
def main():
2025-06-12 11:54:26 +05:30
if len(sys.argv) != 4:
print("Usage: python verify_windows_install_path.py <python_version> <architecture> <freethreaded>")
2025-06-06 18:51:53 +05:30
sys.exit(1)
2025-06-12 11:54:26 +05:30
python_version = sys.argv[1]
architecture = sys.argv[2]
freethreaded = sys.argv[3]
2025-06-06 18:51:53 +05:30
2025-06-12 11:54:26 +05:30
expected_path = build_expected_path(python_version, architecture, freethreaded)
2025-06-06 18:51:53 +05:30
2025-06-13 17:15:00 +05:30
print("Validating against PATH environment variable...")
2025-06-06 18:51:53 +05:30
path_env = os.getenv("PATH", "")
2025-06-13 17:15:00 +05:30
if expected_path.lower() in path_env.lower():
print("Correct path present in PATH")
else:
2025-06-06 18:51:53 +05:30
print("Expected path not found in PATH")
sys.exit(1)
if __name__ == "__main__":
2025-06-13 19:21:00 +05:30
main()