diff --git a/.copier-answers.yml b/.copier-answers.yml index 5373142..4477df7 100644 --- a/.copier-answers.yml +++ b/.copier-answers.yml @@ -1,4 +1,4 @@ -_commit: cd034ea +_commit: 65cc40e _src_path: gh:bswck/skeleton author_username: bswck docs: true diff --git a/.github/FUNDING.yml b/.github/FUNDING.yml index 4cbf85f..2e0584b 100644 --- a/.github/FUNDING.yml +++ b/.github/FUNDING.yml @@ -1 +1,3 @@ +# {{'project/.github/#% if author_username == "bswck" %#FUNDING.yml#% endif %#'|skeleton_notice(snref=snref, srev=srev)|custom_indent("# ")}} + github: "bswck" \ No newline at end of file diff --git a/.github/ISSUE_TEMPLATE/bug.yml b/.github/ISSUE_TEMPLATE/bug.yml index 1e6d5a4..cd64e1a 100644 --- a/.github/ISSUE_TEMPLATE/bug.yml +++ b/.github/ISSUE_TEMPLATE/bug.yml @@ -1,3 +1,7 @@ +# This file was generated from bswck/skeleton@65cc40e. +# Instead of changing this particular file, you might want to alter the template: +# https://github.com/bswck/skeleton/tree/65cc40e/project/.github/ISSUE_TEMPLATE/bug.yml.jinja + # docs https://docs.github.com/en/communities/using-templates-to-encourage-useful-issues-and-pull-requests/syntax-for-issue-forms # https://docs.github.com/en/communities/using-templates-to-encourage-useful-issues-and-pull-requests/syntax-for-githubs-form-schema diff --git a/.github/ISSUE_TEMPLATE/config.yml b/.github/ISSUE_TEMPLATE/config.yml index 3ba13e0..faee706 100644 --- a/.github/ISSUE_TEMPLATE/config.yml +++ b/.github/ISSUE_TEMPLATE/config.yml @@ -1 +1,5 @@ -blank_issues_enabled: false +# This file was generated from bswck/skeleton@65cc40e. +# Instead of changing this particular file, you might want to alter the template: +# https://github.com/bswck/skeleton/tree/65cc40e/project/.github/ISSUE_TEMPLATE/config.yml.jinja + +blank_issues_enabled: true diff --git a/.github/ISSUE_TEMPLATE/functionality.yaml b/.github/ISSUE_TEMPLATE/functionality.yml similarity index 81% rename from .github/ISSUE_TEMPLATE/functionality.yaml rename to .github/ISSUE_TEMPLATE/functionality.yml index 2692857..757f883 100644 --- a/.github/ISSUE_TEMPLATE/functionality.yaml +++ b/.github/ISSUE_TEMPLATE/functionality.yml @@ -1,3 +1,7 @@ +# This file was generated from bswck/skeleton@65cc40e. +# Instead of changing this particular file, you might want to alter the template: +# https://github.com/bswck/skeleton/tree/65cc40e/project/.github/ISSUE_TEMPLATE/functionality.yml.jinja + # docs https://docs.github.com/en/communities/using-templates-to-encourage-useful-issues-and-pull-requests/syntax-for-issue-forms # https://docs.github.com/en/communities/using-templates-to-encourage-useful-issues-and-pull-requests/syntax-for-githubs-form-schema diff --git a/.github/pull_request_template.md b/.github/PULL_REQUEST_TEMPLATE.md similarity index 100% rename from .github/pull_request_template.md rename to .github/PULL_REQUEST_TEMPLATE.md diff --git a/.github/dependabot.yml b/.github/dependabot.yml new file mode 100644 index 0000000..53007fa --- /dev/null +++ b/.github/dependabot.yml @@ -0,0 +1,6 @@ +version: 2 +updates: +- package-ecosystem: "gitsubmodule" + directory: "/" + schedule: + interval: "daily" diff --git a/.github/workflows/documentation-links.yml b/.github/workflows/documentation-links.yml index 4df361e..baed077 100644 --- a/.github/workflows/documentation-links.yml +++ b/.github/workflows/documentation-links.yml @@ -1,3 +1,7 @@ +# This file was generated from bswck/skeleton@65cc40e. +# Instead of changing this particular file, you might want to alter the template: +# https://github.com/bswck/skeleton/tree/65cc40e/project/.github/workflows/%23%25%20if%20docs%20%25%23documentation-links.yml%23%25%20endif%20%25%23.jinja + name: "readthedocs/actions" on: pull_request_target: @@ -5,6 +9,7 @@ on: - "opened" paths: - "docs/**" + - "CHANGELOG.md" permissions: pull-requests: "write" diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml index e30d3ab..41280f4 100644 --- a/.github/workflows/lint.yml +++ b/.github/workflows/lint.yml @@ -1,3 +1,7 @@ +# This file was generated from bswck/skeleton@65cc40e. +# Instead of changing this particular file, you might want to alter the template: +# https://github.com/bswck/skeleton/tree/65cc40e/project/.github/workflows/lint.yml.jinja + name: "Lint" on: ["push"] @@ -13,6 +17,6 @@ jobs: python-version: "3.8" - name: "Install Ruff" run: | - pipx install ruff + pip install ruff - name: "Analyze the code with Ruff" run: "ruff ." diff --git a/.github/workflows/mypy.yml b/.github/workflows/mypy.yml index c971280..39e220e 100644 --- a/.github/workflows/mypy.yml +++ b/.github/workflows/mypy.yml @@ -1,3 +1,7 @@ +# This file was generated from bswck/skeleton@65cc40e. +# Instead of changing this particular file, you might want to alter the template: +# https://github.com/bswck/skeleton/tree/65cc40e/project/.github/workflows/mypy.yml.jinja + name: "Mypy" on: ["push"] @@ -13,7 +17,7 @@ jobs: python-version: "3.8" - name: "Install the project" run: | - pipx install poetry + pip install poetry poetry install - name: "Type-check with mypy" run: > diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index a92ee37..98c94ef 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -1,3 +1,7 @@ +# This file was generated from bswck/skeleton@65cc40e. +# Instead of changing this particular file, you might want to alter the template: +# https://github.com/bswck/skeleton/tree/65cc40e/project/.github/workflows/%23%25%20if%20publish_on_pypi%20%25%23release.yml%23%25%20endif%20%25%23.jinja + name: "PyPI" on: diff --git a/.github/workflows/smokeshow.yml b/.github/workflows/smokeshow.yml index 5ef721f..d3078d1 100644 --- a/.github/workflows/smokeshow.yml +++ b/.github/workflows/smokeshow.yml @@ -1,3 +1,7 @@ +# This file was generated from bswck/skeleton@65cc40e. +# Instead of changing this particular file, you might want to alter the template: +# https://github.com/bswck/skeleton/tree/65cc40e/project/.github/workflows/%23%25%20if%20public%20%25%23smokeshow.yml%23%25%20endif%20%25%23.jinja + name: "Smokeshow" on: diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index f3644dd..5c6326d 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -1,3 +1,7 @@ +# This file was generated from bswck/skeleton@65cc40e. +# Instead of changing this particular file, you might want to alter the template: +# https://github.com/bswck/skeleton/tree/65cc40e/project/.github/workflows/%23%25%20if%20test_suite%20%25%23test.yml%23%25%20endif%20%25%23.jinja + name: "Tests" on: ["push"] @@ -17,7 +21,7 @@ jobs: python-version: "${{matrix.python-version}}" - name: "Install the project" run: | - pipx install poetry + pip install poetry poetry install - name: "Run tests" run: "poetry run coverage run -m pytest -v ." diff --git a/.gitignore b/.gitignore index bf95f21..e9472d8 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,7 @@ +# This file was generated from bswck/skeleton@65cc40e. +# Instead of changing this particular file, you might want to alter the template: +# https://github.com/bswck/skeleton/tree/65cc40e/project/.gitignore.jinja + # Byte-compiled / optimized / DLL files __pycache__/ *.py[cod] diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 9d10978..a0412f2 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -1,11 +1,8 @@ +# This file was generated from bswck/skeleton@65cc40e. +# Instead of changing this particular file, you might want to alter the template: +# https://github.com/bswck/skeleton/tree/65cc40e/project/%23%25%20if%20use_precommit%20%25%23.pre-commit-config.yaml%23%25%20endif%20%25%23.jinja + repos: -- repo: "https://github.com/pre-commit/pre-commit-hooks" - rev: "v4.5.0" - hooks: - - id: "check-yaml" - name: "Check YAML files" - - id: "trailing-whitespace" - name: "Trim trailing whitespaces" - repo: "https://github.com/astral-sh/ruff-pre-commit" rev: "v0.1.5" hooks: @@ -19,6 +16,10 @@ repos: - repo: "https://github.com/python-poetry/poetry" rev: "1.7.0" hooks: + - id: "poetry-lock" + stages: ["push"] + name: "Run Poetry lock hook" + args: ["--no-update"] - id: "poetry-check" stages: ["push"] name: "Run Poetry check hook" \ No newline at end of file diff --git a/.readthedocs.yml b/.readthedocs.yml index 69bfdf3..7e5e33d 100644 --- a/.readthedocs.yml +++ b/.readthedocs.yml @@ -1,3 +1,7 @@ +# This file was generated from bswck/skeleton@65cc40e. +# Instead of changing this particular file, you might want to alter the template: +# https://github.com/bswck/skeleton/tree/65cc40e/project/%23%25%20if%20docs%20%25%23.readthedocs.yml%23%25%20endif%20%25%23.jinja +# # Read the Docs configuration file # See https://docs.readthedocs.io/en/stable/config-file/v2.html for details version: 2 diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 4337d4a..418bd12 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -1,3 +1,8 @@ + # Contributing to [runtime_generics](https://github.com/bswck/runtime_generics) 🎉 Contributions are very welcome. 🚀 @@ -25,11 +30,25 @@ If you are proposing a feature: - Remember that this is a volunteer-driven project, and that contributions are welcome! ✨ -## Get started! 🕹️ +## Pull Request guidelines 📝 +1. Initially mark the PR as a draft, so that the maintainers know that you are making final touches. + +1. Ensure that the [test coverage](https://coverage-badge.samuelcolvin.workers.dev/redirect/bswck/runtime_generics) is not decreased. If you add a new feature, please add tests for it. [Read more about coverage](https://coverage.readthedocs.io/en/latest/index.html). + +1. Ensure that all GitHub checks pass. If they are disabled in your PR, ping the maintainers to request enabling them. + +1. Don't forget to link the relevant issue(s) in the PR description and describe the changes you made. + +# Get started! 🕹️ Ready to contribute? Here's a quick guide on how to set up runtime_generics and make a change. + > [!Note] > If you use Windows, it is highly recommended to complete the installation in the way presented below through [WSL2](https://learn.microsoft.com/en-us/windows/wsl/install). @@ -95,12 +114,3 @@ Ready to contribute? Here's a quick guide on how to set up runtime_generics and 1. Submit a pull request through the GitHub website. - -## Pull Request guidelines 📝 -1. Initially mark the PR as a draft, so that the maintainers know that you are making final touches. - -1. Ensure that the [test coverage](https://coverage-badge.samuelcolvin.workers.dev/redirect/bswck/runtime_generics) is not decreased. If you add a new feature, please add tests for it. [Read more about coverage](https://coverage.readthedocs.io/en/latest/index.html). - -1. Ensure that all GitHub checks pass. If they are disabled in your PR, ping the maintainers to request enabling them. - -1. Don't forget to link the relevant issue(s) in the PR description and describe the changes you made. diff --git a/README.md b/README.md index 9a57a59..4416ab3 100644 --- a/README.md +++ b/README.md @@ -69,11 +69,9 @@ my_generic.whoami() # I am MyGeneric[int] ``` # Installation -If you want to… -## …use this tool in your project 💻 You might simply install it with pip: ```shell @@ -86,8 +84,13 @@ If you use [Poetry](https://python-poetry.org/), then run: poetry add runtime-generics ``` -## …contribute to [runtime_generics](https://github.com/bswck/runtime_generics) 🚀 +## For contributors + > [!Note] > If you use Windows, it is highly recommended to complete the installation in the way presented below through [WSL2](https://learn.microsoft.com/en-us/windows/wsl/install). diff --git a/changes/.gitignore b/changes/.gitignore index b722e9e..9e2dd94 100644 --- a/changes/.gitignore +++ b/changes/.gitignore @@ -1 +1,5 @@ +# This file was generated from bswck/skeleton@65cc40e. +# Instead of changing this particular file, you might want to alter the template: +# https://github.com/bswck/skeleton/tree/65cc40e/project/changes/.gitignore.jinja + !.gitignore \ No newline at end of file diff --git a/docs/contributing.md b/docs/contributing.md index 76c1766..7da1dd5 100644 --- a/docs/contributing.md +++ b/docs/contributing.md @@ -1,4 +1,9 @@ + # Contributing to [runtime_generics](https://github.com/bswck/runtime_generics) 🎉 Contributions are very welcome. 🚀 @@ -26,11 +31,25 @@ If you are proposing a feature: - Remember that this is a volunteer-driven project, and that contributions are welcome! ✨ -## Get started! 🕹️ +## Pull Request guidelines 📝 +1. Initially mark the PR as a draft, so that the maintainers know that you are making final touches. + +1. Ensure that the [test coverage](https://coverage-badge.samuelcolvin.workers.dev/redirect/bswck/runtime_generics) is not decreased. If you add a new feature, please add tests for it. [Read more about coverage](https://coverage.readthedocs.io/en/latest/index.html). + +1. Ensure that all GitHub checks pass. If they are disabled in your PR, ping the maintainers to request enabling them. + +1. Don't forget to link the relevant issue(s) in the PR description and describe the changes you made. + +# Get started! 🕹️ Ready to contribute? Here's a quick guide on how to set up runtime_generics and make a change. + !!! Note If you use Windows, it is highly recommended to complete the installation in the way presented below through [WSL2](https://learn.microsoft.com/en-us/windows/wsl/install). @@ -96,12 +115,3 @@ Ready to contribute? Here's a quick guide on how to set up runtime_generics and 1. Submit a pull request through the GitHub website. - -## Pull Request guidelines 📝 -1. Initially mark the PR as a draft, so that the maintainers know that you are making final touches. - -1. Ensure that the [test coverage](https://coverage-badge.samuelcolvin.workers.dev/redirect/bswck/runtime_generics) is not decreased. If you add a new feature, please add tests for it. [Read more about coverage](https://coverage.readthedocs.io/en/latest/index.html). - -1. Ensure that all GitHub checks pass. If they are disabled in your PR, ping the maintainers to request enabling them. - -1. Don't forget to link the relevant issue(s) in the PR description and describe the changes you made. diff --git a/docs/index.md b/docs/index.md index caf5027..9781590 100644 --- a/docs/index.md +++ b/docs/index.md @@ -11,11 +11,9 @@ Reuse type arguments explicitly passed at runtime to a generic class before instantiating. # Installation -If you want to… -## …use this tool in your project 💻 You might simply install it with pip: ```shell @@ -28,8 +26,13 @@ If you use [Poetry](https://python-poetry.org/), then run: poetry add runtime-generics ``` -## …contribute to [runtime_generics](https://github.com/bswck/runtime_generics) 🚀 +## For contributors + !!! Note If you use Windows, it is highly recommended to complete the installation in the way presented below through [WSL2](https://learn.microsoft.com/en-us/windows/wsl/install). diff --git a/mkdocs.yml b/mkdocs.yml index e5c7255..97e67e7 100644 --- a/mkdocs.yml +++ b/mkdocs.yml @@ -1,3 +1,7 @@ +# This file was generated from bswck/skeleton@65cc40e. +# Instead of changing this particular file, you might want to alter the template: +# https://github.com/bswck/skeleton/tree/65cc40e/project/%23%25%20if%20docs%20%25%23mkdocs.yml%23%25%20endif%20%25%23.jinja + site_name: "runtime_generics" site_description: "Reuse type arguments explicitly passed at runtime to a generic class before instantiating." site_url: "https://runtime-generics.readthedocs.io/en/latest/" diff --git a/playground/.gitkeep b/playground/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/poetry.lock b/poetry.lock index b2d7a96..66e0ddb 100644 --- a/poetry.lock +++ b/poetry.lock @@ -1394,5 +1394,5 @@ testing = ["big-O", "jaraco.functools", "jaraco.itertools", "more-itertools", "p [metadata] lock-version = "2.0" -python-versions = "^3.8" -content-hash = "eddacd946f96894004e528ad68fb00cddb19e97013e3518b290630f80410c12c" +python-versions = ">=3.8,<=3.12" +content-hash = "3e96b5d4faa2fcd7e79710be2550a88660a3345a46e6528c33c14b10367ac236" diff --git a/pyproject.toml b/pyproject.toml index e7452be..5a94bb2 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,3 +1,7 @@ +# This file was generated from bswck/skeleton@65cc40e. +# Instead of changing this particular file, you might want to alter the template: +# https://github.com/bswck/skeleton/tree/65cc40e/project/pyproject.toml.jinja + [tool.poetry] name = "runtime_generics" version = "2.0.3" @@ -14,11 +18,15 @@ Issues = "https://github.com/bswck/runtime_generics/issues" Distribution = "https://pypi.org/project/runtime-generics/" Coverage = "https://coverage-badge.samuelcolvin.workers.dev/redirect/bswck/runtime_generics" - [tool.poetry.dependencies] -python = "^3.8" +python = ">=3.8,<=3.12" [tool.poetry.group.dev.dependencies] + +[tool.poetry.group.dev-skeleton.dependencies] +# This dependency group was generated from bswck/skeleton@65cc40e. +# Instead of changing this particular file, you might want to alter the template: +# https://github.com/bswck/skeleton/tree/65cc40e/project/pyproject.toml.jinja mypy = "^1.7.0" ruff = "^0.1.2" towncrier = "^23.11.0" @@ -27,8 +35,6 @@ coverage = "^7.3.2" poethepoet = "^0.24.3" pre-commit = "^3.5.0" smokeshow = "^0.4.0" - - [tool.poetry.group.docs] optional = true @@ -40,12 +46,11 @@ mkdocstrings = { version = ">=0.19.0", extras = ["python"] } [tool.poe.tasks] test = "pytest -v" lint = "ruff check ." -lock = "scripts/lock.sh" -bump = "scripts/bump.sh" +reanswer = "scripts/skeleton.sh reanswer" +bump = "scripts/skeleton.sh bump" check = [ { ref="test" }, { ref="lint" }, - { ref="lock" }, ] release.script = "scripts.release:main" @@ -119,7 +124,7 @@ package = "runtime_generics" filename = "CHANGELOG.md" start_string = "\n" underlines = ["", "", ""] # We use Markdown -title_format = "## [{version}](https://github.com/bswck/runtime_generics/tree/{version}) – {project_date}" +title_format = "## [{version}](https://github.com/bswck/runtime_generics/tree/{version}) ({project_date})" issue_format = "[#{issue}](https://github.com/bswck/runtime_generics/issues/{issue})" [[tool.towncrier.type]] diff --git a/scripts/lock.sh b/scripts/lock.sh deleted file mode 100755 index 20312ce..0000000 --- a/scripts/lock.sh +++ /dev/null @@ -1,11 +0,0 @@ -#!/usr/bin/env bash -# (C) 2023–present Bartosz Sławecki (bswck) -# -# Run this before pushing to ensure that the package lock is up-to-date. -# -# Usage: -# $ poe lock - -poetry lock --no-update -echo "Auto-commit package lock" -git add "poetry.lock" && git commit -m "Update package lock" || exit 0 \ No newline at end of file diff --git a/scripts/release.py b/scripts/release.py index 8179dc7..c515b1c 100644 --- a/scripts/release.py +++ b/scripts/release.py @@ -1,9 +1,10 @@ #!/usr/bin/env python # (C) 2023–present Bartosz Sławecki (bswck) # -# Note: -# If you want to change this file, you might want to do it at the infrastructure -# level. See https://github.com/bswck/skeleton. +# This file was generated from bswck/skeleton@65cc40e. +# Instead of changing this particular file, you might want to alter the template: +# https://github.com/bswck/skeleton/tree/65cc40e/project/scripts/release.py.jinja +# """ Automate the release process by updating local files, creating and pushing a new tag. @@ -16,7 +17,6 @@ from __future__ import annotations import argparse -import functools import logging import os import subprocess @@ -53,13 +53,6 @@ def _ask_for_confirmation(msg: str, *, default: bool | None = None) -> bool: return answer[0] == "y" -def _decode_if_bytes(value: bytes | str, /) -> str: - """Decode bytes to str.""" - if isinstance(value, bytes): - return value.decode() - return value - - def _setup_logging() -> None: _LOGGER.setLevel(logging.INFO) _logger_handler = logging.StreamHandler() @@ -69,15 +62,13 @@ def _setup_logging() -> None: def release(version: str, /) -> None: """Release a semver version.""" - cmd, shell = str.split, functools.partial(subprocess.run, check=True) - - changed_files = _decode_if_bytes( - shell( - cmd("git diff --name-only HEAD"), - capture_output=True, - ).stdout + command, run = ( + subprocess.getoutput, + lambda *prompt: subprocess.run([*prompt], check=True), ) + changed_files = command("git status --porcelain") + if changed_files: do_continue = _ask_for_confirmation( "There are uncommitted changes in the working tree in these files:\n" @@ -99,45 +90,28 @@ def release(version: str, /) -> None: _abort(f"You said no when prompted to bump to the {version!r} version.") _LOGGER.info("Bumping to the %r version", version) + run("poetry", "version", version) - shell([*cmd("poetry version"), version]) - - new_version = "v" + ( - _decode_if_bytes( - shell( - cmd("poetry version --short"), - capture_output=True, - ).stdout, - ).strip() - ) - - default_release_notes = _decode_if_bytes( - shell( - cmd(f"towncrier build --draft --yes --version={new_version}"), - capture_output=True, - ).stdout - ) - shell(cmd(f"towncrier build --yes --version={new_version}")) - - changed_for_release = _decode_if_bytes( - shell( - cmd("git diff --name-only HEAD"), - capture_output=True, - ).stdout + new_version = "v" + command("poetry version --short").strip() + default_release_notes = command( + f"towncrier build --draft --yes --version={new_version}" ) + command(f"towncrier build --yes --version={new_version}") + changed_for_release = command("git status --porcelain") if changed_for_release: - shell(cmd("git diff")) + run("git", "diff") + do_commit = _ask_for_confirmation( "You are about to commit and push auto-changed files due " - "to version upgrade, see the diff view above. " + "to version upgrade, as in the diff view displayed just now. " "Are you sure?", default=True, ) if do_commit: - shell([*cmd("git commit -am"), f"Release {new_version}"]) - shell(cmd("git push")) + run("git", "commit", "-am", f"Release {new_version}") + run("git", "push") else: _abort( "Changes made uncommitted. " @@ -147,12 +121,12 @@ def release(version: str, /) -> None: _LOGGER.info("Creating %s tag...", new_version) try: - shell([*cmd("git tag -sa"), new_version, "-m", f"Release {new_version}"]) + run("git", "tag", "-sa", new_version, "-m", f"Release {new_version}") except subprocess.CalledProcessError: _abort(f"Failed to create {new_version} tag, probably already exists.") else: _LOGGER.info("Pushing local tags...") - shell(cmd("git push --tags")) + run("git", "push", "--tags") do_release = _ask_for_confirmation( "Create a GitHub release now? GitHub CLI required.", @@ -173,7 +147,7 @@ def release(version: str, /) -> None: temp_file.close() while not notes_complete: - shell(cmd(f"{_EDITOR} {temp_file.name}")) + run(_EDITOR, temp_file.name) release_notes = Path(temp_file.name).read_text() print("Release notes:") print(release_notes) @@ -183,15 +157,13 @@ def release(version: str, /) -> None: default=True, ) - shell( - cmd( - f"gh release create {new_version} --generate-notes " - f"--notes-file {temp_file.name}", - ) + run( + "gh", "release", "create", new_version, "--generate-notes", + "--notes-file", temp_file.name, ) os.unlink(temp_file.name) else: - shell(cmd(f"gh release create {new_version} --generate-notes")) + run("gh", "release", "create", new_version, "--generate-notes") def main(argv: list[str] | None = None) -> None: @@ -199,13 +171,8 @@ def main(argv: list[str] | None = None) -> None: _setup_logging() parser = argparse.ArgumentParser(description="Release a semver version.") - parser.add_argument( - "version", - type=str, - nargs=1, - ) - args: argparse.Namespace = parser.parse_args(argv) - release(args.version.pop()) + parser.add_argument("version", type=str) + release(*vars(parser.parse_args(argv)).values()) if __name__ == "__main__": diff --git a/scripts/bump.sh b/scripts/skeleton.sh similarity index 72% rename from scripts/bump.sh rename to scripts/skeleton.sh index 4325927..274fadc 100755 --- a/scripts/bump.sh +++ b/scripts/skeleton.sh @@ -1,32 +1,28 @@ #!/usr/bin/env bash # (C) 2023–present Bartosz Sławecki (bswck) # -# Sync with bswck/skeleton. -# This script was adopted from https://github.com/bswck/skeleton/tree/cd034ea/project/scripts/bump.sh.jinja +# Interact with bswck/skeleton (current version: https://github.com/bswck/skeleton/tree/65cc40e). +# +# This file was generated from bswck/skeleton@65cc40e. +# Instead of changing this particular file, you might want to alter the template: +# https://github.com/bswck/skeleton/tree/65cc40e/project/scripts/skeleton.sh.jinja # # Usage: +# +# To update to the latest version: # $ poe bump +# +# To update to version 1.2.3: +# $ poe bump 1.2.3 +# +# To make a mechanized repo patch, but keep the current skeleton version: +# $ poe reanswer +# +# It's intended to be impossible to make a mechanized repo patch and update the skeleton +# at the same time. # shellcheck disable=SC2005 - - -# Automatically copied from https://github.com/bswck/skeleton/tree/cd034ea/handle-task-event.sh -make_token() { - export TOKEN - TOKEN="$(echo "$(date +%s%N)" | sha256sum | head -c "${1:-10}")" -} - -stash() { - make_token 32 - export STASH_TOKEN="$TOKEN" - git stash push -m "$STASH_TOKEN" -} - -unstash() { - STASH_ID="$(echo "$("$(git stash list)" | grep "${1:-STASH_TOKEN}" | grep -oP "^stash@{\K(\d)+")")" - git stash pop "stash@{$STASH_ID}" -} - +# Automatically copied from https://github.com/bswck/skeleton/tree/65cc40e/handle-task-event.sh setup_gh() { echo "Calling GitHub setup hooks..." supply_smokeshow_key @@ -40,7 +36,7 @@ determine_project_path() { ensure_gh_environment() { # Ensure that the GitHub environment exists - echo "$(jq -n '{"deployment_branch_policy": {"protected_branches": false, "custom_branch_policies": true}}' | gh api -H "Accept: application/vnd.github+json" -X PUT "/repos/bswck/runtime_generics/environments/$1" --input -)" > /dev/null 2>&1 || return 1 + echo "$(jq -n '{"deployment_branch_policy": {"protected_branches": false,"custom_branch_policies": true}}' | gh api -H "Accept: application/vnd.github+json" -X PUT "/repos/bswck/runtime_generics/environments/$1" --input -)" > /dev/null 2>&1 || return 1 } supply_smokeshow_key() { @@ -63,7 +59,6 @@ supply_smokeshow_key() { } # End of copied code - determine_new_ref() { # Determine the new skeleton revision set by the child process export NEW_REF @@ -72,10 +67,11 @@ determine_new_ref() { before_update_algorithm() { # Stash changes if any - if test "$(echo "$(git diff --name-only)")" + if test "$(git status --porcelain)" then - echo "There are uncommitted changes in the project." - stash + echo "There are uncommitted changes in the project." 1>&2 + echo "Stash them and continue." 1>&2 + return 1 else echo "Working tree clean, no need to stash." fi @@ -83,7 +79,19 @@ before_update_algorithm() { run_update_algorithm() { # Run the underlying update algorithm - copier update --trust --vcs-ref "${1:-"HEAD"}" "${@:2}" || return 1 + export MODE + SKELETON_COMMAND="${1:-"bump"}" + if test "$SKELETON_COMMAND" = "bump" + then + copier update --trust --vcs-ref "${2:-"HEAD"}" --defaults || return 1 + elif test "$SKELETON_COMMAND" = "reanswer" + then + # shellcheck disable=SC2068 + copier update --trust --vcs-ref "$LAST_REF" ${@:3} || return 1 + else + echo "Unknown update algorithm: '$1'" + return 1 + fi determine_new_ref determine_project_path } @@ -91,17 +99,14 @@ run_update_algorithm() { after_update_algorithm() { # Run post-update hooks, auto-commit changes cd "$PROJECT_PATH" || exit 1 - echo "Previous skeleton revision: $LAST_REF" echo "Current skeleton revision: ${NEW_REF:-"N/A"}" - local REVISION_PARAGRAPH="Skeleton revision: https://github.com/bswck/skeleton/tree/${NEW_REF:-"HEAD"}" - git add . if test "$LAST_REF" = "$NEW_REF" then echo "The version of the skeleton has not changed." - local COMMIT_MSG="Patch .copier-answers.yml at bswck/skeleton@$NEW_REF" + local COMMIT_MSG="Mechanized patch at bswck/skeleton@$NEW_REF" else if test "$NEW_REF" then @@ -116,19 +121,13 @@ after_update_algorithm() { read -r || exit 1 git commit --no-verify -m "$COMMIT_MSG" -m "$REVISION_PARAGRAPH" setup_gh - if test "$STASH_TOKEN" - then - echo "Unstashing changes..." - unstash && echo "Done!" - fi } main() { - export LAST_REF="cd034ea" + export LAST_REF="65cc40e" export PROJECT_PATH_KEY="$$_skeleton_project_path" export NEW_REF_KEY="$$_skeleton_new_ref" export LAST_LICENSE_NAME="MIT" - cd "${PROJECT_PATH:=$(git rev-parse --show-toplevel)}" || exit 1 echo echo "--- Last skeleton revision: $LAST_REF"