diff --git a/.github/CONTRIBUTING.md b/.github/CONTRIBUTING.md index c5028c2..b1c9597 100644 --- a/.github/CONTRIBUTING.md +++ b/.github/CONTRIBUTING.md @@ -43,7 +43,7 @@ When you're ready to contribute code to address an open issue, please follow the git clone https://github.com/USERNAME/python-package-template.git - or + or git clone git@github.com:USERNAME/python-package-template.git diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml new file mode 100644 index 0000000..012f302 --- /dev/null +++ b/.pre-commit-config.yaml @@ -0,0 +1,60 @@ +ci: + autoupdate_commit_msg: "chore: update pre-commit hooks" + autofix_commit_msg: "style: pre-commit fixes" + +repos: + - repo: https://github.com/pre-commit/pre-commit-hooks + rev: v4.1.0 + hooks: + - id: check-added-large-files + - id: check-case-conflict + - id: check-merge-conflict + - id: check-symlinks + - id: check-yaml + - id: debug-statements + - id: end-of-file-fixer + - id: mixed-line-ending + - id: requirements-txt-fixer + - id: trailing-whitespace + + - repo: https://github.com/PyCQA/isort + rev: 5.12.0 + hooks: + - id: isort + args: ["-a", "from __future__ import annotations"] + + - repo: https://github.com/asottile/pyupgrade + rev: v2.31.0 + hooks: + - id: pyupgrade + args: [--py37-plus] + + - repo: https://github.com/hadialqattan/pycln + rev: v1.2.5 + hooks: + - id: pycln + args: [--config=pyproject.toml] + stages: [manual] + + - repo: https://github.com/codespell-project/codespell + rev: v2.1.0 + hooks: + - id: codespell + + - repo: https://github.com/pre-commit/pygrep-hooks + rev: v1.9.0 + hooks: + - id: python-check-blanket-noqa + - id: python-check-blanket-type-ignore + - id: python-no-log-warn + - id: python-no-eval + - id: python-use-type-annotations + - id: rst-backticks + - id: rst-directive-colons + - id: rst-inline-touching-normal + + - repo: https://github.com/mgedmin/check-manifest + rev: "0.47" + hooks: + - id: check-manifest + stages: [manual] diff --git a/.readthedocs.yaml b/.readthedocs.yaml index f2e380b..ac457e9 100644 --- a/.readthedocs.yaml +++ b/.readthedocs.yaml @@ -11,4 +11,3 @@ python: path: . extra_requirements: - dev - diff --git a/docs/source/conf.py b/docs/source/conf.py index e574055..2fab8ca 100644 --- a/docs/source/conf.py +++ b/docs/source/conf.py @@ -4,6 +4,8 @@ # list see the documentation: # https://www.sphinx-doc.org/en/master/usage/configuration.html +from __future__ import annotations + import logging import os import sys diff --git a/docs/source/overview.md b/docs/source/overview.md index d8d63b4..802d341 100644 --- a/docs/source/overview.md +++ b/docs/source/overview.md @@ -1,3 +1,2 @@ Overview ======== - diff --git a/gitops/commit-template.txt b/gitops/commit-template.txt new file mode 100644 index 0000000..5e251d0 --- /dev/null +++ b/gitops/commit-template.txt @@ -0,0 +1,4 @@ +[TYPE] Brief description of the change + +- Detailed explanation of the change +- Additional context or information if necessary diff --git a/gitops/commit_all.sh b/gitops/commit_all.sh new file mode 100644 index 0000000..6365d96 --- /dev/null +++ b/gitops/commit_all.sh @@ -0,0 +1,31 @@ +#!/bin/bash + +# Check if the current directory is a Git repository +if ! git rev-parse --is-inside-work-tree &>/dev/null; then + echo "Error: Not in a Git repository." + exit 1 +fi + +current_branch=$(git symbolic-ref --short HEAD) + +# Check if there are any changes to commit +if [[ -n $(git status -s) ]]; then + git fetch origin "$current_branch" + git pull origin "$current_branch" + + commit_template="./gitops/commit-template.txt" + + if [ -f "$commit_template" ]; then + git config commit.template "$commit_template" + git commit + git config --unset commit.template + git push origin "$current_branch" + + echo "Committed and pushed changes successfully." + else + echo "Commit template not found: $commit_template" + exit 1 + fi +else + echo "No changes to commit." +fi diff --git a/my_package/__init__.py b/my_package/__init__.py index b230225..ac02de7 100644 --- a/my_package/__init__.py +++ b/my_package/__init__.py @@ -1 +1,3 @@ +from __future__ import annotations + from .version import VERSION, VERSION_SHORT diff --git a/my_package/version.py b/my_package/version.py index 7c1aef3..bb400bb 100644 --- a/my_package/version.py +++ b/my_package/version.py @@ -1,3 +1,5 @@ +from __future__ import annotations + _MAJOR = "0" _MINOR = "1" # On main and in a nightly release the patch should be one ahead of the last @@ -7,5 +9,5 @@ # https://semver.org/#is-v123-a-semantic-version for the semantics. _SUFFIX = "" -VERSION_SHORT = "{0}.{1}".format(_MAJOR, _MINOR) -VERSION = "{0}.{1}.{2}{3}".format(_MAJOR, _MINOR, _PATCH, _SUFFIX) +VERSION_SHORT = f"{_MAJOR}.{_MINOR}" +VERSION = f"{_MAJOR}.{_MINOR}.{_PATCH}{_SUFFIX}" diff --git a/scripts/personalize.py b/scripts/personalize.py index 9f5a4b5..8d1e2c8 100644 --- a/scripts/personalize.py +++ b/scripts/personalize.py @@ -5,6 +5,8 @@ This script is interactive and will prompt you for various inputs. """ +from __future__ import annotations + import sys from pathlib import Path from typing import Generator, List, Tuple @@ -157,7 +159,7 @@ def iterfiles(dir: Path) -> Generator[Path, None, None]: yield path -def personalize_file(path: Path, dry_run: bool, replacements: List[Tuple[str, str]]): +def personalize_file(path: Path, dry_run: bool, replacements: list[tuple[str, str]]): with path.open(mode="r+t", encoding="utf-8") as file: filedata = file.read() diff --git a/scripts/prepare_changelog.py b/scripts/prepare_changelog.py index 083eeda..64a3616 100644 --- a/scripts/prepare_changelog.py +++ b/scripts/prepare_changelog.py @@ -1,3 +1,5 @@ +from __future__ import annotations + from datetime import datetime from pathlib import Path diff --git a/scripts/release_notes.py b/scripts/release_notes.py index 8ca99a9..3f3cdf4 100755 --- a/scripts/release_notes.py +++ b/scripts/release_notes.py @@ -1,9 +1,9 @@ -# encoding: utf-8 - """ Prepares markdown release notes for GitHub releases. """ +from __future__ import annotations + import os from typing import List, Optional @@ -19,7 +19,7 @@ def get_change_log_notes() -> str: in_current_section = False - current_section_notes: List[str] = [] + current_section_notes: list[str] = [] with open("CHANGELOG.md") as changelog: for line in changelog: if line.startswith("## "): @@ -55,7 +55,7 @@ def get_commit_history() -> str: # Out of `all_tags`, find the latest previous version so that we can collect all # commits between that version and the new version we're about to publish. # Note that we ignore pre-releases unless the new version is also a pre-release. - last_tag: Optional[str] = None + last_tag: str | None = None for tag in all_tags: if not tag.strip(): # could be blank line continue diff --git a/tests/hello_test.py b/tests/hello_test.py index 23b9253..ba29a4f 100644 --- a/tests/hello_test.py +++ b/tests/hello_test.py @@ -1,2 +1,5 @@ +from __future__ import annotations + + def test_hello(): print("Hello, World!")