Skip to content

Commit

Permalink
docs: Update changelog to address mdformat issues (#137)
Browse files Browse the repository at this point in the history
* docs: Update changelog to address mdformat issues.

Also added pylint as an additional check for python coding standards and errors.

* ci: Skip running pylint in pre-commit.ci since it isn't available
  • Loading branch information
nfelt14 authored Oct 4, 2024
1 parent ed405fe commit cee71b6
Show file tree
Hide file tree
Showing 10 changed files with 119 additions and 32 deletions.
17 changes: 15 additions & 2 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,13 @@ default_stages: [pre-commit]
ci:
autofix_prs: false
autoupdate_schedule: weekly
skip: [check-poetry, pyright, poetry-audit, markdown-link-check]
autoupdate_commit_msg: 'chore(pre-commit-deps): pre-commit autoupdate'
skip:
- check-poetry
- pylint
- pyright
- poetry-audit
- markdown-link-check
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: 2c9f875913ee60ca25ce70243dc24d5b6415598c # frozen: v4.6.0
Expand Down Expand Up @@ -60,7 +66,7 @@ repos:
hooks:
- id: blacken-docs
files: \.(rst|md|markdown|tex)$
additional_dependencies: [black==24.4.2] # This may need to be updated/removed in the future once ruff supports formatting Python code blocks in markdown
additional_dependencies: [black==24.8.0] # This may need to be updated/removed in the future once ruff supports formatting Python code blocks in markdown
args: [--line-length=100]
- repo: https://github.com/lyz-code/yamlfix
rev: 8072181c0f2eab9f2dd8db2eb3b9556d7cd0bd74 # frozen: 1.17.0
Expand Down Expand Up @@ -107,6 +113,13 @@ repos:
- id: toml-sort-fix
- repo: local
hooks:
- id: pylint
name: pylint
entry: pylint
language: system
types: [python]
pass_filenames: true
args: [-sn]
- id: pyright
name: pyright
entry: pyright
Expand Down
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ Things to be included in the next release go here.
- chore(python-deps): update dependency pyright to v1.1.382.post1 for dev ([#132](https://github.com/tektronix/python-package-ci-cd/pull/132))
- chore(docker-deps): update python:3.12-alpine docker digest to e75de17 in all dependant actions ([#130](https://github.com/tektronix/python-package-ci-cd/pull/130))
- chore(docker-deps): update python:3.12-alpine docker digest to 6666ea3 in all dependant actions ([#129](https://github.com/tektronix/python-package-ci-cd/pull/129))
- [pre-commit.ci] pre-commit autoupdate ([#117](https://github.com/tektronix/python-package-ci-cd/pull/117))
- chore(pre-commit-deps): pre-commit autoupdate ([#117](https://github.com/tektronix/python-package-ci-cd/pull/117))
- chore(python-deps): update dependency pyright to v1.1.382.post0 for dev ([#125](https://github.com/tektronix/python-package-ci-cd/pull/125))
- chore(python-deps): update dependency pyright to v1.1.382 for dev ([#124](https://github.com/tektronix/python-package-ci-cd/pull/124))
- chore(gh-actions-deps): update github/codeql-action action to v3.26.9 in all dependant reusable workflows ([#123](https://github.com/tektronix/python-package-ci-cd/pull/123))
Expand Down
2 changes: 1 addition & 1 deletion actions/create_unique_testpypi_version/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ def main() -> None:
tomli_w.dump(pyproject_data, file_handle)

# Set the output variable for GitHub Actions
with open(os.environ["GITHUB_OUTPUT"], "a") as github_output_file_handle: # noqa: PTH123
with open(os.environ["GITHUB_OUTPUT"], "a", encoding="utf-8") as github_output_file_handle: # noqa: PTH123
github_output_file_handle.write(f"new-version={updated_version}\n")


Expand Down
4 changes: 2 additions & 2 deletions actions/find_unreleased_changelog_items/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ def get_commit_messages(since_tag: str | None = None) -> list[str]:
return run_cmd_in_subprocess(f"git log {range_spec} --pretty=format:%s").splitlines()


def main() -> None:
def main() -> None: # pylint: disable=too-many-locals
"""Check for entries in the Unreleased section of the CHANGELOG.md file.
Raises:
Expand Down Expand Up @@ -137,7 +137,7 @@ def main() -> None:
print(
f"\nAdding the following contents to the GitHub Workflow Summary:\n\n{summary_contents}"
)
with open(os.environ["GITHUB_STEP_SUMMARY"], "a") as summary_file: # noqa: PTH123
with open(os.environ["GITHUB_STEP_SUMMARY"], "a", encoding="utf-8") as summary_file: # noqa: PTH123
summary_file.write(summary_contents)


Expand Down
73 changes: 73 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ poetry-audit-plugin = "^0.4.0"
poetry-plugin-export = "1.8.0"
poetry-pre-commit-plugin = "^0.1.2"
pre-commit = "3.8.0"
pylint = "3.3.1"
pyright = "1.1.383"
tox = "^4.18.0"
tox-gh-actions = "^3.2.0"
Expand Down Expand Up @@ -83,6 +84,78 @@ pytest-html = "^4.1.1"
pytest-order = "^1.2.1"
pytest-subprocess = "^1.5.2"

[tool.pylint.main]
fail-under = 10.0
ignore-patterns = [
"^\\.#",
"^\\..*_cache",
"^\\.docs.*",
"^\\.env.*",
"^\\.idea",
"^\\.results.*",
"^\\.tox",
"^\\.venv.*",
"^\\.vscode",
"^temp_.*\\..*"
]
init-hook = 'import sys; sys.path.append(".")'
jobs = 0
load-plugins = """
pylint.extensions.check_elif,
pylint.extensions.code_style,
pylint.extensions.comparison_placement,
pylint.extensions.consider_refactoring_into_while_condition,
pylint.extensions.dict_init_mutate,
pylint.extensions.docparams,
pylint.extensions.docstyle,
pylint.extensions.dunder,
pylint.extensions.eq_without_hash,
pylint.extensions.for_any_all,
pylint.extensions.no_self_use,
pylint.extensions.overlapping_exceptions,
pylint.extensions.private_import,
pylint.extensions.set_membership,
pylint.extensions.typing,
pylint.extensions.while_used
"""
recursive = true

[tool.pylint."messages control"]
disable = [
"broad-exception-caught", # caught by ruff
"fixme", # caught by ruff
"global-statement", # caught by ruff
"invalid-name", # caught by ruff
"line-too-long", # caught by ruff
"locally-disabled", # allowed
"missing-class-docstring", # caught by ruff
"missing-module-docstring", # caught by ruff
"no-member", # caught by pyright
"protected-access", # caught by ruff
"raise-missing-from", # caught by ruff
"redefined-builtin", # caught by ruff
"suppressed-message", # allowed
"too-many-arguments", # caught by ruff
"too-many-branches", # caught by ruff
"too-many-statements", # caught by ruff
"too-many-statements", # caught by ruff
"unused-argument", # caught by ruff
"unused-import", # caught by ruff
"use-implicit-booleaness-not-comparison-to-string", # caught by ruff
"wrong-import-order" # caught by ruff
]
enable = ["all"]

[tool.pylint.reports]
# Python expression which should return a score less than or equal to 10. You
# have access to the variables 'fatal', 'error', 'warning', 'refactor',
# 'convention', and 'info' which contain the number of messages in each category,
# as well as 'statement' which is the total number of statements analyzed. This
# score is used by the global evaluation report (RP0004).
evaluation = "max(0, 0 if fatal else 10.0 - ((float(5 * error + warning + refactor + convention + info) / statement) * 10))"
output-format = "text" # colorized could be another option
score = true

[tool.pyright]
ignore = [
"temp_*.py"
Expand Down
8 changes: 4 additions & 4 deletions tests/test_bump_version_in_files.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
"""Test the bump_version_in_files module."""

from collections.abc import Generator
from pathlib import Path
from typing import Generator
from unittest.mock import MagicMock, patch

import pytest
Expand All @@ -10,14 +10,14 @@


@pytest.fixture(autouse=True)
def mock_subprocess_check_call() -> Generator[None, None, None]:
def mock_subprocess_check_call() -> Generator[None]:
"""Mock subprocess.check_call for all tests."""
with patch("subprocess.check_call", MagicMock(return_value=None)):
yield


@pytest.fixture()
def temporary_directory(tmp_path: Path) -> Path:
@pytest.fixture(name="temporary_directory")
def fixture_temporary_directory(tmp_path: Path) -> Path:
"""Create a temporary directory."""
# Create a temporary directory with some files
test_dir = tmp_path / "test_dir"
Expand Down
15 changes: 8 additions & 7 deletions tests/test_create_unique_testpypi_version.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

from __future__ import annotations

from typing import Generator, TYPE_CHECKING
from typing import TYPE_CHECKING
from unittest.mock import MagicMock, patch

import pytest
Expand All @@ -12,6 +12,7 @@
from actions.create_unique_testpypi_version.main import create_new_post_version, main

if TYPE_CHECKING:
from collections.abc import Generator
from pathlib import Path

# Sample data for mocking
Expand All @@ -32,8 +33,8 @@ def _mock_environment(monkeypatch: pytest.MonkeyPatch) -> None: # pyright: igno
monkeypatch.setenv("INPUT_PACKAGE-NAME", PACKAGE_NAME)


@pytest.fixture()
def mock_testpypi_server() -> Generator[MagicMock, None, None]:
@pytest.fixture(name="mock_testpypi_server")
def fixture_mock_testpypi_server() -> Generator[MagicMock]:
"""Mock the PyPISimple class and its methods."""
with patch("actions.create_unique_testpypi_version.main.PyPISimple") as mock_pypi_simple:
mock_server = mock_pypi_simple.return_value
Expand All @@ -43,8 +44,8 @@ def mock_testpypi_server() -> Generator[MagicMock, None, None]:
yield mock_server


@pytest.fixture()
def mock_pyproject_file(tmp_path: Path, monkeypatch: pytest.MonkeyPatch) -> Path:
@pytest.fixture(name="mock_pyproject_file")
def fixture_mock_pyproject_file(tmp_path: Path, monkeypatch: pytest.MonkeyPatch) -> Path:
"""Mock the pyproject.toml file.
Args:
Expand All @@ -63,8 +64,8 @@ def mock_pyproject_file(tmp_path: Path, monkeypatch: pytest.MonkeyPatch) -> Path
return pyproject_file


@pytest.fixture()
def mock_github_output_file(tmp_path: Path, monkeypatch: pytest.MonkeyPatch) -> Path:
@pytest.fixture(name="mock_github_output_file")
def fixture_mock_github_output_file(tmp_path: Path, monkeypatch: pytest.MonkeyPatch) -> Path:
"""Mock the GitHub output file.
Args:
Expand Down
6 changes: 3 additions & 3 deletions tests/test_docs.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,17 @@
import sys
import time

from collections.abc import Generator
from importlib.util import find_spec
from pathlib import Path
from typing import Generator

import pytest

REPO_ROOT_DIR = Path(__file__).resolve().parent.parent


@pytest.fixture(name="docs_server")
def fixture_docs_server(site_dir: str) -> Generator[str, None, None]:
def fixture_docs_server(site_dir: str) -> Generator[str]:
"""Serve the documentation site."""
port = f"8{sys.version_info.major}{sys.version_info.minor}"
cmd = [sys.executable, "-m", "http.server", port, "--directory", site_dir]
Expand Down Expand Up @@ -49,7 +49,7 @@ def fixture_site_dir(pytestconfig: pytest.Config) -> str:


@pytest.fixture(scope="module", autouse=True)
def _docs_tests_setup() -> Generator[None, None, None]: # pyright: ignore [reportUnusedFunction]
def _docs_tests_setup() -> Generator[None]: # pyright: ignore [reportUnusedFunction]
"""Setup for docs tests.."""
starting_directory = Path.cwd()
try:
Expand Down
16 changes: 8 additions & 8 deletions tests/test_find_unreleased_changelog_items.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@
MOCK_TEMPLATES_FOLDER = "mock_templates"


@pytest.fixture()
def mock_previous_files(tmp_path: Path) -> tuple[Path, Path]:
@pytest.fixture(name="mock_previous_files")
def fixture_mock_previous_files(tmp_path: Path) -> tuple[Path, Path]:
"""Create filepaths in the temporary directory for the template files.
Args:
Expand All @@ -40,8 +40,8 @@ def mock_previous_files(tmp_path: Path) -> tuple[Path, Path]:
)


@pytest.fixture()
def mock_changelog_file(monkeypatch: pytest.MonkeyPatch, tmp_path: Path) -> Path:
@pytest.fixture(name="mock_changelog_file")
def fixture_mock_changelog_file(monkeypatch: pytest.MonkeyPatch, tmp_path: Path) -> Path:
"""Mock the pyproject.toml file.
Args:
Expand All @@ -63,8 +63,8 @@ def mock_changelog_file(monkeypatch: pytest.MonkeyPatch, tmp_path: Path) -> Path
return mock_path


@pytest.fixture()
def summary_file(tmp_path: Path) -> Path:
@pytest.fixture(name="summary_file")
def fixture_summary_file(tmp_path: Path) -> Path:
"""Create a summary file for the GitHub Actions step.
Args:
Expand All @@ -76,8 +76,8 @@ def summary_file(tmp_path: Path) -> Path:
return tmp_path / "github_summary.txt"


@pytest.fixture()
def mock_env_vars(
@pytest.fixture(name="mock_env_vars")
def fixture_mock_env_vars(
tmp_path: Path,
monkeypatch: pytest.MonkeyPatch,
summary_file: Path,
Expand Down
8 changes: 4 additions & 4 deletions tests/test_update_development_dependencies.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

import sys

from collections.abc import Generator
from pathlib import Path
from typing import Generator
from unittest.mock import call, MagicMock, patch

import pytest
Expand All @@ -21,7 +21,7 @@


@pytest.fixture(autouse=True)
def mock_pypi_server() -> Generator[MagicMock, None, None]:
def mock_pypi_server() -> Generator[MagicMock]:
"""Mock the PyPISimple class and its methods."""
with patch("actions.update_development_dependencies.main.PyPISimple") as mock_pypi_simple:
mock_server = mock_pypi_simple.return_value
Expand All @@ -31,8 +31,8 @@ def mock_pypi_server() -> Generator[MagicMock, None, None]:
yield mock_server


@pytest.fixture()
def repo_root_dir(
@pytest.fixture(name="repo_root_dir")
def fixture_repo_root_dir(
monkeypatch: pytest.MonkeyPatch,
tmp_path: Path,
) -> Path:
Expand Down

0 comments on commit cee71b6

Please sign in to comment.