Skip to content

Commit 721dcb8

Browse files
committed
chore(tooling): adopt pyproject, ruff, and update CI
- Consolidate packaging and tooling into pyproject.toml and standardise linting and formatting with ruff. - Move metadata and deps into pyproject.toml; compile requirements.txt (runtime) and requirements-dev.txt (runtime + dev: pytest, pytest-mock, moto, ruff) from it via pip-tools; retire requirements.in. - Move pytest config into [tool.pytest.ini_options] and remove pytest.ini. - Add [tool.ruff] config; apply ruff check --fix and ruff format across code. - CI: unit_tests installs requirements-dev.txt; add a lint workflow running ruff check and ruff format --check on PRs to develop. Closes #183, #173
1 parent f900ae2 commit 721dcb8

37 files changed

Lines changed: 451 additions & 155 deletions

.github/workflows/lint.yml

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
name: Lint
2+
3+
on:
4+
pull_request:
5+
branches: [ develop ]
6+
7+
jobs:
8+
ruff:
9+
runs-on: ubuntu-latest
10+
11+
steps:
12+
- name: Checkout code
13+
uses: actions/checkout@v4
14+
15+
- name: Set up Python
16+
uses: actions/setup-python@v5
17+
with:
18+
python-version: '3.11'
19+
20+
- name: Install ruff
21+
run: |
22+
python -m pip install --upgrade pip
23+
pip install ruff
24+
25+
- name: Lint
26+
run: ruff check .
27+
28+
- name: Format check
29+
run: ruff format --check .

.github/workflows/unit_tests.yml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,7 @@ jobs:
2020
- name: Install dependencies
2121
run: |
2222
python -m pip install --upgrade pip
23-
pip install -r requirements.txt
24-
pip install pytest pytest-mock "moto[s3]"
23+
pip install -r requirements-dev.txt
2524
2625
- name: Run tests (excluding integration tests)
2726
run: |

app/__init__.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,23 +3,23 @@
33
import logging
44

55
from apiflask import APIFlask
6+
from flask import jsonify, request
67

78
from app.crates.ids import InvalidCrateId
8-
from app.crates.resolver import CrateNotFound, AmbiguousCrate
9+
from app.crates.resolver import AmbiguousCrate, CrateNotFound
910
from app.health import health_bp
10-
from app.ro_crates.routes import v1_post_bp, v1_minio_post_bp, v1_minio_get_bp
11+
from app.ro_crates.routes import v1_minio_get_bp, v1_minio_post_bp, v1_post_bp
1112
from app.services.logging_service import (
13+
get_request_id,
1214
new_request_id,
1315
set_request_id,
14-
get_request_id,
1516
)
1617
from app.storage.errors import StorageError
1718
from app.utils.config import (
18-
Settings,
1919
InvalidAPIUsage,
20+
Settings,
2021
make_celery,
2122
)
22-
from flask import jsonify, request
2323

2424
logger = logging.getLogger(__name__)
2525

app/celery_worker.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,4 @@
66

77
from celery import Celery
88

9-
109
celery = Celery()

app/crates/resolver.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
from dataclasses import dataclass
1111

1212
from app.crates.ids import validate_crate_id
13-
from app.crates.layout import crate_zip_key, crate_dir_prefix, crate_metadata_key
13+
from app.crates.layout import crate_dir_prefix, crate_metadata_key, crate_zip_key
1414
from app.storage.base import StorageBackend
1515
from app.storage.errors import ObjectNotFound
1616

app/ro_crates/routes/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
"""Defines main Blueprint and registers sub-Blueprints for organising related routes."""
22

3-
from app.ro_crates.routes.post_routes import post_routes_bp, minio_post_routes_bp
43
from app.ro_crates.routes.get_routes import get_routes_bp
4+
from app.ro_crates.routes.post_routes import minio_post_routes_bp, post_routes_bp
55

66
# Always registered:
77
v1_post_bp = post_routes_bp

app/ro_crates/routes/post_routes.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,4 @@ def validate_ro_crate_metadata(json_data) -> tuple[Response, int]:
7979

8080
profiles_path = current_app.config["PROFILES_PATH"]
8181

82-
return run_metadata_validation(
83-
crate_json, profile_name, profiles_path=profiles_path
84-
)
82+
return run_metadata_validation(crate_json, profile_name, profiles_path=profiles_path)

app/services/logging_service.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
import json
44
import logging
55
import uuid
6-
76
from contextvars import ContextVar
87
from typing import Iterable, Optional
98

app/services/validation_service.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
import json
44
import logging
55

6-
from flask import jsonify, Response, current_app
6+
from flask import Response, current_app, jsonify
77

88
from app.crates.ids import validate_crate_id
99
from app.crates.layout import result_key
@@ -76,9 +76,7 @@ def run_metadata_validation(
7676
if not metadata:
7777
return jsonify({"error": "Required parameter crate_json is empty"}), 422
7878

79-
outcome = validate_metadata(
80-
metadata, profile_name=profile_name, profiles_path=profiles_path
81-
)
79+
outcome = validate_metadata(metadata, profile_name=profile_name, profiles_path=profiles_path)
8280
status_code = 422 if outcome.status is ValidationStatus.ERROR else 200
8381
return jsonify(outcome.to_dict()), status_code
8482

app/storage/__init__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
are interchangeable.
66
"""
77

8-
from app.storage.base import StorageBackend, ObjectStat
9-
from app.storage.errors import StorageError, ObjectNotFound
8+
from app.storage.base import ObjectStat, StorageBackend
9+
from app.storage.errors import ObjectNotFound, StorageError
1010

1111
__all__ = ["StorageBackend", "ObjectStat", "StorageError", "ObjectNotFound"]

0 commit comments

Comments
 (0)