mirror of
https://github.com/servo/servo.git
synced 2025-06-08 00:23:30 +00:00
Use ruff
to enforce python code formatting (#37117)
Requires servo/servo#37045 for deps and config. Testing: No need for tests to test tests. Fixes: servo/servo#37041 --------- Signed-off-by: zefr0x <zer0-x.7ty50@aleeas.com>
This commit is contained in:
parent
41ecfb53a1
commit
c96de69e80
67 changed files with 3021 additions and 3085 deletions
|
@ -22,61 +22,61 @@ SEARCH_PATHS = [
|
|||
|
||||
# Individual files providing mach commands.
|
||||
MACH_MODULES = [
|
||||
os.path.join('python', 'servo', 'bootstrap_commands.py'),
|
||||
os.path.join('python', 'servo', 'build_commands.py'),
|
||||
os.path.join('python', 'servo', 'testing_commands.py'),
|
||||
os.path.join('python', 'servo', 'post_build_commands.py'),
|
||||
os.path.join('python', 'servo', 'package_commands.py'),
|
||||
os.path.join('python', 'servo', 'devenv_commands.py'),
|
||||
os.path.join("python", "servo", "bootstrap_commands.py"),
|
||||
os.path.join("python", "servo", "build_commands.py"),
|
||||
os.path.join("python", "servo", "testing_commands.py"),
|
||||
os.path.join("python", "servo", "post_build_commands.py"),
|
||||
os.path.join("python", "servo", "package_commands.py"),
|
||||
os.path.join("python", "servo", "devenv_commands.py"),
|
||||
]
|
||||
|
||||
CATEGORIES = {
|
||||
'bootstrap': {
|
||||
'short': 'Bootstrap Commands',
|
||||
'long': 'Bootstrap the build system',
|
||||
'priority': 90,
|
||||
"bootstrap": {
|
||||
"short": "Bootstrap Commands",
|
||||
"long": "Bootstrap the build system",
|
||||
"priority": 90,
|
||||
},
|
||||
'build': {
|
||||
'short': 'Build Commands',
|
||||
'long': 'Interact with the build system',
|
||||
'priority': 80,
|
||||
"build": {
|
||||
"short": "Build Commands",
|
||||
"long": "Interact with the build system",
|
||||
"priority": 80,
|
||||
},
|
||||
'post-build': {
|
||||
'short': 'Post-build Commands',
|
||||
'long': 'Common actions performed after completing a build.',
|
||||
'priority': 70,
|
||||
"post-build": {
|
||||
"short": "Post-build Commands",
|
||||
"long": "Common actions performed after completing a build.",
|
||||
"priority": 70,
|
||||
},
|
||||
'testing': {
|
||||
'short': 'Testing',
|
||||
'long': 'Run tests.',
|
||||
'priority': 60,
|
||||
"testing": {
|
||||
"short": "Testing",
|
||||
"long": "Run tests.",
|
||||
"priority": 60,
|
||||
},
|
||||
'devenv': {
|
||||
'short': 'Development Environment',
|
||||
'long': 'Set up and configure your development environment.',
|
||||
'priority': 50,
|
||||
"devenv": {
|
||||
"short": "Development Environment",
|
||||
"long": "Set up and configure your development environment.",
|
||||
"priority": 50,
|
||||
},
|
||||
'build-dev': {
|
||||
'short': 'Low-level Build System Interaction',
|
||||
'long': 'Interact with specific parts of the build system.',
|
||||
'priority': 20,
|
||||
"build-dev": {
|
||||
"short": "Low-level Build System Interaction",
|
||||
"long": "Interact with specific parts of the build system.",
|
||||
"priority": 20,
|
||||
},
|
||||
'package': {
|
||||
'short': 'Package',
|
||||
'long': 'Create objects to distribute',
|
||||
'priority': 15,
|
||||
"package": {
|
||||
"short": "Package",
|
||||
"long": "Create objects to distribute",
|
||||
"priority": 15,
|
||||
},
|
||||
'misc': {
|
||||
'short': 'Potpourri',
|
||||
'long': 'Potent potables and assorted snacks.',
|
||||
'priority': 10,
|
||||
"misc": {
|
||||
"short": "Potpourri",
|
||||
"long": "Potent potables and assorted snacks.",
|
||||
"priority": 10,
|
||||
},
|
||||
"disabled": {
|
||||
"short": "Disabled",
|
||||
"long": "The disabled commands are hidden by default. Use -v to display them. These commands are unavailable "
|
||||
'for your current context, run "mach <command>" to see why.',
|
||||
"priority": 0,
|
||||
},
|
||||
'disabled': {
|
||||
'short': 'Disabled',
|
||||
'long': 'The disabled commands are hidden by default. Use -v to display them. These commands are unavailable '
|
||||
'for your current context, run "mach <command>" to see why.',
|
||||
'priority': 0,
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
@ -92,17 +92,25 @@ def _process_exec(args, cwd):
|
|||
def install_virtual_env_requirements(project_path: str, marker_path: str):
|
||||
requirements_paths = [
|
||||
os.path.join(project_path, "python", "requirements.txt"),
|
||||
os.path.join(project_path, WPT_TOOLS_PATH, "requirements_tests.txt",),
|
||||
os.path.join(project_path, WPT_RUNNER_PATH, "requirements.txt",),
|
||||
os.path.join(
|
||||
project_path,
|
||||
WPT_TOOLS_PATH,
|
||||
"requirements_tests.txt",
|
||||
),
|
||||
os.path.join(
|
||||
project_path,
|
||||
WPT_RUNNER_PATH,
|
||||
"requirements.txt",
|
||||
),
|
||||
]
|
||||
|
||||
requirements_hasher = hashlib.sha256()
|
||||
for path in requirements_paths:
|
||||
with open(path, 'rb') as file:
|
||||
with open(path, "rb") as file:
|
||||
requirements_hasher.update(file.read())
|
||||
|
||||
try:
|
||||
with open(marker_path, 'r') as marker_file:
|
||||
with open(marker_path, "r") as marker_file:
|
||||
marker_hash = marker_file.read()
|
||||
except FileNotFoundError:
|
||||
marker_hash = None
|
||||
|
@ -132,27 +140,28 @@ def _activate_virtualenv(topdir):
|
|||
_process_exec(["uv", "venv"], cwd=topdir)
|
||||
|
||||
script_dir = "Scripts" if _is_windows() else "bin"
|
||||
runpy.run_path(os.path.join(virtualenv_path, script_dir, 'activate_this.py'))
|
||||
runpy.run_path(os.path.join(virtualenv_path, script_dir, "activate_this.py"))
|
||||
|
||||
install_virtual_env_requirements(topdir, marker_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')
|
||||
|
||||
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
|
||||
# system is case sensitive or not.
|
||||
if _is_windows() and not os.path.exists('Python'):
|
||||
print('Cannot run mach in a path on a case-sensitive file system on Windows.')
|
||||
print('For more details, see https://github.com/pypa/virtualenv/issues/935')
|
||||
if _is_windows() and not os.path.exists("Python"):
|
||||
print("Cannot run mach in a path on a case-sensitive file system on Windows.")
|
||||
print("For more details, see https://github.com/pypa/virtualenv/issues/935")
|
||||
sys.exit(1)
|
||||
|
||||
|
||||
def _is_windows():
|
||||
return sys.platform == 'win32'
|
||||
return sys.platform == "win32"
|
||||
|
||||
|
||||
def bootstrap_command_only(topdir):
|
||||
|
@ -168,9 +177,9 @@ def bootstrap_command_only(topdir):
|
|||
import servo.util
|
||||
|
||||
try:
|
||||
force = '-f' in sys.argv or '--force' in sys.argv
|
||||
skip_platform = '--skip-platform' in sys.argv
|
||||
skip_lints = '--skip-lints' in sys.argv
|
||||
force = "-f" in sys.argv or "--force" in sys.argv
|
||||
skip_platform = "--skip-platform" in sys.argv
|
||||
skip_lints = "--skip-lints" in sys.argv
|
||||
servo.platform.get().bootstrap(force, skip_platform, skip_lints)
|
||||
except NotImplementedError as exception:
|
||||
print(exception)
|
||||
|
@ -186,9 +195,9 @@ def bootstrap(topdir):
|
|||
|
||||
# We don't support paths with spaces for now
|
||||
# https://github.com/servo/servo/issues/9616
|
||||
if ' ' in topdir and (not _is_windows()):
|
||||
print('Cannot run mach in a path with spaces.')
|
||||
print('Current path:', topdir)
|
||||
if " " in topdir and (not _is_windows()):
|
||||
print("Cannot run mach in a path with spaces.")
|
||||
print("Current path:", topdir)
|
||||
sys.exit(1)
|
||||
|
||||
_activate_virtualenv(topdir)
|
||||
|
@ -196,7 +205,7 @@ def bootstrap(topdir):
|
|||
def populate_context(context, key=None):
|
||||
if key is None:
|
||||
return
|
||||
if key == 'topdir':
|
||||
if key == "topdir":
|
||||
return topdir
|
||||
raise AttributeError(key)
|
||||
|
||||
|
@ -204,11 +213,12 @@ def bootstrap(topdir):
|
|||
sys.path[0:0] = [WPT_PATH, WPT_RUNNER_PATH, WPT_SERVE_PATH]
|
||||
|
||||
import mach.main
|
||||
|
||||
mach = mach.main.Mach(os.getcwd())
|
||||
mach.populate_context_handler = populate_context
|
||||
|
||||
for category, meta in CATEGORIES.items():
|
||||
mach.define_category(category, meta['short'], meta['long'], meta['priority'])
|
||||
mach.define_category(category, meta["short"], meta["long"], meta["priority"])
|
||||
|
||||
for path in MACH_MODULES:
|
||||
# explicitly provide a module name
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue