Skip to content

Commit 7de34b7

Browse files
DonDebonairFizzadar
authored andcommitted
feat: use ruff for linting and formatting
1 parent 30fab8a commit 7de34b7

File tree

9 files changed

+68
-195
lines changed

9 files changed

+68
-195
lines changed

.flake8

Lines changed: 0 additions & 17 deletions
This file was deleted.

.github/workflows/test.yml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,10 @@ jobs:
2222
python-version: "3.13"
2323
- name: Install uv
2424
uses: astral-sh/setup-uv@v6
25-
- run: uv sync --group test --no-default-groups
26-
- run: uv run flake8
25+
- uses: astral-sh/ruff-action@v3
26+
- uses: astral-sh/ruff-action@v3
27+
with:
28+
args: "format --check"
2729

2830
type-check:
2931
runs-on: ubuntu-24.04

docs/contributing.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,8 @@ uv sync
3535

3636
### Code Style & Type Checking
3737

38-
Code style is enforced via Black, isort and flake8. Types are checked with mypy currently, and pyright is recommended for local development though currently optional. There is a script to run the linting & type-checking:
38+
Code style is enforced via [ruff](https://docs.astral.sh/ruff/). Types are checked with mypy currently, and pyright is
39+
recommended for local development though currently optional. There is a script to run the linting & type-checking:
3940

4041
```sh
4142
scripts/dev-lint.sh

pyproject.toml

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -51,17 +51,13 @@ test = [
5151
"coverage>=7.7.1,<8",
5252
"pytest-cov>=7.0.0,<8",
5353
"pytest-testinfra>=10.2.2,<11",
54-
"black>=25.1.0,<26",
55-
"isort>=6.0.1,<7",
56-
"flake8>=7.1.2,<8",
57-
"flake8-black>=0.3.6,<0.4",
58-
"flake8-isort==6.1.2,<7",
5954
"pyyaml>=6.0.2,<7",
6055
"mypy==1.17.1",
6156
"types-cryptography>=3.3.23.2,<4",
6257
"types-paramiko>=2.7,<4",
6358
"types-python-dateutil>2,<3",
6459
"types-PyYAML>6,<7",
60+
"ruff>=0.13.1",
6561
"pyinfra-testgen==0.1.1",
6662
]
6763

@@ -80,7 +76,7 @@ dev = [
8076
"ipdb",
8177
"ipdbplugin",
8278
# dev-only lint extras
83-
"flake8-spellcheck==0.28.0",
79+
"typos>=1.36.2",
8480
"redbaron",
8581
]
8682

@@ -108,15 +104,11 @@ packages = ["src/pyinfra", "src/pyinfra_cli"]
108104
[tool.hatch.version]
109105
source = "uv-dynamic-versioning"
110106

111-
[tool.black]
107+
[tool.ruff]
112108
line-length = 100
113-
target-version = ["py38"]
114109

115-
[tool.isort]
116-
profile = "black"
117-
line_length = 100
118-
combine_as_imports = true
119-
include_trailing_comma = true
110+
[tool.ruff.lint.isort]
111+
combine-as-imports = true
120112

121113
[tool.mypy]
122114
check_untyped_defs = true

scripts/dev-lint.sh

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@
22

33
set -euo pipefail
44

5-
echo "Execute black..."
6-
uv run black ./
5+
echo "Execute ruff format..."
6+
uv run ruff format
77

8-
echo "Execute flake8..."
9-
uv run flake8
8+
echo "Execute ruff check..."
9+
uv run ruff check
1010

1111
echo "Execute mypy..."
1212
uv run mypy

scripts/spellcheck.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
#!/usr/bin/env bash
22

3-
flake8 --select=SC --ignore=
3+
uv run typos

src/pyinfra/facts/selinux.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ def command(self, target):
8282

8383
@override
8484
def process(self, output):
85-
# example output: /etc all files system_u:object_r:etc_t:s0 # noqa: SC100
85+
# example output: /etc all files system_u:object_r:etc_t:s0
8686
# but lines at end that won't match: /etc/systemd/system = /usr/lib/systemd/system
8787
if len(output) != 1:
8888
return self.default()
@@ -104,7 +104,7 @@ class SEPorts(FactBase):
104104
"""
105105

106106
default = dict
107-
# example output: amqp_port_t tcp 15672, 5671-5672 # noqa: SC100
107+
# example output: amqp_port_t tcp 15672, 5671-5672
108108
_regex = re.compile(r"^([\w_]+)\s+(\w+)\s+([\w\-,\s]+)$")
109109

110110
@override

tests/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# Import `pyinfra_cli` to trigger gevent monkey patching
2-
import logging # noqa: I100
2+
import logging
33

44
import gevent.hub
55

uv.lock

Lines changed: 49 additions & 154 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)