Skip to content

Commit

Permalink
Lint, Py311
Browse files Browse the repository at this point in the history
  • Loading branch information
KyleJamesWalker committed Mar 25, 2024
1 parent b5d4c14 commit eef8715
Show file tree
Hide file tree
Showing 14 changed files with 144 additions and 50 deletions.
44 changes: 44 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
# See https://pre-commit.com for more information
# See https://pre-commit.com/hooks.html for more hooks
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.5.0
hooks:
- id: trailing-whitespace
exclude: .bumpversion.cfg

- id: end-of-file-fixer

- id: check-yaml
args: ['--unsafe']

- id: check-added-large-files

- id: no-commit-to-branch
args: ['--branch', 'main']

- repo: https://github.com/charliermarsh/ruff-pre-commit
rev: v0.2.2
hooks:
- id: ruff
args: ["--fix"]

- repo: https://github.com/psf/black
rev: 24.2.0
hooks:
- id: black

- repo: https://github.com/python-jsonschema/check-jsonschema
rev: 0.28.0
hooks:
- id: check-github-workflows

- repo: https://github.com/pycqa/isort
rev: 5.13.2
hooks:
- id: isort

- repo: https://github.com/KyleJamesWalker/pre-commit-hooks
rev: v0.0.4
hooks:
- id: todo
4 changes: 2 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM python:3.10-slim
FROM python:3.11-slim

RUN apt update && apt install -y \
curl \
Expand All @@ -15,7 +15,7 @@ RUN apt update && apt install -y \

WORKDIR /code

COPY setup.py setup.cfg /code/
COPY setup.py pyproject.toml /code/
RUN pip install -e "."
RUN pip check

Expand Down
1 change: 1 addition & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,5 @@ build:
docker-compose build app test

test:
mkdir reports
docker-compose run --rm test
2 changes: 0 additions & 2 deletions docker-compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@ services:
build:
context: .
dockerfile: Dockerfile.test
env_file:
- .env
volumes:
- ./pr_changes:/code/pr_changes
- ./reports:/code/reports
Expand Down
3 changes: 2 additions & 1 deletion pr_changes/__main__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
"""Entry point for the pr-changes-matrix-builder."""
from pr_changes import gh, action

from pr_changes import action, gh
from pr_changes.config import get_config


Expand Down
11 changes: 10 additions & 1 deletion pr_changes/action.py
Original file line number Diff line number Diff line change
@@ -1,22 +1,25 @@
"""PR Changes Primary Action Module."""

import fnmatch
import hashlib
import json
import os
import re
import sys

from typing import List, Dict
from pr_changes.config import get_config
from typing import Dict, List


def dict_hash(data: Dict) -> str:
"""Generate a hash of a dictionary.
Args:
----
d: Dictionary to hash.
Returns:
-------
Hash of the dictionary.
"""
Expand All @@ -27,9 +30,11 @@ def generate_matrix(changes: List[str]) -> Dict:
"""Generate the matrix of changes.
Args:
----
changes: List of changed files.
Returns:
-------
Fully populated matrix of changes with injected values.
"""
Expand Down Expand Up @@ -78,9 +83,11 @@ def include_file(fn: str) -> bool:
"""Check if the filename is an included match.
Args:
----
fn: Filename to check.
Returns:
-------
True if the file should be included.
"""
Expand All @@ -99,9 +106,11 @@ def ignore_file(fn: str) -> bool:
"""Check if the filename is an excluded match.
Args:
----
fn: Filename to check.
Returns:
-------
True if the file should be excluded.
"""
Expand Down
4 changes: 4 additions & 0 deletions pr_changes/config.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Configuration module."""

import yamlsettings

__CONFIG = None
Expand All @@ -10,9 +11,11 @@ def __validate__(cfg: yamlsettings.yamldict.YAMLDict):
Asserts if a value in the required_keys paths is not defined
Args:
----
cfg: Configuration Settings
Raises:
------
RuntimeError: When a required key is null
"""
Expand All @@ -31,6 +34,7 @@ def __process_config__(cfg: yamlsettings.yamldict.YAMLDict):
"""Process the configuration.
Args:
----
cfg: Configuration Settings
"""
Expand Down
1 change: 1 addition & 0 deletions pr_changes/gh.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Handle all the Github CLI Class."""

import subprocess
import sys

Expand Down
75 changes: 74 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,79 @@ exclude = '''
| \.git # root of the project
| \.hg
| \.mypy_cache
)
| \.tox
| \.venv
| _build
| buck-out
| build
| dist
)/
| foo.py # also separately exclude a file named foo.py in
# the root of the project
)
'''

[tool.ruff]
lint.extend-select = ["D"]
lint.extend-ignore = [
"D107",
"D203",
"D212",
"D213",
"D400",
"D402",
"D413",
"D415",
"D416",
"D417",
]

# Same as Black.
line-length = 88

# Assume Python 3.11.
target-version = "py311"

[tool.ruff.lint.mccabe]
max-complexity = 20

[tool.isort]
skip = [".gitignore", ".dockerignore", ".venv"]
no_sections = true
lines_between_types = 1
multi_line_output = 3
include_trailing_comma = true
use_parentheses = true
ensure_newline_before_comments = true
line_length = 88
profile = "black"

[tool.coverage.report]
# Regexes for lines to exclude from consideration
exclude_lines = [
# re-enable the standard pragma
"pragma: no cover",
# Don't complain about missing debug-only code:
"def __repr__",
# Don't complain if tests don't hit defensive assertion code:
"raise NotImplementedError",
# Don't complain if non-runnable code isn't run:
"if __name__ == .__main__.:",
]

[tool.coverage.run]
relative_files = true
data_file = "reports/.coverage"

[tool.pytest.ini_options]
minversion = "6.0"
addopts = [
"--cov-config=pyproject.toml",
"--cov-report=xml:reports/coverage.xml",
"--junitxml=reports/results.xml",
"--cov-report=term-missing",
"--cov=pr_changes",
]
testpaths = [
"tests",
]
37 changes: 0 additions & 37 deletions setup.cfg

This file was deleted.

7 changes: 2 additions & 5 deletions setup.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Package setup"""

from setuptools import find_packages, setup

requirements = [
Expand All @@ -7,11 +8,7 @@

extras_require = {
"test": [
"flake8<4",
"flake8-docstrings==1.6.0",
"pytest==6.2.5",
"pytest-black==0.3.12",
"pytest-flake8==1.0.7",
"pytest-cov==3.0.0",
"pytest-xdist==2.5.0",
"pook==1.0.2",
Expand All @@ -27,7 +24,7 @@

setup(
name="pr_changes",
version="0.0.1",
version="0.0.2",
author="KyleJamesWalker",
description="Build a matrix from a PR",
packages=find_packages(),
Expand Down
3 changes: 2 additions & 1 deletion tests/conftest.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""Pytest conftest file."""
import pytest

import pr_changes.config
import pytest
import yamlsettings


Expand Down
1 change: 1 addition & 0 deletions tests/test_action.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Test Action."""

from pr_changes.action import generate_matrix


Expand Down
1 change: 1 addition & 0 deletions tests/test_config.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Test Configuration."""

import pytest

from pr_changes.config import get_config
Expand Down

0 comments on commit eef8715

Please sign in to comment.