Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 7 additions & 8 deletions .github/workflows/QA.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,12 @@ jobs:
- name: Install dependencies (and project)
run: |
pip install -U pip
pip install -e .[lint,scripts,test,check]
pip install -e .[qa,scripts,test]

- name: Check black formatting
run: inv lint-black

- name: Check ruff
run: inv lint-ruff
- name: Check Lint and Formatting
run: |
inv check-format
inv lint

- name: Check pyright
run: inv check-pyright
- name: Type Check
run: inv type-check
11 changes: 5 additions & 6 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,13 @@ repos:
hooks:
- id: trailing-whitespace
- id: end-of-file-fixer
- repo: https://github.com/psf/black
rev: "24.4.2"
hooks:
- id: black

- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.5.1
rev: v0.15.12
hooks:
- id: ruff
- id: ruff-check
- id: ruff-format

- repo: https://github.com/RobertCraigie/pyright-python
rev: v1.1.370
hooks:
Expand Down
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

- Remove `black` from `pyproject.toml` and `tasks.py`
- Upgrade `ruff` to `0.15.12`

### Changed

- Upgrade Docker image to use python:3.12-slim-bookworm
Expand Down
7 changes: 0 additions & 7 deletions docs/Developer-Setup.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@ The key part is the symlink to `.venv` so that LSP-pyright and other tool can au
- When doing some JS, you obviously need a Node.JS as well
- [hatch](https://pypi.org/project/hatch/) installed globally
- [Visual Studio Code](https://github.com/microsoft/vscode) with following extensions (more or less related to Python development)
- Black Formater (Microsoft)
- Dev Containers (Microsoft)
- Docker (Microsoft)
- Excalidraw (pomdtr)
Expand Down Expand Up @@ -77,12 +76,6 @@ This additional Hatch config section ensures that all virtual environments (the
On every project, create a local `.vscode/settings.json` to automatically format your code (adjust `typeCheckingMode` depending on your project):
``` json
{
"[python]": {
"editor.defaultFormatter": "ms-python.black-formatter",
"editor.codeActionsOnSave": {
"source.organizeImports": "explicit"
}
},
"python.analysis.typeCheckingMode": "strict",
"eslint.validate": ["javascript", "typescript", "vue"],
"eslint.workingDirectories": [{ "mode": "auto" }],
Expand Down
12 changes: 6 additions & 6 deletions docs/Usage.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,14 @@ If you've not already read it, please check our [Policy](./Policy.md) first.
❯ hatch env show

# linting, testing, coverage, checking
❯ hatch run lint:all
❯ hatch run lint:fixall
❯ hatch run qa:analyse-all
❯ hatch run qa:fixall
# run tests on all matrixed' envs
❯ hatch run test:run
# run tests in a single matrixed' env
❯ hatch env run -e test -i py=3.11 coverage
# run static type checks
❯ hatch env run check:all
❯ hatch env run -e qa type-check

# building packages
❯ hatch build
Expand All @@ -39,13 +39,13 @@ If you've not already read it, please check our [Policy](./Policy.md) first.
❯ inv -l

# linting, testing, coverage, static type checks
❯ inv lintall
❯ inv analyse-all
❯ inv fixall
❯ inv test
❯ inv coverage
❯ inv checkall
❯ inv type-check

# building packages
❯ pip install build
❯ python3 -m build
```
```
10 changes: 5 additions & 5 deletions docs/pyproject.toml.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,12 @@ Version must be dynamic and set once in code. `module.__about__` usually.

### Linting

- Black (latest available version)
- Ruff (latest available version)
- Ruff for import sorting (isort-like) and many other checks
- Dedicated hatch environment
- Black and ruff configuration so those works without hatch as well
- Scripts for just black and just ruff checking
- Scripts for black fixing and ruf fixing (accepts params)
- Ruff configuration so those works without hatch as well
- Scripts for just ruff checking
- Scripts for ruff fixing (accepts params)
- Scripts for global checking and fixing
- Sample ruff configuration

Expand All @@ -42,4 +42,4 @@ Version must be dynamic and set once in code. `module.__about__` usually.
- Dedicated hatch environment
- Hatch environment matrix to easily tests on multiple python versions
- pytest and coverage configuration so those works without hatch as well
- Scripts for running tests (accepts params), running with coverage and reporting
- Scripts for running tests (accepts params), running with coverage and reporting
40 changes: 13 additions & 27 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,8 @@ additional-keywords = ["some"]
scripts = [
"invoke==2.2.0",
]
lint = [
"black==24.4.2",
"ruff==0.5.1",
]
check = [
qa = [
"ruff==0.15.12",
"pyright==1.1.370",
]
test = [
Expand All @@ -34,9 +31,8 @@ dev = [
"pre-commit==3.7.1",
"debugpy==1.8.2",
"great-project[scripts]",
"great-project[lint]",
"great-project[qa]",
"great-project[test]",
"great-project[check]",
]

[project.scripts]
Expand Down Expand Up @@ -69,29 +65,19 @@ report-cov = "inv report-cov"
coverage = "inv coverage --args '{args}'"
html = "inv coverage --html --args '{args}'"

[tool.hatch.envs.lint]
template = "lint"
[tool.hatch.envs.qa]
template = "qa"
skip-install = false
features = ["scripts", "lint"]

[tool.hatch.envs.lint.scripts]
black = "inv lint-black --args '{args}'"
ruff = "inv lint-ruff --args '{args}'"
all = "inv lintall --args '{args}'"
fix-black = "inv fix-black --args '{args}'"
fix-ruff = "inv fix-ruff --args '{args}'"
fixall = "inv fixall --args '{args}'"
features = ["scripts", "qa", "test"]

[tool.hatch.envs.check]
features = ["scripts", "check"]
[tool.hatch.envs.qa.scripts]
lint = "inv lint --args '{args}'"
format = "inv format --args '{args}'"
check-format = "inv check-format"
fixall = "inv fixall"
type-check = "inv type-check --args '{args}'"
analyse-all = "inv analyse-all"

[tool.hatch.envs.check.scripts]
pyright = "inv check-pyright --args '{args}'"
all = "inv checkall --args '{args}'"

[tool.black]
line-length = 88
target-version = ['py311']

[tool.ruff]
target-version = "py312"
Expand Down
64 changes: 19 additions & 45 deletions tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,69 +42,43 @@ def coverage(ctx: Context, args: str = "", *, html: bool = False):
report_cov(ctx, html=html)


@task(optional=["args"], help={"args": "black additional arguments"})
def lint_black(ctx: Context, args: str = "."):
args = args or "." # needed for hatch script
ctx.run("black --version", pty=use_pty)
ctx.run(f"black --check --diff {args}", pty=use_pty)


@task(optional=["args"], help={"args": "ruff additional arguments"})
def lint_ruff(ctx: Context, args: str = "."):
def lint(ctx: Context, args: str = "."):
args = args or "." # needed for hatch script
ctx.run("ruff --version", pty=use_pty)
ctx.run(f"ruff check {args}", pty=use_pty)


@task(
optional=["args"],
help={
"args": "linting tools (black, ruff) additional arguments, typically a path",
},
)
def lintall(ctx: Context, args: str = "."):
"""Check linting"""
args = args or "." # needed for hatch script
lint_black(ctx, args)
lint_ruff(ctx, args)


@task(optional=["args"], help={"args": "check tools (pyright) additional arguments"})
def check_pyright(ctx: Context, args: str = ""):
def type_check(ctx: Context, args: str = ""):
"""check static types with pyright"""
ctx.run("pyright --version")
ctx.run(f"pyright {args}", pty=use_pty)


@task(optional=["args"], help={"args": "check tools (pyright) additional arguments"})
def checkall(ctx: Context, args: str = ""):
@task()
def analyse_all(ctx: Context):
"""check static types"""
check_pyright(ctx, args)
lint(ctx)
format(ctx, "--check")
type_check(ctx)


@task(optional=["args"], help={"args": "black additional arguments"})
def fix_black(ctx: Context, args: str = "."):
"""fix black formatting"""
@task(optional=["args"], help={"args": "ruff additional arguments"})
def format(ctx: Context, args: str = "."): # noqa: A001
"""fix ruff formatting"""
args = args or "." # needed for hatch script
ctx.run(f"black {args}", pty=use_pty)
ctx.run("ruff --version", pty=use_pty)
ctx.run(f"ruff format {args}", pty=use_pty)


@task(optional=["args"], help={"args": "ruff additional arguments"})
def fix_ruff(ctx: Context, args: str = "."):
"""fix all ruff rules"""
args = args or "." # needed for hatch script
ctx.run(f"ruff check --fix {args}", pty=use_pty)
@task()
def check_format(ctx: Context):
format(ctx, "--check")


@task(
optional=["args"],
help={
"args": "linting tools (black, ruff) additional arguments, typically a path",
},
)
def fixall(ctx: Context, args: str = "."):
@task()
def fixall(ctx: Context):
"""Fix everything automatically"""
args = args or "." # needed for hatch script
fix_black(ctx, args)
fix_ruff(ctx, args)
lintall(ctx, args)
lint(ctx, "--fix")
format(ctx)
Loading