mirror of
https://github.com/servo/servo.git
synced 2025-06-08 00:23:30 +00:00
This reverts commit 4103421ba5
.
Signed-off-by: Mukilan Thiyagarajan <mukilan@igalia.com>
This commit is contained in:
parent
3f69ef2303
commit
2f64dde623
22 changed files with 80 additions and 100 deletions
|
@ -4,6 +4,7 @@
|
|||
|
||||
import hashlib
|
||||
import os
|
||||
import platform
|
||||
import site
|
||||
import subprocess
|
||||
import sys
|
||||
|
@ -92,13 +93,11 @@ def _get_virtualenv_script_dir():
|
|||
def _get_virtualenv_lib_dir():
|
||||
if os.name == "nt" and os.sep != "/":
|
||||
return os.path.join("Lib", "site-packages")
|
||||
with open(".python-version", "r") as python_version_file:
|
||||
python_version = python_version_file.read().strip()
|
||||
return os.path.join(
|
||||
"lib",
|
||||
f"python{python_version}",
|
||||
"site-packages"
|
||||
)
|
||||
return os.path.join(
|
||||
"lib",
|
||||
f"python{sys.version_info[0]}.{sys.version_info[1]}",
|
||||
"site-packages"
|
||||
)
|
||||
|
||||
|
||||
def _process_exec(args):
|
||||
|
@ -132,8 +131,11 @@ def install_virtual_env_requirements(project_path: str, python: str, virtualenv_
|
|||
requirements_hash = requirements_hasher.hexdigest()
|
||||
|
||||
if marker_hash != requirements_hash:
|
||||
print(" * Upgrading pip...")
|
||||
_process_exec([python, "-m", "pip", "install", "--upgrade", "pip"])
|
||||
|
||||
print(" * Installing Python requirements...")
|
||||
_process_exec(["uv", "pip", "install",
|
||||
_process_exec([python, "-m", "pip", "install", "-I",
|
||||
"-r", requirements_paths[0],
|
||||
"-r", requirements_paths[1],
|
||||
"-r", requirements_paths[2]])
|
||||
|
@ -142,14 +144,14 @@ def install_virtual_env_requirements(project_path: str, python: str, virtualenv_
|
|||
|
||||
|
||||
def _activate_virtualenv(topdir):
|
||||
virtualenv_path = os.path.join(topdir, ".venv")
|
||||
virtualenv_path = os.path.join(topdir, "python", "_venv%d.%d" % (sys.version_info[0], sys.version_info[1]))
|
||||
python = sys.executable
|
||||
|
||||
if os.environ.get("VIRTUAL_ENV") != virtualenv_path:
|
||||
venv_script_path = os.path.join(virtualenv_path, _get_virtualenv_script_dir())
|
||||
if not os.path.exists(virtualenv_path):
|
||||
print(" * Setting up virtual environment...")
|
||||
_process_exec(["uv", "venv"])
|
||||
_process_exec([python, "-m", "venv", "--system-site-packages", virtualenv_path])
|
||||
|
||||
# This general approach is taken from virtualenv's `activate_this.py`.
|
||||
os.environ["PATH"] = os.pathsep.join([venv_script_path, *os.environ.get("PATH", "").split(os.pathsep)])
|
||||
|
@ -169,11 +171,6 @@ def _activate_virtualenv(topdir):
|
|||
|
||||
install_virtual_env_requirements(topdir, python, virtualenv_path)
|
||||
|
||||
# Turn off warnings about deprecated syntax in our indirect dependencies.
|
||||
# TODO: Find a better approach for doing this.
|
||||
import warnings
|
||||
warnings.filterwarnings('ignore', category=SyntaxWarning, module=r'.*.venv')
|
||||
|
||||
|
||||
def _ensure_case_insensitive_if_windows():
|
||||
# The folder is called 'python'. By deliberately checking for it with the wrong case, we determine if the file
|
||||
|
@ -224,6 +221,13 @@ def bootstrap(topdir):
|
|||
print('Current path:', topdir)
|
||||
sys.exit(1)
|
||||
|
||||
# Ensure we are running Python 3.10+. We put this check here so we generate a
|
||||
# user-friendly error message rather than a cryptic stack trace on module import.
|
||||
if sys.version_info < (3, 10):
|
||||
print('Python3 (>=3.10) is required to run mach.')
|
||||
print('You are running Python', platform.python_version())
|
||||
sys.exit(1)
|
||||
|
||||
_activate_virtualenv(topdir)
|
||||
|
||||
def populate_context(context, key=None):
|
||||
|
|
|
@ -175,7 +175,7 @@ class MachCommands(CommandBase):
|
|||
return status
|
||||
|
||||
@Command('clean',
|
||||
description='Clean the target/ and Python virtual environment directories',
|
||||
description='Clean the target/ and python/_venv[version]/ directories',
|
||||
category='build')
|
||||
@CommandArgument('--manifest-path',
|
||||
default=None,
|
||||
|
@ -188,7 +188,8 @@ class MachCommands(CommandBase):
|
|||
def clean(self, manifest_path=None, params=[], verbose=False):
|
||||
self.ensure_bootstrapped()
|
||||
|
||||
virtualenv_path = path.join(self.get_top_dir(), '.venv')
|
||||
virtualenv_fname = '_venv%d.%d' % (sys.version_info[0], sys.version_info[1])
|
||||
virtualenv_path = path.join(self.get_top_dir(), 'python', virtualenv_fname)
|
||||
if path.exists(virtualenv_path):
|
||||
print('Removing virtualenv directory: %s' % virtualenv_path)
|
||||
shutil.rmtree(virtualenv_path)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue