Skip to content

Commit 1c7f1ea

Browse files
authored
Merge pull request #56 from openzim/remove-black
remove black as dev dependency and upgrade ruff
2 parents 4141bf2 + 590c6b1 commit 1c7f1ea

8 files changed

Lines changed: 83 additions & 103 deletions

File tree

.github/workflows/QA.yaml

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,13 @@ jobs:
2222
- name: Install dependencies (and project)
2323
run: |
2424
pip install -U pip
25-
pip install -e .[lint,scripts,test,check]
25+
pip install -e .[qa,scripts,test]
2626
27-
- name: Check black formatting
28-
run: inv lint-black
27+
- name: Check Linting
28+
run: inv check-lint
2929

30-
- name: Check ruff
31-
run: inv lint-ruff
30+
- name: Check Formatting
31+
run: inv check-format
3232

33-
- name: Check pyright
34-
run: inv check-pyright
33+
- name: Check Type
34+
run: inv check-type

.pre-commit-config.yaml

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,13 @@ repos:
66
hooks:
77
- id: trailing-whitespace
88
- id: end-of-file-fixer
9-
- repo: https://github.com/psf/black
10-
rev: "24.4.2"
11-
hooks:
12-
- id: black
9+
1310
- repo: https://github.com/astral-sh/ruff-pre-commit
14-
rev: v0.5.1
11+
rev: v0.15.12
1512
hooks:
16-
- id: ruff
13+
- id: ruff-check
14+
- id: ruff-format
15+
1716
- repo: https://github.com/RobertCraigie/pyright-python
1817
rev: v1.1.370
1918
hooks:

CHANGELOG.md

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,14 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
77

88
## [Unreleased]
99

10+
- Remove `black` from `pyproject.toml` and `tasks.py`
11+
- Upgrade `ruff` to `0.15.12`
12+
- Merge `check` and `lint` features into `qa`
13+
- Remove `lint-black`, `lint-ruff`, `fix-black`, `fix-ruff`, `lintall`, `fixall`, and
14+
`check-pyright` invoke tasks
15+
- Add new invoke tasks: `check-lint`, `check-format`, `check-type`, `check-all`,
16+
`fix-format`, `fix-lint` and `fix-all`
17+
1018
### Changed
1119

1220
- Upgrade Docker image to use python:3.12-slim-bookworm
@@ -86,7 +94,6 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
8694

8795
- Fix few invoke task arguments and help
8896

89-
9097
## [0.1.7] - 2023-08-04
9198

9299
### Changed
@@ -141,8 +148,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
141148

142149
### Added
143150

144-
- Add the scripts to lint's features, otherwise we can use the hatch run lint:*
145-
151+
- Add the scripts to lint's features, otherwise we can use the hatch run lint:\*
146152

147153
## [0.1.0] - 2023-06-22
148154

docs/Developer-Setup.md

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,6 @@ The key part is the symlink to `.venv` so that LSP-pyright and other tool can au
4949
- When doing some JS, you obviously need a Node.JS as well
5050
- [hatch](https://pypi.org/project/hatch/) installed globally
5151
- [Visual Studio Code](https://github.com/microsoft/vscode) with following extensions (more or less related to Python development)
52-
- Black Formater (Microsoft)
5352
- Dev Containers (Microsoft)
5453
- Docker (Microsoft)
5554
- Excalidraw (pomdtr)
@@ -77,12 +76,6 @@ This additional Hatch config section ensures that all virtual environments (the
7776
On every project, create a local `.vscode/settings.json` to automatically format your code (adjust `typeCheckingMode` depending on your project):
7877
``` json
7978
{
80-
"[python]": {
81-
"editor.defaultFormatter": "ms-python.black-formatter",
82-
"editor.codeActionsOnSave": {
83-
"source.organizeImports": "explicit"
84-
}
85-
},
8679
"python.analysis.typeCheckingMode": "strict",
8780
"eslint.validate": ["javascript", "typescript", "vue"],
8881
"eslint.workingDirectories": [{ "mode": "auto" }],

docs/Usage.md

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,12 @@ If you've not already read it, please check our [Policy](./Policy.md) first.
1313
❯ hatch env show
1414

1515
# linting, testing, coverage, checking
16-
❯ hatch run lint:all
17-
❯ hatch run lint:fixall
16+
❯ hatch run qa:check-all
17+
❯ hatch run qa:fix-all
1818
# run tests on all matrixed' envs
1919
❯ hatch run test:run
2020
# run tests in a single matrixed' env
2121
❯ hatch env run -e test -i py=3.11 coverage
22-
# run static type checks
23-
❯ hatch env run check:all
2422

2523
# building packages
2624
❯ hatch build
@@ -38,14 +36,15 @@ If you've not already read it, please check our [Policy](./Policy.md) first.
3836
# scripts discovery
3937
❯ inv -l
4038

41-
# linting, testing, coverage, static type checks
42-
❯ inv lintall
43-
❯ inv fixall
39+
# check linting, formatting and static type checks
40+
❯ inv check-all
41+
# fix everything automatically
42+
❯ inv fix-all
43+
# run tests
4444
❯ inv test
4545
❯ inv coverage
46-
❯ inv checkall
4746

4847
# building packages
4948
❯ pip install build
5049
❯ python3 -m build
51-
```
50+
```

docs/pyproject.toml.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,12 @@ Version must be dynamic and set once in code. `module.__about__` usually.
2020

2121
### Linting
2222

23-
- Black (latest available version)
23+
- Ruff (latest available version)
2424
- Ruff for import sorting (isort-like) and many other checks
2525
- Dedicated hatch environment
26-
- Black and ruff configuration so those works without hatch as well
27-
- Scripts for just black and just ruff checking
28-
- Scripts for black fixing and ruf fixing (accepts params)
26+
- Ruff configuration so those works without hatch as well
27+
- Scripts for just ruff checking
28+
- Scripts for ruff fixing (accepts params)
2929
- Scripts for global checking and fixing
3030
- Sample ruff configuration
3131

@@ -42,4 +42,4 @@ Version must be dynamic and set once in code. `module.__about__` usually.
4242
- Dedicated hatch environment
4343
- Hatch environment matrix to easily tests on multiple python versions
4444
- pytest and coverage configuration so those works without hatch as well
45-
- Scripts for running tests (accepts params), running with coverage and reporting
45+
- Scripts for running tests (accepts params), running with coverage and reporting

pyproject.toml

Lines changed: 14 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,8 @@ additional-keywords = ["some"]
1919
scripts = [
2020
"invoke==2.2.0",
2121
]
22-
lint = [
23-
"black==24.4.2",
24-
"ruff==0.5.1",
25-
]
26-
check = [
22+
qa = [
23+
"ruff==0.15.12",
2724
"pyright==1.1.370",
2825
]
2926
test = [
@@ -34,9 +31,8 @@ dev = [
3431
"pre-commit==3.7.1",
3532
"debugpy==1.8.2",
3633
"great-project[scripts]",
37-
"great-project[lint]",
34+
"great-project[qa]",
3835
"great-project[test]",
39-
"great-project[check]",
4036
]
4137

4238
[project.scripts]
@@ -69,29 +65,20 @@ report-cov = "inv report-cov"
6965
coverage = "inv coverage --args '{args}'"
7066
html = "inv coverage --html --args '{args}'"
7167

72-
[tool.hatch.envs.lint]
73-
template = "lint"
68+
[tool.hatch.envs.qa]
69+
template = "qa"
7470
skip-install = false
75-
features = ["scripts", "lint"]
76-
77-
[tool.hatch.envs.lint.scripts]
78-
black = "inv lint-black --args '{args}'"
79-
ruff = "inv lint-ruff --args '{args}'"
80-
all = "inv lintall --args '{args}'"
81-
fix-black = "inv fix-black --args '{args}'"
82-
fix-ruff = "inv fix-ruff --args '{args}'"
83-
fixall = "inv fixall --args '{args}'"
71+
features = ["scripts", "qa", "test"]
8472

85-
[tool.hatch.envs.check]
86-
features = ["scripts", "check"]
73+
[tool.hatch.envs.qa.scripts]
74+
check-lint = "inv check-lint --args '{args}'"
75+
check-format = "inv check-format --args '{args}'"
76+
check-type = "inv check-type --args '{args}'"
77+
check-all = "inv check-all --args '{args}'"
78+
fix-format = "inv fix-format --args '{args}'"
79+
fix-lint = "inv fix-lint --args '{args}'"
80+
fix-all = "inv fix-all --args '{args}'"
8781

88-
[tool.hatch.envs.check.scripts]
89-
pyright = "inv check-pyright --args '{args}'"
90-
all = "inv checkall --args '{args}'"
91-
92-
[tool.black]
93-
line-length = 88
94-
target-version = ['py311']
9582

9683
[tool.ruff]
9784
target-version = "py312"

tasks.py

Lines changed: 35 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -42,69 +42,65 @@ def coverage(ctx: Context, args: str = "", *, html: bool = False):
4242
report_cov(ctx, html=html)
4343

4444

45-
@task(optional=["args"], help={"args": "black additional arguments"})
46-
def lint_black(ctx: Context, args: str = "."):
45+
def _lint(ctx: Context, args: str = "."):
4746
args = args or "." # needed for hatch script
48-
ctx.run("black --version", pty=use_pty)
49-
ctx.run(f"black --check --diff {args}", pty=use_pty)
47+
ctx.run("ruff --version", pty=use_pty)
48+
ctx.run(f"ruff check {args}", pty=use_pty)
5049

5150

5251
@task(optional=["args"], help={"args": "ruff additional arguments"})
53-
def lint_ruff(ctx: Context, args: str = "."):
52+
def check_lint(ctx: Context, args: str = "."):
53+
"""check linting with ruff"""
5454
args = args or "." # needed for hatch script
55-
ctx.run("ruff --version", pty=use_pty)
56-
ctx.run(f"ruff check {args}", pty=use_pty)
55+
_lint(ctx, args)
5756

5857

59-
@task(
60-
optional=["args"],
61-
help={
62-
"args": "linting tools (black, ruff) additional arguments, typically a path",
63-
},
64-
)
65-
def lintall(ctx: Context, args: str = "."):
66-
"""Check linting"""
58+
@task(optional=["args"], help={"args": "ruff additional arguments"})
59+
def fix_lint(ctx: Context, args: str = "."):
60+
"""fix linting issues with ruff"""
6761
args = args or "." # needed for hatch script
68-
lint_black(ctx, args)
69-
lint_ruff(ctx, args)
62+
_lint(ctx, f"--fix {args}")
7063

7164

7265
@task(optional=["args"], help={"args": "check tools (pyright) additional arguments"})
73-
def check_pyright(ctx: Context, args: str = ""):
66+
def check_type(ctx: Context, args: str = ""):
7467
"""check static types with pyright"""
7568
ctx.run("pyright --version")
7669
ctx.run(f"pyright {args}", pty=use_pty)
7770

7871

79-
@task(optional=["args"], help={"args": "check tools (pyright) additional arguments"})
80-
def checkall(ctx: Context, args: str = ""):
81-
"""check static types"""
82-
check_pyright(ctx, args)
72+
def _format(ctx: Context, args: str = "."):
73+
args = args or "." # needed for hatch script
74+
ctx.run("ruff --version", pty=use_pty)
75+
ctx.run(f"ruff format {args}", pty=use_pty)
8376

8477

85-
@task(optional=["args"], help={"args": "black additional arguments"})
86-
def fix_black(ctx: Context, args: str = "."):
87-
"""fix black formatting"""
78+
@task(optional=["args"], help={"args": "ruff additional arguments"})
79+
def check_format(ctx: Context, args: str = "."):
80+
"""check formatting with ruff"""
8881
args = args or "." # needed for hatch script
89-
ctx.run(f"black {args}", pty=use_pty)
82+
_format(ctx, f"--check {args}")
9083

9184

9285
@task(optional=["args"], help={"args": "ruff additional arguments"})
93-
def fix_ruff(ctx: Context, args: str = "."):
94-
"""fix all ruff rules"""
86+
def fix_format(ctx: Context, args: str = "."):
87+
"""fix formatting with ruff"""
9588
args = args or "." # needed for hatch script
96-
ctx.run(f"ruff check --fix {args}", pty=use_pty)
89+
_format(ctx, args)
9790

9891

99-
@task(
100-
optional=["args"],
101-
help={
102-
"args": "linting tools (black, ruff) additional arguments, typically a path",
103-
},
104-
)
105-
def fixall(ctx: Context, args: str = "."):
92+
@task(optional=["args"], help={"args": "additional arguments"})
93+
def check_all(ctx: Context, args: str = ""):
94+
"""check linting, formatting and static types"""
95+
args = args or "." # needed for hatch script
96+
check_lint(ctx, args)
97+
check_format(ctx, args)
98+
check_type(ctx, args)
99+
100+
101+
@task(optional=["args"], help={"args": "additional arguments"})
102+
def fix_all(ctx: Context, args: str = ""):
106103
"""Fix everything automatically"""
107104
args = args or "." # needed for hatch script
108-
fix_black(ctx, args)
109-
fix_ruff(ctx, args)
110-
lintall(ctx, args)
105+
fix_lint(ctx, args)
106+
fix_format(ctx, args)

0 commit comments

Comments
 (0)