Skip to content

Commit

Permalink
Use ruff format instead of black
Browse files Browse the repository at this point in the history
This arguably makes `with ...` over multiple lines more readable (on top
of fewer dependencies).

Signed-off-by: Nils Philippsen <[email protected]>
  • Loading branch information
nphilipp committed Aug 30, 2024
1 parent 0e9cf55 commit 15adaa9
Show file tree
Hide file tree
Showing 12 changed files with 60 additions and 145 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/main.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -73,4 +73,4 @@ jobs:
- uses: actions/checkout@v4

- name: run tests through tox
run: "tox -e black,ruff"
run: "tox -e format,lint"
15 changes: 5 additions & 10 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,12 @@ repos:
- id: check-added-large-files
- id: check-yaml
- id: debug-statements
- repo: https://github.com/pycqa/flake8
rev: 6.0.0
- repo: https://github.com/astral-sh/ruff-pre-commit
hooks:
- id: flake8
- repo: https://github.com/psf/black
rev: 22.12.0
hooks:
- id: black
args:
- --diff
- --check
- id: ruff
types: [file, python]
- id: ruff-format
types: [file, python]
- repo: https://github.com/adrienverge/yamllint
rev: v1.29.0
hooks:
Expand Down
97 changes: 1 addition & 96 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 6 additions & 4 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@
requires = ["poetry-core"]
build-backend = "poetry.core.masonry.api"

[project]
requires-python = ">=3.9"

[tool.poetry]
name = "rpmautospec"
version = "0.7.1"
Expand Down Expand Up @@ -57,7 +60,6 @@ pytest-xdist = [
{ version = "^2.5.0 || ^3", python = "^3.12" }
]
coverage = "^7.2.0"
black = "^24.1.0"
ruff = "^0.2.0 || ^0.3.0 || ^0.4.0 || ^0.5.0 || ^0.6.0"

[tool.poetry.scripts]
Expand All @@ -72,9 +74,6 @@ rpmautospec = "rpmautospec.cli:cli"
[tool.poetry.build]
generate-setup-file = true

[tool.black]
line_length = 100

[tool.ruff]
line-length = 100
target-version = "py39"
Expand All @@ -89,3 +88,6 @@ allowed-confusables = ["’"]
[tool.pytest.ini_options]
addopts = "--cov --cov-config .coveragerc --cov-report term --cov-report xml --cov-report html"
tmp_path_retention_policy = "failed"

