From 23926d002bcd0a926bcac21a3a87da19f5c6b234 Mon Sep 17 00:00:00 2001
From: jakkdl
Date: Sun, 17 Nov 2024 16:19:46 +0100
Subject: [PATCH 1/5] move changelog&version check to pre-commit and separate
CI job that skips on skip-release label
---
.github/workflows/ci.yml | 17 ++++++++++++++---
.pre-commit-config.yaml | 16 +++++++++++++++-
docs/changelog.rst | 2 +-
...ersion.py => check_changelog_and_version.py} | 3 +++
4 files changed, 33 insertions(+), 5 deletions(-)
rename tests/{test_changelog_and_version.py => check_changelog_and_version.py} (97%)
diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml
index 536433b..193eb47 100644
--- a/.github/workflows/ci.yml
+++ b/.github/workflows/ci.yml
@@ -62,10 +62,22 @@ jobs:
- name: Run tests
run: python -m tox -e flake8_7 -- --onlyfuzz --no-cov -n auto
+ check_release:
+ runs-on: ubuntu-latest
+ strategy:
+ fail-fast: false
+ if: ${{ ! contains(github.event.issue.labels.*.name, 'skip-release') }}
+ steps:
+ - uses: actions/checkout@v4
+ - name: Set up Python 3
+ uses: actions/setup-python@v5
+ - name: Test changelog & version python tests/test_changelog_and_version.py --ensure-tag
+ run: python3 tests/check_changelog_and_version.py
+
release:
runs-on: ubuntu-latest
- needs: [pyright, test]
- if: github.repository == 'python-trio/flake8-async' && github.ref == 'refs/heads/main'
+ needs: [pyright, test, check_release]
+ if: github.repository == 'python-trio/flake8-async' && github.ref == 'refs/heads/main'
steps:
- uses: actions/checkout@v4
- name: Set up Python 3
@@ -77,5 +89,4 @@ jobs:
TWINE_USERNAME: __token__
TWINE_PASSWORD: ${{ secrets.TWINE_PASSWORD }}
run: |
- python tests/test_changelog_and_version.py --ensure-tag
python -m build && twine upload --skip-existing dist/*
diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml
index 3ec7c04..971afa6 100644
--- a/.pre-commit-config.yaml
+++ b/.pre-commit-config.yaml
@@ -3,8 +3,9 @@ default_language_version:
python: python3.12
# pyright requires internet connection to run, which the pre-commit ci app doesn't have.
# it instead runs in a github action
+# check-relase-changelog is run in CI to be able to access PR labels
ci:
- skip: [pyright]
+ skip: [pyright, check-release-changelog]
repos:
- repo: https://github.com/astral-sh/ruff-pre-commit
@@ -100,3 +101,16 @@ repos:
rev: v1.0.0
hooks:
- id: sphinx-lint
+
+ - repo: local
+ hooks:
+ - id: check-release-changelog
+ name: check-release-changelog
+ language: system
+ entry: python3 tests/check_changelog_and_version.py
+ files: flake8_async/__init__.py|docs/changelog.rst
+
+ - repo: meta
+ hooks:
+ - id: check-hooks-apply
+ - id: check-useless-excludes
diff --git a/docs/changelog.rst b/docs/changelog.rst
index 12bbe51..8631102 100644
--- a/docs/changelog.rst
+++ b/docs/changelog.rst
@@ -4,7 +4,7 @@ Changelog
`CalVer, YY.month.patch `_
-24.10.2
+24.10.3
=======
- :ref:`ASYNC101 ` and :ref:`ASYNC119 ` are now silenced for decorators in :ref:`transform-async-generator-decorators`
- :ref:`ASYNC102 ` now also warns about ``await()`` inside ``__aexit__``.
diff --git a/tests/test_changelog_and_version.py b/tests/check_changelog_and_version.py
similarity index 97%
rename from tests/test_changelog_and_version.py
rename to tests/check_changelog_and_version.py
index 1d64676..a998279 100755
--- a/tests/test_changelog_and_version.py
+++ b/tests/check_changelog_and_version.py
@@ -112,6 +112,9 @@ def update_version() -> None:
if __name__ == "__main__":
+ test_last_release_against_changelog()
+ test_version_increments_are_correct()
+
update_version()
if "--ensure-tag" in sys.argv:
ensure_tagged()
From 2b00f8496c50647325c0d093bc82096e797cf4e1 Mon Sep 17 00:00:00 2001
From: jakkdl
Date: Sun, 17 Nov 2024 16:33:38 +0100
Subject: [PATCH 2/5] add --allow-future
---
.pre-commit-config.yaml | 2 +-
docs/changelog.rst | 7 +++++--
tests/check_changelog_and_version.py | 15 ++++++++++++---
3 files changed, 18 insertions(+), 6 deletions(-)
diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml
index 971afa6..e06117f 100644
--- a/.pre-commit-config.yaml
+++ b/.pre-commit-config.yaml
@@ -107,7 +107,7 @@ repos:
- id: check-release-changelog
name: check-release-changelog
language: system
- entry: python3 tests/check_changelog_and_version.py
+ entry: python3 tests/check_changelog_and_version.py --allow-future
files: flake8_async/__init__.py|docs/changelog.rst
- repo: meta
diff --git a/docs/changelog.rst b/docs/changelog.rst
index 8631102..6403b3c 100644
--- a/docs/changelog.rst
+++ b/docs/changelog.rst
@@ -4,9 +4,12 @@ Changelog
`CalVer, YY.month.patch `_
-24.10.3
-=======
+Future
+======
- :ref:`ASYNC101 ` and :ref:`ASYNC119 ` are now silenced for decorators in :ref:`transform-async-generator-decorators`
+
+24.10.2
+=======
- :ref:`ASYNC102 ` now also warns about ``await()`` inside ``__aexit__``.
24.10.1
diff --git a/tests/check_changelog_and_version.py b/tests/check_changelog_and_version.py
index a998279..cb606f9 100755
--- a/tests/check_changelog_and_version.py
+++ b/tests/check_changelog_and_version.py
@@ -16,6 +16,8 @@
README = ROOT_PATH / "README.md"
INIT_FILE = ROOT_PATH / "flake8_async" / "__init__.py"
+ALLOW_FUTURE = "--allow-future" in sys.argv
+
T = TypeVar("T", bound="Version")
@@ -44,6 +46,7 @@ def get_releases() -> Iterable[Version]:
valid_pattern = re.compile(r"^(\d\d\.\d?\d\.\d?\d)$")
header_pattern = re.compile(r"^=+$")
last_line_was_date = False
+ last_line: str | None = None
with open(CHANGELOG, encoding="utf-8") as f:
lines = f.readlines()
for line in lines:
@@ -54,9 +57,15 @@ def get_releases() -> Iterable[Version]:
elif version_match:
yield Version.from_string(version_match.group(1))
last_line_was_date = True
- else:
- # stop lines such as `Future\n=====` making it through to main/
- assert not header_pattern.match(line), line
+ # only allow `Future\n=====` when run in pre-commit
+ elif header_pattern.match(line):
+ assert ALLOW_FUTURE, (
+ "FUTURE header with no --allow-future. "
+ "If CI you maybe want the skip-release label."
+ )
+ assert last_line is not None
+ assert last_line.lower().strip() == "future"
+ last_line = line
def test_last_release_against_changelog() -> None:
From dca068a1d34cf15c2cc5bcaa4487a308e490a449 Mon Sep 17 00:00:00 2001
From: jakkdl
Date: Fri, 22 Nov 2024 16:43:12 +0100
Subject: [PATCH 3/5] don't use label
---
.github/workflows/ci.yml | 3 +--
.pre-commit-config.yaml | 4 ++--
tests/check_changelog_and_version.py | 7 ++-----
3 files changed, 5 insertions(+), 9 deletions(-)
diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml
index 193eb47..1bbff94 100644
--- a/.github/workflows/ci.yml
+++ b/.github/workflows/ci.yml
@@ -30,7 +30,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
- python-version: ['3.9', '3.10', '3.11', '3.12', 3.13]
+ python-version: ['3.9', '3.10', '3.11', '3.12', '3.13']
fail-fast: false
steps:
- uses: actions/checkout@v4
@@ -66,7 +66,6 @@ jobs:
runs-on: ubuntu-latest
strategy:
fail-fast: false
- if: ${{ ! contains(github.event.issue.labels.*.name, 'skip-release') }}
steps:
- uses: actions/checkout@v4
- name: Set up Python 3
diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml
index e06117f..af21205 100644
--- a/.pre-commit-config.yaml
+++ b/.pre-commit-config.yaml
@@ -3,7 +3,7 @@ default_language_version:
python: python3.12
# pyright requires internet connection to run, which the pre-commit ci app doesn't have.
# it instead runs in a github action
-# check-relase-changelog is run in CI to be able to access PR labels
+# check-release-changelog is run as a dedicated job
ci:
skip: [pyright, check-release-changelog]
@@ -107,7 +107,7 @@ repos:
- id: check-release-changelog
name: check-release-changelog
language: system
- entry: python3 tests/check_changelog_and_version.py --allow-future
+ entry: python3 tests/check_changelog_and_version.py --allow-future-in-changelog
files: flake8_async/__init__.py|docs/changelog.rst
- repo: meta
diff --git a/tests/check_changelog_and_version.py b/tests/check_changelog_and_version.py
index cb606f9..90e4121 100755
--- a/tests/check_changelog_and_version.py
+++ b/tests/check_changelog_and_version.py
@@ -16,7 +16,7 @@
README = ROOT_PATH / "README.md"
INIT_FILE = ROOT_PATH / "flake8_async" / "__init__.py"
-ALLOW_FUTURE = "--allow-future" in sys.argv
+ALLOW_FUTURE = "--allow-future-in-changelog" in sys.argv
T = TypeVar("T", bound="Version")
@@ -59,10 +59,7 @@ def get_releases() -> Iterable[Version]:
last_line_was_date = True
# only allow `Future\n=====` when run in pre-commit
elif header_pattern.match(line):
- assert ALLOW_FUTURE, (
- "FUTURE header with no --allow-future. "
- "If CI you maybe want the skip-release label."
- )
+ assert ALLOW_FUTURE, "FUTURE header with no --allow-future-in-changelog. "
assert last_line is not None
assert last_line.lower().strip() == "future"
last_line = line
From 25010acfb4a57dfb8021827abc4c780c726d38c7 Mon Sep 17 00:00:00 2001
From: jakkdl
Date: Mon, 25 Nov 2024 12:16:05 +0100
Subject: [PATCH 4/5] allow larger release in changelog, fix update_version
---
docs/usage.rst | 2 +-
tests/check_changelog_and_version.py | 21 ++++++++++++++-------
2 files changed, 15 insertions(+), 8 deletions(-)
diff --git a/docs/usage.rst b/docs/usage.rst
index 4ec19e1..5e813ac 100644
--- a/docs/usage.rst
+++ b/docs/usage.rst
@@ -33,7 +33,7 @@ adding the following to your ``.pre-commit-config.yaml``:
minimum_pre_commit_version: '2.9.0'
repos:
- repo: https://github.com/python-trio/flake8-async
- rev: 23.2.5
+ rev: 24.10.2
hooks:
- id: flake8-async
# args: [--enable=ASYNC, --disable=ASYNC9, --autofix=ASYNC]
diff --git a/tests/check_changelog_and_version.py b/tests/check_changelog_and_version.py
index 90e4121..ef3c706 100755
--- a/tests/check_changelog_and_version.py
+++ b/tests/check_changelog_and_version.py
@@ -13,7 +13,7 @@
ROOT_PATH = Path(__file__).parent.parent
CHANGELOG = ROOT_PATH / "docs" / "changelog.rst"
-README = ROOT_PATH / "README.md"
+USAGE = ROOT_PATH / "docs" / "usage.rst"
INIT_FILE = ROOT_PATH / "flake8_async" / "__init__.py"
ALLOW_FUTURE = "--allow-future-in-changelog" in sys.argv
@@ -66,9 +66,12 @@ def get_releases() -> Iterable[Version]:
def test_last_release_against_changelog() -> None:
- """Ensure we have the latest version covered in 'changelog.rst'."""
+ """Ensure we have the latest version covered in 'changelog.rst'.
+
+ If changelog version is greater, the __init__ gets bumped in update_version().
+ """
latest_release = next(iter(get_releases()))
- assert latest_release == VERSION
+ assert latest_release >= VERSION, f"{latest_release}, {VERSION}"
def test_version_increments_are_correct() -> None:
@@ -104,17 +107,21 @@ def update_version() -> None:
INIT_FILE = ROOT_PATH / "flake8_async" / "__init__.py"
subs = (f'__version__ = "{VERSION}"', f'__version__ = "{last_version}"')
INIT_FILE.write_text(INIT_FILE.read_text().replace(*subs))
+ print("updated VERSION in __init__.py")
# Similarly, update the pre-commit config example in the README
- current = README.read_text()
+ current = USAGE.read_text()
wanted = re.sub(
- pattern=r"^ rev: (\d+\.\d+\.\d+)$",
- repl=f" rev: {last_version}",
+ pattern=r"^ rev: (\d+\.\d+\.\d+)$",
+ repl=f" rev: {last_version}",
string=current,
flags=re.MULTILINE,
)
+ if last_version != VERSION:
+ assert current != wanted, "version changed but regex didn't substitute"
if current != wanted:
- README.write_text(wanted)
+ USAGE.write_text(wanted)
+ print("updated rev in pre-commit example")
if __name__ == "__main__":
From 077f54e04b3e092e1f2d4c95c652b2be02c6d604 Mon Sep 17 00:00:00 2001
From: jakkdl
Date: Wed, 27 Nov 2024 15:20:18 +0100
Subject: [PATCH 5/5] fix job name
---
.github/workflows/ci.yml | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml
index 1bbff94..8b3ddcf 100644
--- a/.github/workflows/ci.yml
+++ b/.github/workflows/ci.yml
@@ -70,8 +70,8 @@ jobs:
- uses: actions/checkout@v4
- name: Set up Python 3
uses: actions/setup-python@v5
- - name: Test changelog & version python tests/test_changelog_and_version.py --ensure-tag
- run: python3 tests/check_changelog_and_version.py
+ - name: Test changelog & version
+ run: python tests/check_changelog_and_version.py
release:
runs-on: ubuntu-latest