From ff285d5e7ed2266763137009d03518467a7bb4e1 Mon Sep 17 00:00:00 2001 From: Dmitry Dygalo Date: Sun, 15 Sep 2024 14:29:44 +0200 Subject: [PATCH] chore: Add Justfile Signed-off-by: Dmitry Dygalo --- CONTRIBUTING.md | 2 ++ Justfile | 23 +++++++++++++++++++ crates/jsonschema-py/benches/bench.py | 6 ++++- .../python/jsonschema_rs/__init__.pyi | 2 +- crates/jsonschema-py/tests-py/test_suite.py | 7 +++--- 5 files changed, 35 insertions(+), 5 deletions(-) create mode 100644 Justfile diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index a17c96b2..f838602c 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -10,6 +10,8 @@ To open an issue, [follow this link](https://github.com/Stranger6667/jsonschema- When making a feature request, please make it clear what problem you intend to solve with the feature and provide some ideas on how to implement it. +**NOTE**: Many commands are available via a [Justfile](https://github.com/casey/just) located in the root of the repository. + ## Running the Tests The tests in jsonschema depend on the [JSON Schema Test Suite](https://github.com/json-schema-org/JSON-Schema-Test-Suite). Before running the tests, you need to download the suite. diff --git a/Justfile b/Justfile new file mode 100644 index 00000000..074d04b8 --- /dev/null +++ b/Justfile @@ -0,0 +1,23 @@ +default: + @just --list + +fuzz TARGET: + cargo +nightly fuzz run --release {{TARGET}} fuzz/corpus/{{TARGET}} fuzz/seeds/{{TARGET}} -- -dict=fuzz/dict + +lint-rs: + cargo +nightly fmt --all + cargo clippy --all-features --all-targets + +lint-py: + uvx ruff check crates/jsonschema-py/python crates/jsonschema-py/tests-py crates/jsonschema-py/benches + uvx ruff check --select I --fix crates/jsonschema-py/python crates/jsonschema-py/tests-py crates/jsonschema-py/benches + uvx mypy crates/jsonschema-py/python + +lint: lint-rs lint-py + +test-py *FLAGS: + uvx --with="crates/jsonschema-py[tests]" pytest crates/jsonschema-py/tests-py -rs {{FLAGS}} + +bench-py *FLAGS: + uvx --with="crates/jsonschema-py[bench]" pytest crates/jsonschema-py/benches/bench.py --benchmark-columns=min {{FLAGS}} + diff --git a/crates/jsonschema-py/benches/bench.py b/crates/jsonschema-py/benches/bench.py index 7968c63d..f06eb0b2 100644 --- a/crates/jsonschema-py/benches/bench.py +++ b/crates/jsonschema-py/benches/bench.py @@ -1,6 +1,7 @@ import json import sys from contextlib import suppress +from pathlib import Path import fastjsonschema import jsonschema @@ -12,6 +13,9 @@ jsonschema_rs = None +BENCHMARK_DATA = Path(__file__).parent.parent.parent / "benchmark/data" + + def load_json(filename): with open(filename) as fd: return json.load(fd) @@ -23,7 +27,7 @@ def load_json_str(filename): def load_from_benches(filename, loader=load_json): - return loader(f"../benchmark/data/{filename}") + return loader(BENCHMARK_DATA / filename) OPENAPI = load_from_benches("openapi.json") diff --git a/crates/jsonschema-py/python/jsonschema_rs/__init__.pyi b/crates/jsonschema-py/python/jsonschema_rs/__init__.pyi index 0e10789c..a57954ac 100644 --- a/crates/jsonschema-py/python/jsonschema_rs/__init__.pyi +++ b/crates/jsonschema-py/python/jsonschema_rs/__init__.pyi @@ -1,5 +1,5 @@ -from typing import Any, Callable, TypeVar from collections.abc import Iterator +from typing import Any, Callable, TypeVar _SchemaT = TypeVar("_SchemaT", bool, dict[str, Any]) _FormatFunc = TypeVar("_FormatFunc", bound=Callable[[str], bool]) diff --git a/crates/jsonschema-py/tests-py/test_suite.py b/crates/jsonschema-py/tests-py/test_suite.py index 00706cd5..858ccf5c 100644 --- a/crates/jsonschema-py/tests-py/test_suite.py +++ b/crates/jsonschema-py/tests-py/test_suite.py @@ -4,6 +4,7 @@ import socket import subprocess import sys +from pathlib import Path from time import sleep from urllib.parse import urlparse @@ -11,7 +12,7 @@ import jsonschema_rs -TEST_SUITE_PATH = "../jsonschema/tests/suite" +TEST_SUITE_PATH = Path(__file__).parent.parent.parent / "jsonschema/tests/suite" EXPONENTIAL_BASE = 2 JITTER = (0.0, 0.5) INITIAL_RETRY_DELAY = 0.05 @@ -41,7 +42,7 @@ def wait_until_responsive(url: str, retries: int = MAX_WAITING_RETRIES, delay: f @pytest.fixture(scope="session", autouse=True) def mock_server(): - process = subprocess.Popen(args=[sys.executable, f"{TEST_SUITE_PATH}/bin/jsonschema_suite", "serve"]) + process = subprocess.Popen(args=[sys.executable, TEST_SUITE_PATH / "bin/jsonschema_suite", "serve"]) wait_until_responsive("http://127.0.0.1:1234") try: yield @@ -89,7 +90,7 @@ def pytest_generate_tests(metafunc): filename, ) for draft in SUPPORTED_DRAFTS - for root, _, files in os.walk(f"{TEST_SUITE_PATH}/tests/draft{draft}/") + for root, _, files in os.walk(TEST_SUITE_PATH / f"tests/draft{draft}/") for filename in files for block in load_file(os.path.join(root, filename)) for test in block["tests"]