[tool.black]
line_length = 100
9 changes: 6 additions & 3 deletions rpmautospec/pkg_history.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,9 +139,12 @@ def _get_rpmverflags(
rpm.addMacro("_sourcedir", f"{path}")
rpm.addMacro("_builddir", f"{path}")

with specfile.open(mode="rb") as unabridged, NamedTemporaryFile(
mode="wb", prefix=f"rpmautospec-abridged-{name}-", suffix=".spec"
) as abridged:
with (
specfile.open(mode="rb") as unabridged,
NamedTemporaryFile(
mode="wb", prefix=f"rpmautospec-abridged-{name}-", suffix=".spec"
) as abridged,
):
# Attempt to parse a shortened version of the spec file first, to speed up
# processing in certain cases. This includes all lines before `%prep`, i.e. in most
# cases everything which is needed to make RPM parsing succeed and contain the info
Expand Down
11 changes: 6 additions & 5 deletions rpmautospec/subcommands/process_distgit.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,11 +85,12 @@ def do_process_distgit(

autorelease_number = result["release-number"]

with processor.specfile.open(
"r", encoding="utf-8", errors="surrogateescape"
) as specfile, tempfile.NamedTemporaryFile(
"w", encoding="utf-8", errors="surrogateescape"
) as tmp_specfile:
with (
processor.specfile.open("r", encoding="utf-8", errors="surrogateescape") as specfile,
tempfile.NamedTemporaryFile(
"w", encoding="utf-8", errors="surrogateescape"
) as tmp_specfile,
):
# Process the spec file into a temporary file...
used_features = []

Expand Down
7 changes: 4 additions & 3 deletions tests/rpmautospec/subcommands/test_changelog.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,9 +69,10 @@ def test_do_generate_changelog_error():


def test_generate_changelog(cli_runner):
with mock.patch.object(
changelog, "do_generate_changelog"
) as do_generate_changelog, mock.patch.object(changelog, "pager") as pager:
with (
mock.patch.object(changelog, "do_generate_changelog") as do_generate_changelog,
mock.patch.object(changelog, "pager") as pager,
):
generated_changelog = do_generate_changelog.return_value

pager_sentinel = object()
Expand Down
14 changes: 8 additions & 6 deletions tests/rpmautospec/subcommands/test_process_distgit.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,9 +119,10 @@ def fuzz_spec_file(
):
"""Fuzz a spec file in ways which (often) shouldn't change the outcome"""
new_spec_file_path = spec_file_path.with_name(spec_file_path.name + ".new")
with spec_file_path.open("r", encoding="utf-8") as orig, new_spec_file_path.open(
"w", encoding="utf-8"
) as new:
with (
spec_file_path.open("r", encoding="utf-8") as orig,
new_spec_file_path.open("w", encoding="utf-8") as new,
):
if is_processed:
autorelease_blurb = process_distgit.AUTORELEASE_TEMPLATE.format(autorelease_number=15)
print(
Expand Down Expand Up @@ -353,9 +354,10 @@ def wrap_cls(*args, **kwargs):
/ "dummy-test-package-gloster.spec.expected"
)

with tempfile.NamedTemporaryFile(mode="w+", encoding="utf8") as tmpspec, open(
expected_spec_file_path, "r", encoding="utf-8"
) as expspec:
with (
tempfile.NamedTemporaryFile(mode="w+", encoding="utf8") as tmpspec,
open(expected_spec_file_path, "r", encoding="utf-8") as expspec,
):
# Copy expected spec file and potentially bump release number
relnum_seen = None
relnumdef_re = re.compile(
Expand Down
8 changes: 5 additions & 3 deletions tests/rpmautospec/test_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,11 @@ def test_setup_logging(log_level_name):
"""Test the setup_logging() function."""
log_level = getattr(logging, log_level_name)

with mock.patch.object(cli.logging, "StreamHandler") as StreamHandler, mock.patch.object(
cli.logging, "lastResort"
) as lastResort, mock.patch.object(cli.logging, "basicConfig") as basicConfig:
with (
mock.patch.object(cli.logging, "StreamHandler") as StreamHandler,
mock.patch.object(cli.logging, "lastResort") as lastResort,
mock.patch.object(cli.logging, "basicConfig") as basicConfig,
):
info_handler = StreamHandler.return_value
cli.setup_logging(log_level)

Expand Down
7 changes: 4 additions & 3 deletions tests/rpmautospec/test_pager.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,10 @@ def test_page(testcase):
else:
os.environ.pop("RPMAUTOSPEC_LESS", None)

with mock.patch.object(pager.pydoc, "pager") as pydoc_pager, mock.patch.object(
pager, "print"
) as print:
with (
mock.patch.object(pager.pydoc, "pager") as pydoc_pager,
mock.patch.object(pager, "print") as print,
):
pager.page("Hello!", enabled="enabled" in testcase)

if "disabled" in testcase:
Expand Down
13 changes: 8 additions & 5 deletions tests/rpmautospec/test_pkg_history.py
Original file line number Diff line number Diff line change
Expand Up @@ -274,11 +274,14 @@ def test__get_rpmverflags_for_commit(self, testcase, specfile, repo, processor):
)
]

with mock.patch.object(
processor, "_get_rpmverflags", wraps=processor._get_rpmverflags
) as _get_rpmverflags, mock.patch.object(
pkg_history, "_checkout_tree_files", side_effect=pkg_history._checkout_tree_files
) as _checkout_tree_files:
with (
mock.patch.object(
processor, "_get_rpmverflags", wraps=processor._get_rpmverflags
) as _get_rpmverflags,
mock.patch.object(
pkg_history, "_checkout_tree_files", side_effect=pkg_history._checkout_tree_files
) as _checkout_tree_files,
):
side_effect = [mock.DEFAULT]
if needs_full_repo:
side_effect.insert(0, {"error": "specfile-parse-error"})
Expand Down
12 changes: 6 additions & 6 deletions tox.ini
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
[tox]
minversion = 3.9.0
envlist =
black
ruff
format
lint
py{39,310,311,312}
isolated_build = true
skip_missing_interpreters = true
Expand All @@ -21,12 +21,12 @@ commands_pre =
commands =
pytest --import-mode importlib -n auto -o 'addopts=--cov --cov-config .coveragerc --cov-report term --cov-report xml --cov-report html --cov-fail-under {env:COV_FAIL_UNDER:100}' tests/

[testenv:black]
deps = black
[testenv:format]
deps = ruff
commands_pre =
commands = black --check --diff rpmautospec/ tests/
commands = ruff format --diff rpmautospec/ tests/

[testenv:ruff]
[testenv:lint]
deps = ruff
commands_pre =
commands = ruff check rpmautospec/ tests/
Expand Down

0 comments on commit 15adaa9

Please sign in to comment.