Skip to content

Modernise Packaging and CI #4

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Sep 24, 2024
Merged
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
25 changes: 13 additions & 12 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Python application
name: Run Python Tests and Pre-Commit Hooks

on:
push:
Expand All @@ -8,25 +8,26 @@ on:
branches:
- main
jobs:
build:
tests:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v4

- name: Set up Python 3.10
uses: actions/setup-python@v2
uses: actions/setup-python@v5
with:
python-version: '3.10'

- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install pre-commit
pip install -e .[dev]
- name: Install uv
uses: astral-sh/setup-uv@v3
with:
version: "0.4.15"

- name: Install project
run: uv sync --all-extras --dev

- name: Run pre-commit hooks
run: pre-commit run --all-files
run: uvx --with pre-commit pre-commit run --all-files

- name: Run tests
run: |
python -m unittest discover
run: uv run python -m unittest discover
13 changes: 13 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,19 @@ repos:
args: [--unittest]
- id: requirements-txt-fixer

- repo: https://github.com/asottile/pyupgrade
rev: v3.17.0
hooks:
- id: pyupgrade
args: ["--py310-plus"]

- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.6.7
hooks:
# Run the linter.
- id: ruff
args: ["--fix"]

- repo: https://github.com/psf/black-pre-commit-mirror
rev: 23.9.1
hooks:
Expand Down
1 change: 0 additions & 1 deletion .version

This file was deleted.

6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,12 @@ Note: Either `errors_enabled` or `errors_ignored` are enforced, not both.

The configuration file supports some magic keys that make it easier to configure the script.

##### `__default____`
##### `__default__`

The `__default____` key can be used to apply the same configuration to all the files in the repository.
The `__default__` key can be used to apply the same configuration to all the files in the repository.

```yaml
__default____:
__default__:
errors_ignored:
- <checkpatch option>
- <checkpatch option>
Expand Down
8 changes: 6 additions & 2 deletions checkpatch_hook/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@
logger = getLogger(__name__)
logger.setLevel(logging.INFO)

checkpatch_script_path = importlib.resources.files("checkpatch_hook.scripts").joinpath(
"checkpatch.pl"
)


def _parse_args() -> dict:
parser = argparse.ArgumentParser()
Expand Down Expand Up @@ -109,7 +113,7 @@ def pre_commit_hook(config_file: Path, commit_files: list[Path], fix_inplace: bo
config = config_file_obj.load_config()
logger.debug(f"Config file @ {config_file.resolve()}")

errors: DefaultDict[str, list] = defaultdict(lambda: [])
errors: DefaultDict[str, list] = defaultdict(list)
# accumulate checkpatch errors for each configured dir
for config_dir, dconfig in config["DIR_CONFIGS"].items():
# Special case for the default config
Expand Down Expand Up @@ -149,7 +153,7 @@ def _run_checkpatch(
max_line_length: int | str | None,
) -> None:
cmd = [
"checkpatch.pl",
str(checkpatch_script_path),
"--strict", # Be more annoying
"--no-tree", # No kernel source tree present
# Some stuff to make parsing easier
Expand Down
39 changes: 39 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
[project]
name = "checkpatch-hook"
dynamic = ["version"]
description = "Checkpatch Pre-Commit Hook"
authors = [
{name = "Blu Wireless Technology Ltd.", email = "[email protected]"}
]
readme = "README.md"
requires-python = ">=3.10"
dependencies = [
"pyyaml>=6.0.2",
]

[tool.uv]
dev-dependencies = [
"tox>=4.18.0",
"pytest>=8.3.2",
"coverage>=7.6.1",
"pytest-cov>=5.0.0",
]

[build-system]
requires = ["hatchling", "hatch-vcs"]
build-backend = "hatchling.build"

[tool.hatch.version]
source = "vcs"

[project.scripts]
checkpatch = "checkpatch_hook:main"

[tool.coverage.report]
exclude_also = [
"def __repr__",
"raise AssertionError",
"raise NotImplementedError",
"if __name__ == .__main__.:",
"@(abc\\.)?abstractmethod",
]
36 changes: 0 additions & 36 deletions setup.py

This file was deleted.