From 984c4d21f8c7a74ce44c3c0b832859ac7de12e1b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miro=20Hron=C4=8Dok?= Date: Mon, 22 Jul 2024 10:58:55 +0200 Subject: [PATCH 01/10] Allow running blurb test from blurb-* directories Fixes https://github.com/python/blurb/issues/21 --- src/blurb/blurb.py | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/src/blurb/blurb.py b/src/blurb/blurb.py index 4930bb4..d54a950 100755 --- a/src/blurb/blurb.py +++ b/src/blurb/blurb.py @@ -642,7 +642,7 @@ def save_next(self): tests_run = 0 class TestParserPasses(unittest.TestCase): - directory = "blurb/tests/pass" + directory = "tests/pass" def filename_test(self, filename): b = Blurbs() @@ -667,7 +667,7 @@ def test_files(self): class TestParserFailures(TestParserPasses): - directory = "blurb/tests/fail" + directory = "tests/fail" def filename_test(self, filename): b = Blurbs() @@ -820,6 +820,15 @@ def help(subcommand=None): subcommands["--help"] = help +def _find_blurb_dir(): + if os.path.isdir("blurb"): + return "blurb" + for path in glob.iglob("blurb-*"): + if os.path.isdir(path): + return path + return None + + @subcommand def test(*args): """ @@ -828,12 +837,13 @@ def test(*args): # unittest.main doesn't work because this isn't a module # so we'll do it ourselves - while not os.path.isdir("blurb"): + while (blurb_dir := _find_blurb_dir()) is None: old_dir = os.getcwd() os.chdir("..") if old_dir == os.getcwd(): # we reached the root and never found it! sys.exit("Error: Couldn't find the root of your blurb repo!") + os.chdir(blurb_dir) print("-" * 79) From 95bdb6be08f4e1a3f194f08b958428f88500c371 Mon Sep 17 00:00:00 2001 From: Hugo van Kemenade <1324225+hugovk@users.noreply.github.com> Date: Mon, 23 Sep 2024 11:23:57 -0700 Subject: [PATCH 02/10] Drop support for Python 3.8 --- .github/workflows/test.yml | 2 +- README.md | 2 -- pyproject.toml | 3 +-- tox.ini | 2 +- 4 files changed, 3 insertions(+), 6 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 388811d..ff31dc6 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -11,7 +11,7 @@ jobs: strategy: fail-fast: false matrix: - python-version: ["3.8", "3.9", "3.10", "3.11", "3.12", "3.13"] + python-version: ["3.9", "3.10", "3.11", "3.12", "3.13"] steps: - uses: actions/checkout@v4 diff --git a/README.md b/README.md index d477343..c5e6abc 100644 --- a/README.md +++ b/README.md @@ -26,8 +26,6 @@ and automatically uses the correct file paths. You can install **blurb** from PyPI using `pip`. Alternatively, simply add `blurb` to a directory on your path. -**blurb**'s only dependency is Python 3.8+. - ## Files used by blurb diff --git a/pyproject.toml b/pyproject.toml index 0843f61..cad458f 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -15,12 +15,11 @@ maintainers = [ authors = [ { name = "Larry Hastings", email = "larry@hastings.org" }, ] -requires-python = ">=3.8" +requires-python = ">=3.9" classifiers = [ "Intended Audience :: Developers", "License :: OSI Approved :: BSD License", "Programming Language :: Python :: 3 :: Only", - "Programming Language :: Python :: 3.8", "Programming Language :: Python :: 3.9", "Programming Language :: Python :: 3.10", "Programming Language :: Python :: 3.11", diff --git a/tox.ini b/tox.ini index 793f226..4956937 100644 --- a/tox.ini +++ b/tox.ini @@ -2,7 +2,7 @@ requires = tox>=4.2 env_list = - py{313, 312, 311, 310, 39, 38} + py{313, 312, 311, 310, 39} [testenv] extras = From 6ed4c79ba187d8ee56b4d57594540fbc0bbab1da Mon Sep 17 00:00:00 2001 From: Hugo van Kemenade <1324225+hugovk@users.noreply.github.com> Date: Fri, 27 Sep 2024 14:41:36 -0700 Subject: [PATCH 03/10] Generate digital attestations for PyPI (PEP 740) --- .github/workflows/release.yml | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index befd5af..4c6267e 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -11,6 +11,9 @@ on: permissions: contents: read +env: + FORCE_COLOR: 1 + jobs: # Always build & lint package. build-package: @@ -47,6 +50,7 @@ jobs: - name: Publish to Test PyPI uses: pypa/gh-action-pypi-publish@release/v1 with: + attestations: true repository-url: https://test.pypi.org/legacy/ # Publish to PyPI on GitHub Releases. @@ -78,3 +82,5 @@ jobs: - name: Publish to PyPI uses: pypa/gh-action-pypi-publish@release/v1 + with: + attestations: true From 0615781b61af502e9e97e7eb0596702412b927a6 Mon Sep 17 00:00:00 2001 From: Hugo van Kemenade <1324225+hugovk@users.noreply.github.com> Date: Fri, 27 Sep 2024 14:44:25 -0700 Subject: [PATCH 04/10] Add more linting --- .pre-commit-config.yaml | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index a8986c4..c076739 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -2,26 +2,39 @@ repos: - repo: https://github.com/pre-commit/pre-commit-hooks rev: v4.6.0 hooks: + - id: check-added-large-files - id: check-case-conflict - id: check-merge-conflict - id: check-toml - id: check-yaml - id: debug-statements - id: end-of-file-fixer + - id: forbid-submodules - id: trailing-whitespace + - repo: https://github.com/python-jsonschema/check-jsonschema + rev: 0.29.2 + hooks: + - id: check-dependabot + - id: check-github-workflows + + - repo: https://github.com/rhysd/actionlint + rev: v1.7.2 + hooks: + - id: actionlint + - repo: https://github.com/tox-dev/pyproject-fmt - rev: 2.1.3 + rev: 2.2.4 hooks: - id: pyproject-fmt - repo: https://github.com/abravalheri/validate-pyproject - rev: v0.18 + rev: v0.20.2 hooks: - id: validate-pyproject - repo: https://github.com/tox-dev/tox-ini-fmt - rev: 1.3.1 + rev: 1.4.1 hooks: - id: tox-ini-fmt From 83199ea32f9d365be2ed812f263cb3a29499af81 Mon Sep 17 00:00:00 2001 From: Hugo van Kemenade <1324225+hugovk@users.noreply.github.com> Date: Fri, 27 Sep 2024 15:27:23 -0700 Subject: [PATCH 05/10] Restrict permissions --- .github/workflows/test.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index ff31dc6..276a00b 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -2,6 +2,9 @@ name: Test on: [push, pull_request, workflow_dispatch] +permissions: + contents: read + env: FORCE_COLOR: 1 From 97049c2b358dd57529a30ada92851e28886b1ab7 Mon Sep 17 00:00:00 2001 From: Hugo van Kemenade <1324225+hugovk@users.noreply.github.com> Date: Fri, 11 Oct 2024 10:52:45 +0300 Subject: [PATCH 06/10] Add version subcommand --- src/blurb/blurb.py | 13 ++++++++++++- tox.ini | 2 ++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/src/blurb/blurb.py b/src/blurb/blurb.py index 4930bb4..27c3e3d 100755 --- a/src/blurb/blurb.py +++ b/src/blurb/blurb.py @@ -742,6 +742,15 @@ def get_subcommand(subcommand): +@subcommand +def version(): + """ +Print blurb version. + """ + print("blurb version", __version__) + + + @subcommand def help(subcommand=None): """ @@ -818,6 +827,8 @@ def help(subcommand=None): # Make "blurb --help" work. subcommands["--help"] = help +subcommands["--version"] = version +subcommands["-v"] = version @subcommand @@ -1205,7 +1216,7 @@ def main(): fn = get_subcommand(subcommand) # hack - if fn in (test, help): + if fn in (help, test, version): sys.exit(fn(*args)) try: diff --git a/tox.ini b/tox.ini index 4956937..fa69718 100644 --- a/tox.ini +++ b/tox.ini @@ -19,5 +19,7 @@ commands = {posargs} blurb test blurb help + blurb --version {envpython} -I -m blurb test {envpython} -I -m blurb help + {envpython} -I -m blurb version From a6aefbfd5e686eaeb405f7ff0c307f0dd9d2a509 Mon Sep 17 00:00:00 2001 From: Hugo van Kemenade <1324225+hugovk@users.noreply.github.com> Date: Fri, 11 Oct 2024 11:05:45 +0300 Subject: [PATCH 07/10] Generate __version__ at build to avoid slow importlib.metadata import --- .gitignore | 3 +++ pyproject.toml | 3 +++ src/blurb/__init__.py | 4 +--- 3 files changed, 7 insertions(+), 3 deletions(-) diff --git a/.gitignore b/.gitignore index 009c104..353ced5 100644 --- a/.gitignore +++ b/.gitignore @@ -90,3 +90,6 @@ ENV/ # pytest .pytest_cache/ + +# hatch-vcs +src/*/_version.py diff --git a/pyproject.toml b/pyproject.toml index cad458f..713dfb0 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -42,6 +42,9 @@ scripts.blurb = "blurb.blurb:main" [tool.hatch] version.source = "vcs" +[tool.hatch.build.hooks.vcs] +version-file = "src/blurb/_version.py" + [tool.hatch.version.raw-options] local_scheme = "no-local-version" diff --git a/src/blurb/__init__.py b/src/blurb/__init__.py index 63dfcac..8dee4bf 100644 --- a/src/blurb/__init__.py +++ b/src/blurb/__init__.py @@ -1,3 +1 @@ -import importlib.metadata - -__version__ = importlib.metadata.version(__name__) +from ._version import __version__ From 56bba411e210b94b5a485c5300856adfbe623fca Mon Sep 17 00:00:00 2001 From: Hugo van Kemenade <1324225+hugovk@users.noreply.github.com> Date: Fri, 11 Oct 2024 19:53:17 +0300 Subject: [PATCH 08/10] Apply suggestions from code review Co-authored-by: Ezio Melotti Co-authored-by: Adam Turner <9087854+AA-Turner@users.noreply.github.com> --- src/blurb/blurb.py | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/src/blurb/blurb.py b/src/blurb/blurb.py index 27c3e3d..faefd10 100755 --- a/src/blurb/blurb.py +++ b/src/blurb/blurb.py @@ -744,9 +744,7 @@ def get_subcommand(subcommand): @subcommand def version(): - """ -Print blurb version. - """ + """Print blurb version.""" print("blurb version", __version__) @@ -825,10 +823,10 @@ def help(subcommand=None): print(doc) sys.exit(0) -# Make "blurb --help" work. +# Make "blurb --help/--version/-V" work. subcommands["--help"] = help subcommands["--version"] = version -subcommands["-v"] = version +subcommands["-V"] = version @subcommand From 1f876646a7cb6765475f30454fe6fc01ae5014db Mon Sep 17 00:00:00 2001 From: Hugo van Kemenade <1324225+hugovk@users.noreply.github.com> Date: Fri, 11 Oct 2024 20:00:13 +0300 Subject: [PATCH 09/10] Test version() --- tests/test_blurb.py | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/tests/test_blurb.py b/tests/test_blurb.py index 1c18a9f..9ff3a8d 100644 --- a/tests/test_blurb.py +++ b/tests/test_blurb.py @@ -179,3 +179,12 @@ def test_extract_next_filename(news_entry, expected_path, fs): # Assert assert path == expected_path + + +def test_version(capfd): + # Act + blurb.version() + + # Assert + captured = capfd.readouterr() + assert captured.out.startswith("blurb version ") From 350fb26767445ac0d3deb582838fa2f4d0186371 Mon Sep 17 00:00:00 2001 From: Hugo van Kemenade <1324225+hugovk@users.noreply.github.com> Date: Sat, 12 Oct 2024 18:33:17 +0300 Subject: [PATCH 10/10] Update changelog for 1.3.0 --- CHANGELOG.md | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 4783afd..3628254 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,14 @@ # Changelog +## 1.3.0 + +* Add support for Python 3.13 by @hugovk in https://github.com/python/blurb/pull/26 +* Drop support for Python 3.8 by @hugovk in https://github.com/python/blurb/pull/27 +* Generate digital attestations for PyPI (PEP 740) by @hugovk in https://github.com/python/blurb/pull/28 +* Allow running blurb test from blurb-* directories by @hroncok in https://github.com/python/blurb/pull/24 +* Add `version` subcommand by @hugovk in https://github.com/python/blurb/pull/29 +* Generate `__version__` at build to avoid slow `importlib.metadata` import by @hugovk in https://github.com/python/blurb/pull/30 + ## 1.2.1 - Fix `python3 -m blurb`.