From aabef62db535a8864809ea13ec6fa82141b064fc Mon Sep 17 00:00:00 2001 From: Andrew Davison Date: Mon, 17 Nov 2025 17:49:24 +0100 Subject: [PATCH] Replace the "black" formatter with "ruff" (https://docs.astral.sh/ruff/), which seems to be much faster. --- .github/workflows/test.yml | 5 ++++- build.py | 13 ++++++++++++- pipeline/src/pyproject_template.toml.txt | 4 ++-- requirements.txt | 2 +- 4 files changed, 19 insertions(+), 5 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 7388560a..4ce3ac84 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -21,9 +21,12 @@ jobs: with: python-version: ${{ matrix.python-version }} - - name: Run build + - name: Install requirements run: | pip install -r requirements.txt + + - name: Run build + run: | python build.py - name: Test built package diff --git a/build.py b/build.py index 08352fc2..6c831bba 100644 --- a/build.py +++ b/build.py @@ -5,6 +5,7 @@ import shutil import subprocess import sys +from time import perf_counter from urllib.request import urlopen, HTTPError from jinja2 import Environment, select_autoescape, FileSystemLoader @@ -23,6 +24,8 @@ print(f"Triggering the generation of Python package for openMINDS, from the {args.branch} branch") print("*******************************************************************************") +start_time = perf_counter() + # Step 0 - read code for additional methods additional_methods = {} with open("pipeline/src/additional_methods/by_name.py.txt") as fp: @@ -35,6 +38,7 @@ instance_loader = InstanceLoader() if os.path.exists("target"): shutil.rmtree("target") +print(f"Cloned {args.branch} branch of central repository ({perf_counter() - start_time} s)") # Step 2 - load instances instances = {} @@ -45,6 +49,7 @@ with open(instance_path) as fp: instance_data = json.load(fp) instances[version][instance_data["@type"]].append(instance_data) +print(f"Loaded instances ({perf_counter() - start_time} s)") python_modules = defaultdict(list) @@ -86,6 +91,9 @@ parent_path = ".".join(parts[:-1]) python_modules[parent_path].append((parts[-1], class_name)) +print(f"Processed schemas ({perf_counter() - start_time} s)") + + # Step 5 - create additional files, e.g. __init__.py openminds_modules = defaultdict(set) for path in sorted(python_modules): @@ -151,5 +159,8 @@ with open("target/codemeta.json", "w") as fp: json.dump(codemeta, fp, indent=2) +print(f"Generated additional files ({perf_counter() - start_time} s)") + # Step 6 - run formatter -subprocess.call([sys.executable, "-m", "black", "--quiet", "target"]) +subprocess.call(["ruff", "format", "--quiet", "target"]) +print(f"Formatted all files ({perf_counter() - start_time} s)") diff --git a/pipeline/src/pyproject_template.toml.txt b/pipeline/src/pyproject_template.toml.txt index 5a705b37..3fb7eabe 100644 --- a/pipeline/src/pyproject_template.toml.txt +++ b/pipeline/src/pyproject_template.toml.txt @@ -34,7 +34,7 @@ dev = [ "setuptools", "wheel", "sphinx", - "black", + "ruff", "twine" ] @@ -51,5 +51,5 @@ include = ["openminds*"] ] build-backend = "setuptools.build_meta" -[tool.black] +[tool.ruff] line-length = 119 diff --git a/requirements.txt b/requirements.txt index 6613c480..7ee97c6e 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,3 +1,3 @@ gitpython jinja2 -black +ruff