Skip to content

Commit

Permalink
Use Ruff & Black instead of pre-commit
Browse files Browse the repository at this point in the history
Ruff is a new sexy in the town. Despite being young, it's much more
lightweight and faster than using pre-commit. The latter always sets up
an isolated virtual environments for each hook which slow and boring.
  • Loading branch information
ikalnytskyi committed Nov 2, 2023
1 parent 1d13f7b commit 1072f2b
Show file tree
Hide file tree
Showing 10 changed files with 31 additions and 49 deletions.
8 changes: 5 additions & 3 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,10 @@ jobs:
with:
python-version: "3.10"

- name: Run pre-commit
run: pipx run -- hatch run lint:run
- name: Lint
run: pipx run -- hatch run lint:check
env:
RUFF_OUTPUT_FORMAT: github

test:
runs-on: ubuntu-latest
Expand All @@ -35,5 +37,5 @@ jobs:
- name: Set up prerequisites
run: sudo apt-get install graphviz libgraphviz-dev

- name: Run tests
- name: Test
run: pipx run -- hatch run test:run
34 changes: 0 additions & 34 deletions .pre-commit-config.yaml

This file was deleted.

16 changes: 13 additions & 3 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,6 @@ source = "vcs"
sources = ["src"]

[tool.hatch.envs.test]
python = "3.10"
dependencies = [
"mock >= 4.0",
"coverage >= 6.4",
Expand All @@ -72,5 +71,16 @@ scripts.run = "python -m pytest {args:-vv}"

[tool.hatch.envs.lint]
detached = true
dependencies = ["pre-commit"]
scripts.run = "python -m pre_commit run --all-files --show-diff-on-failure"
dependencies = ["black >= 23.10.1", "ruff >= 0.1.3"]
scripts.check = ["ruff {args:.}", "black --check --diff {args:.}"]
scripts.fmt = ["ruff --fix {args:.}", "black {args:.}"]

[tool.ruff]
select = ["F", "E", "W", "I", "S", "FBT", "B", "C4", "DTZ", "T10", "ISC", "RET", "SLF", "RUF"]
ignore = ["S101", "S701", "B904", "RUF001"]

[tool.ruff.isort]
known-first-party = ["holocron"]

[tool.ruff.per-file-ignores]
"tests/*" = ["SLF001", "E501", "S603", "S607"]
2 changes: 1 addition & 1 deletion src/holocron/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ def format(self, record):
logger.setLevel(level)

# capture warnings issued by 'warnings' module
logging.captureWarnings(True)
logging.captureWarnings(capture=True)
yield
pending_handler.flush()

Expand Down
2 changes: 1 addition & 1 deletion src/holocron/_core/application.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
class Application:
"""Application instance orchestrates processors execution."""

_processor_reserved_props = {"name", "args"}
_processor_reserved_props = frozenset({"name", "args"})

def __init__(self, metadata=None):
# Metadata is a KV store shared between processors. It serves two
Expand Down
5 changes: 4 additions & 1 deletion src/holocron/_processors/_misc.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
_logger = logging.getLogger("holocron")


def resolve_json_references(value, context, keep_unknown=True):
def resolve_json_references(value, context, *, keep_unknown=True):
def _do_resolve(node):
node = copy.copy(node)

Expand Down Expand Up @@ -85,20 +85,23 @@ def is_encoding(value):
import codecs

return codecs.lookup(value)
return None

@format_checker.checks("timezone", ())
def is_timezone(value):
if isinstance(value, str):
import dateutil.tz

return dateutil.tz.gettz(value)
return None

@format_checker.checks("path", (TypeError,))
def is_path(value):
if isinstance(value, str):
import pathlib

return pathlib.Path(value)
return None

jsonschema.validate(
arguments,
Expand Down
3 changes: 2 additions & 1 deletion src/holocron/_processors/jinja2/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@

import pathlib

import jinja2
import jsonpointer

import jinja2

from .. import source
from .._misc import parameters

Expand Down
4 changes: 2 additions & 2 deletions tests/_processors/test_import_processors.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ def process(app, items):

# Test that out of two processors (i.e. 'yoda' and 'vader'), only expected
# ones are registered in testapp instance.
assert set(["yoda", "vader"]) & set(testapp._processors) == set(registered)
assert {"yoda", "vader"} & set(testapp._processors) == set(registered)


@pytest.mark.parametrize(
Expand All @@ -140,7 +140,7 @@ def test_imports_system_wide(testapp, runprocessor, imports, registered):

# Test that out of two processors (i.e. 'yoda' and 'vader'), only expected
# ones are registered in testapp instance.
assert set(["yoda", "vader"]) & set(testapp._processors) == set(registered)
assert {"yoda", "vader"} & set(testapp._processors) == set(registered)


def test_imports_precedence(testapp, runprocessor, tmpdir, monkeypatch):
Expand Down
2 changes: 1 addition & 1 deletion tests/_processors/test_sitemap.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
class _pytest_xmlasdict:
"""Assert that a given XML has the same semantic meaning."""

def __init__(self, expected, ungzip=False, **kwargs):
def __init__(self, expected, *, ungzip=False, **kwargs):
self._expected = expected
self._ungzip = ungzip
self._kwargs = kwargs
Expand Down
4 changes: 2 additions & 2 deletions tests/test_main.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,9 @@ def example_site(create_site):

@pytest.fixture(scope="function")
def execute(capsys):
def execute(args, as_subprocess=True):
def execute(args, *, as_subprocess=True):
if as_subprocess:
return subprocess.check_output(["holocron"] + args, stderr=subprocess.PIPE)
return subprocess.check_output(["holocron", *args], stderr=subprocess.PIPE)

from holocron.__main__ import main

Expand Down

0 comments on commit 1072f2b

Please sign in to comment.