diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 01859fc..6853071 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -1,4 +1,4 @@ -name: Python application +name: Run Python Tests and Pre-Commit Hooks on: push: @@ -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 diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index b008630..205ae84 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -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: diff --git a/.version b/.version deleted file mode 100644 index 3eefcb9..0000000 --- a/.version +++ /dev/null @@ -1 +0,0 @@ -1.0.0 diff --git a/README.md b/README.md index 01adb27..7d81c9d 100644 --- a/README.md +++ b/README.md @@ -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: - - diff --git a/checkpatch_hook/__init__.py b/checkpatch_hook/__init__.py index 0c18349..d7b0529 100755 --- a/checkpatch_hook/__init__.py +++ b/checkpatch_hook/__init__.py @@ -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() @@ -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 @@ -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 diff --git a/pyproject.toml b/pyproject.toml new file mode 100644 index 0000000..df93973 --- /dev/null +++ b/pyproject.toml @@ -0,0 +1,39 @@ +[project] +name = "checkpatch-hook" +dynamic = ["version"] +description = "Checkpatch Pre-Commit Hook" +authors = [ + {name = "Blu Wireless Technology Ltd.", email = "info@bluwireless.com"} +] +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", +] diff --git a/setup.py b/setup.py deleted file mode 100644 index 2a18c34..0000000 --- a/setup.py +++ /dev/null @@ -1,36 +0,0 @@ -from pathlib import Path - -from setuptools import find_packages, setup - -_version_file_path = Path(__file__).parent.resolve() / ".version" -with _version_file_path.open("r") as file: - _version = file.read().strip() - - -setup( - name="check-commit-hook", - version=_version, - entry_points={ - "console_scripts": [ - "checkpatch=checkpatch_hook:main", - ], - }, - install_requires=[ - "pyyaml", - ], - # These should be bundled together - scripts=[ - "checkpatch_hook/scripts/checkpatch.pl", - "checkpatch_hook/data/const_structs.checkpatch", - "checkpatch_hook/data/spelling.txt", - ".version", - ], - package_data={ - "checkpatch_hook": [ - "data/checkpatch.yaml", - ], - }, - packages=find_packages(), - description="BWT check commit hooks", - python_requires=">=3.10", -)