From 6de029274113e8d78fc60fb251a919444a825ea2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Timoth=C3=A9e=20Mazzucotelli?= Date: Thu, 5 Sep 2024 16:08:01 +0200 Subject: [PATCH 01/21] docs: Update type-ignore paragraph --- docs/work.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/docs/work.md b/docs/work.md index 5eb5445..a440903 100644 --- a/docs/work.md +++ b/docs/work.md @@ -334,9 +334,11 @@ If you cannot or don't know how to fix a typing error in your code, as a last resort you can ignore this specific error with a comment: ```python title="src/your_package/module.py" -result = data_dict.get(key, None).value # type: ignore +result = data_dict.get(key, None).value # type: ignore[ID] ``` +...where ID is the name of the warning, for example `arg-type` or `union-attr`. + ### check-api This actions runs [Griffe](https://github.com/mkdocstrings/griffe) From bf3c328b8aefa1b5e33bb3bf55ff0039c9a436b1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Timoth=C3=A9e=20Mazzucotelli?= Date: Thu, 5 Sep 2024 16:10:12 +0200 Subject: [PATCH 02/21] refactor: Use higher-level uv commands --- docs/work.md | 18 ++++++-- project/.github/workflows/ci.yml.jinja | 6 ++- project/.gitignore | 1 + project/devdeps.txt.jinja | 33 --------------- project/pyproject.toml.jinja | 37 +++++++++++++++- project/scripts/gen_credits.py.jinja | 3 +- project/scripts/make | 58 ++++++-------------------- 7 files changed, 68 insertions(+), 88 deletions(-) delete mode 100644 project/devdeps.txt.jinja diff --git a/docs/work.md b/docs/work.md index a440903..ce8365d 100644 --- a/docs/work.md +++ b/docs/work.md @@ -79,11 +79,11 @@ By default it is set to active versions of Python Dependencies are managed by [uv](https://github.com/astral-sh/uv). -Use `make setup` or `uv venv; uv pip install -r devdeps.txt` to install the dependencies. +Use `make setup` or `uv sync` to install the dependencies. -Runtime dependencies are written in `pyproject.toml`, -under the `[project]` and `[project.optional-dependencies]` -sections, and development dependencies are listed in `devdeps.txt`. +Dependencies are written in `pyproject.toml`. +Runtime dependencies are listed under the `[project]` and `[project.optional-dependencies]` sections, +and development dependencies are listed under the `[tool.uv]` section. Example: @@ -93,6 +93,16 @@ dependencies = [ "fastapi>=1.0", "importlib-metadata>=2.0", ] + +[project.optional-dependencies] +test = [ + "pytest", +] + +[tool.uv] +dev-dependencies = [ + "ruff", +] ``` ## Tasks diff --git a/project/.github/workflows/ci.yml.jinja b/project/.github/workflows/ci.yml.jinja index 98d89c4..63136b8 100644 --- a/project/.github/workflows/ci.yml.jinja +++ b/project/.github/workflows/ci.yml.jinja @@ -121,8 +121,10 @@ jobs: python-version: {% raw %}${{ matrix.python-version }}{% endraw %} allow-prereleases: true - - name: Install uv - run: pip install uv + - name: Setup uv + uses: astral-sh/setup-uv@v1 + with: + enable-cache: true - name: Install dependencies env: diff --git a/project/.gitignore b/project/.gitignore index 41fee62..9fea047 100644 --- a/project/.gitignore +++ b/project/.gitignore @@ -15,6 +15,7 @@ /.pdm-build/ /htmlcov/ /site/ +uv.lock # cache .cache/ diff --git a/project/devdeps.txt.jinja b/project/devdeps.txt.jinja deleted file mode 100644 index 5433621..0000000 --- a/project/devdeps.txt.jinja +++ /dev/null @@ -1,33 +0,0 @@ -# dev -editables>=0.5 - -# maintenance -build>=1.2 -git-changelog>=2.5 -twine>=5.0; python_version < '3.13' - -# ci -duty>=1.4 -ruff>=0.4 -pytest>=8.2 -pytest-cov>=5.0 -pytest-randomly>=3.15 -pytest-xdist>=3.6 -mypy>=1.10 -types-markdown>=3.6 -types-pyyaml>=6.0 - -# docs -black>=24.4 -markdown-callouts>=0.4 -markdown-exec>=1.8 -mkdocs>=1.6 -mkdocs-coverage>=1.0 -mkdocs-gen-files>=0.5 -mkdocs-git-committers-plugin-2>=2.3 -{#- mkdocs-git-revision-date-localized-plugin>=1.2 #} -mkdocs-literate-nav>=0.6 -mkdocs-material>=9.5 -mkdocs-minify-plugin>=0.8 -mkdocstrings[python]>=0.25 -tomli>=2.0; python_version < '3.11' diff --git a/project/pyproject.toml.jinja b/project/pyproject.toml.jinja index dd9e443..b733aaf 100644 --- a/project/pyproject.toml.jinja +++ b/project/pyproject.toml.jinja @@ -128,7 +128,6 @@ source-includes = [ "scripts", "share", "tests", - "devdeps.txt", "duties.py", "mkdocs.yml", "*.md", @@ -139,3 +138,39 @@ source-includes = [ data = [ {path = "share/**/*", relative-to = "."}, ] + +[tool.uv] +dev-dependencies = [ + # dev + "editables>=0.5", + + # maintenance + "build>=1.2", + "git-changelog>=2.5", + "twine>=5.0; python_version < '3.13'", + + # ci + "duty>=1.4", + "ruff>=0.4", + "pytest>=8.2", + "pytest-cov>=5.0", + "pytest-randomly>=3.15", + "pytest-xdist>=3.6", + "mypy>=1.10", + "types-markdown>=3.6", + "types-pyyaml>=6.0", + + # docs + "black>=24.4", + "markdown-callouts>=0.4", + "markdown-exec>=1.8", + "mkdocs>=1.6", + "mkdocs-coverage>=1.0", + "mkdocs-gen-files>=0.5", + "mkdocs-git-revision-date-localized-plugin>=1.2", + "mkdocs-literate-nav>=0.6", + "mkdocs-material>=9.5", + "mkdocs-minify-plugin>=0.8", + "mkdocstrings[python]>=0.25", + "tomli>=2.0; python_version < '3.11'", +] \ No newline at end of file diff --git a/project/scripts/gen_credits.py.jinja b/project/scripts/gen_credits.py.jinja index 1fab507..2001002 100644 --- a/project/scripts/gen_credits.py.jinja +++ b/project/scripts/gen_credits.py.jinja @@ -26,8 +26,7 @@ with project_dir.joinpath("pyproject.toml").open("rb") as pyproject_file: pyproject = tomllib.load(pyproject_file) project = pyproject["project"] project_name = project["name"] -with project_dir.joinpath("devdeps.txt").open() as devdeps_file: - devdeps = [line.strip() for line in devdeps_file if line.strip() and not line.strip().startswith(("-e", "#"))] +devdeps = [dep for dep in pyproject["tool"]["uv"]["dev-dependencies"] if not dep.startswith("-e")] PackageMetadata = Dict[str, Union[str, Iterable[str]]] Metadata = Dict[str, PackageMetadata] diff --git a/project/scripts/make b/project/scripts/make index d898022..e467d5c 100755 --- a/project/scripts/make +++ b/project/scripts/make @@ -13,9 +13,6 @@ from typing import Any, Iterator PYTHON_VERSIONS = os.getenv("PYTHON_VERSIONS", "3.8 3.9 3.10 3.11 3.12 3.13").split() -exe = "" -prefix = "" - def shell(cmd: str, capture_output: bool = False, **kwargs: Any) -> str | None: """Run a shell command.""" @@ -37,18 +34,11 @@ def environ(**kwargs: str) -> Iterator[None]: os.environ.update(original) -def uv_install() -> None: +def uv_install(venv: Path) -> None: """Install dependencies using uv.""" - uv_opts = "" - if "UV_RESOLUTION" in os.environ: - uv_opts = f"--resolution={os.getenv('UV_RESOLUTION')}" - requirements = shell(f"uv pip compile {uv_opts} pyproject.toml devdeps.txt", capture_output=True) - shell("uv pip install -r -", input=requirements, text=True) - if "CI" not in os.environ: - shell("uv pip install --no-deps -e .") - else: - shell("uv pip install --no-deps .") - + with environ(UV_PROJECT_ENVIRONMENT=str(venv)): + shell("uv sync") + def setup() -> None: """Setup the project.""" @@ -59,7 +49,7 @@ def setup() -> None: default_venv = Path(".venv") if not default_venv.exists(): shell("uv venv --python python") - uv_install() + uv_install(default_venv) if PYTHON_VERSIONS: for version in PYTHON_VERSIONS: @@ -67,39 +57,19 @@ def setup() -> None: venv_path = Path(f".venvs/{version}") if not venv_path.exists(): shell(f"uv venv --python {version} {venv_path}") - with environ(VIRTUAL_ENV=str(venv_path.resolve())): - uv_install() - - -def activate(path: str) -> None: - """Activate a virtual environment.""" - global exe, prefix # noqa: PLW0603 - - if (bin := Path(path, "bin")).exists(): - activate_script = bin / "activate_this.py" - elif (scripts := Path(path, "Scripts")).exists(): - activate_script = scripts / "activate_this.py" - exe = ".exe" - prefix = f"{path}/Scripts/" - else: - raise ValueError(f"make: activate: Cannot find activation script in {path}") - - if not activate_script.exists(): - raise ValueError(f"make: activate: Cannot find activation script in {path}") - - exec(activate_script.read_text(), {"__file__": str(activate_script)}) # noqa: S102 + with environ(UV_PROJECT_ENVIRONMENT=str(venv_path.resolve())): + uv_install(venv_path) def run(version: str, cmd: str, *args: str, **kwargs: Any) -> None: """Run a command in a virtual environment.""" kwargs = {"check": True, **kwargs} if version == "default": - activate(".venv") - subprocess.run([f"{prefix}{cmd}{exe}", *args], **kwargs) # noqa: S603, PLW1510 + with environ(UV_PROJECT_ENVIRONMENT=".venv"): + subprocess.run(["uv", "run", cmd, *args], **kwargs) # noqa: S603, PLW1510 else: - activate(f".venvs/{version}") - os.environ["MULTIRUN"] = "1" - subprocess.run([f"{prefix}{cmd}{exe}", *args], **kwargs) # noqa: S603, PLW1510 + with environ(UV_PROJECT_ENVIRONMENT=f".venvs/{version}", MULTIRUN="1"): + subprocess.run(["uv", "run", cmd, *args], **kwargs) # noqa: S603, PLW1510 def multirun(cmd: str, *args: str, **kwargs: Any) -> None: @@ -152,11 +122,7 @@ def main() -> int: print(" 3.x Run a command in the virtual environment for Python 3.x.") # noqa: T201 print(" clean Delete build artifacts and cache files.") # noqa: T201 print(" vscode Configure VSCode to work on this project.") # noqa: T201 - try: - run("default", "python", "-V", capture_output=True) - except (subprocess.CalledProcessError, ValueError): - pass - else: + if os.path.exists(".venv"): print("\nAvailable tasks") # noqa: T201 run("default", "duty", "--list") return 0 From 2e4dd5b65ff49e45a6123a701ae572a6a15041aa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Timoth=C3=A9e=20Mazzucotelli?= Date: Thu, 5 Sep 2024 16:10:37 +0200 Subject: [PATCH 03/21] refactor: Clean up `check` duty (pre tasks) --- project/duties.py.jinja | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/project/duties.py.jinja b/project/duties.py.jinja index 2f899ae..42c7b01 100644 --- a/project/duties.py.jinja +++ b/project/duties.py.jinja @@ -53,7 +53,7 @@ def changelog(ctx: Context, bump: str = "") -> None: ctx.run(tools.git_changelog(bump=bump or None), title="Updating changelog") -@duty(pre=["check_quality", "check_types", "check_docs", "check_dependencies", "check-api"]) +@duty(pre=["check-quality", "check-types", "check-docs", "check-api"]) def check(ctx: Context) -> None: # noqa: ARG001 """Check it all!""" From 5c2384fed4fc039f319699832ea17aabe5e96e67 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Timoth=C3=A9e=20Mazzucotelli?= Date: Thu, 5 Sep 2024 16:10:48 +0200 Subject: [PATCH 04/21] style: Format --- project/duties.py.jinja | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/project/duties.py.jinja b/project/duties.py.jinja index 42c7b01..6faab43 100644 --- a/project/duties.py.jinja +++ b/project/duties.py.jinja @@ -54,7 +54,7 @@ def changelog(ctx: Context, bump: str = "") -> None: @duty(pre=["check-quality", "check-types", "check-docs", "check-api"]) -def check(ctx: Context) -> None: # noqa: ARG001 +def check(ctx: Context) -> None: """Check it all!""" From cb0135bf5bc80768fea17366efba35293c60ba93 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Timoth=C3=A9e=20Mazzucotelli?= Date: Thu, 5 Sep 2024 16:11:18 +0200 Subject: [PATCH 05/21] fix: Disallow overrides when getting Git remote in docs-deploy duty --- project/duties.py.jinja | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/project/duties.py.jinja b/project/duties.py.jinja index 6faab43..6dcf08d 100644 --- a/project/duties.py.jinja +++ b/project/duties.py.jinja @@ -122,9 +122,14 @@ def docs_deploy(ctx: Context) -> None: if not insiders: ctx.run(lambda: False, title="Not deploying docs without Material for MkDocs Insiders!") {%- if insiders %} - origin = ctx.run("git config --get remote.origin.url", silent=True) + origin = ctx.run("git config --get remote.origin.url", silent=True, allow_overrides=False) if "{{ author_username }}-insiders/{{ insiders_repository_name }}" in origin: - ctx.run("git remote add upstream git@github.com:{{ repository_namespace }}/{{ repository_name }}", silent=True, nofail=True) + ctx.run( + "git remote add upstream git@github.com:{{ repository_namespace }}/{{ repository_name }}", + silent=True, + nofail=True, + allow_overrides=False, + ) ctx.run( tools.mkdocs.gh_deploy(remote_name="upstream", force=True), title="Deploying documentation", From 5c57d9213b22e3cebec01d3557ea779695bd50da Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Timoth=C3=A9e=20Mazzucotelli?= Date: Thu, 5 Sep 2024 16:11:43 +0200 Subject: [PATCH 06/21] refactor: Don't show source code in docs when insiders --- project/mkdocs.yml.jinja | 1 + 1 file changed, 1 insertion(+) diff --git a/project/mkdocs.yml.jinja b/project/mkdocs.yml.jinja index 9caf230..e69f1cc 100644 --- a/project/mkdocs.yml.jinja +++ b/project/mkdocs.yml.jinja @@ -140,6 +140,7 @@ plugins: show_root_heading: true show_root_full_path: false show_signature_annotations: true + show_source: {{ "false" if insiders else "true" }} show_symbol_type_heading: true show_symbol_type_toc: true signature_crossrefs: true From c4907eb96914914314bedf55d300179a790b827a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Timoth=C3=A9e=20Mazzucotelli?= Date: Thu, 5 Sep 2024 16:12:26 +0200 Subject: [PATCH 07/21] refactor: Enable Git revision date docs plugin, remove Git committers plugin (vendor lock-in, requires GitHub token) --- project/mkdocs.yml.jinja | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/project/mkdocs.yml.jinja b/project/mkdocs.yml.jinja index e69f1cc..d8cb12f 100644 --- a/project/mkdocs.yml.jinja +++ b/project/mkdocs.yml.jinja @@ -145,12 +145,10 @@ plugins: show_symbol_type_toc: true signature_crossrefs: true summary: true -- git-committers: +- git-revision-date-localized: enabled: !ENV [DEPLOY, false] - repository: {{ repository_namespace }}/{{ repository_name }} -{#- - git-revision-date-localized: enable_creation_date: true - type: timeago #} + type: timeago - minify: minify_html: !ENV [DEPLOY, false] - group: From d4dfab790dee59c335ac8907afd468a2cddd0169 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Timoth=C3=A9e=20Mazzucotelli?= Date: Thu, 5 Sep 2024 16:12:41 +0200 Subject: [PATCH 08/21] refactor: Improve clean command --- project/scripts/make | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/project/scripts/make b/project/scripts/make index e467d5c..c41840f 100755 --- a/project/scripts/make +++ b/project/scripts/make @@ -94,10 +94,10 @@ def clean() -> None: for path in paths_to_clean: shell(f"rm -rf {path}") - cache_dirs = [".cache", ".pytest_cache", ".mypy_cache", ".ruff_cache", "__pycache__"] - for dirpath in Path(".").rglob("*"): - if any(dirpath.match(pattern) for pattern in cache_dirs) and not (dirpath.match(".venv") or dirpath.match(".venvs")): - shutil.rmtree(path, ignore_errors=True) + cache_dirs = {".cache", ".pytest_cache", ".mypy_cache", ".ruff_cache", "__pycache__"} + for dirpath in Path(".").rglob("*/"): + if dirpath.parts[0] not in (".venv", ".venvs") and dirpath.name in cache_dirs: + shutil.rmtree(dirpath, ignore_errors=True) def vscode() -> None: From cd28e761b0cb2c9dd68b73bec5e07120d6fbb0bd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Timoth=C3=A9e=20Mazzucotelli?= Date: Thu, 5 Sep 2024 16:24:56 +0200 Subject: [PATCH 09/21] docs: Update changelog for version 1.4.1 --- CHANGELOG.md | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index b150f29..800a08d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,22 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/) and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html). +## [1.4.1](https://github.com/pawamoy/copier-uv/releases/tag/1.4.1) - 2024-09-05 + +[Compare with 1.4.0](https://github.com/pawamoy/copier-uv/compare/1.4.0...1.4.1) + +### Bug Fixes + +- Disallow overrides when getting Git remote in docs-deploy duty ([cb0135b](https://github.com/pawamoy/copier-uv/commit/cb0135bf5bc80768fea17366efba35293c60ba93) by Timothée Mazzucotelli). + +### Code Refactoring + +- Improve clean command ([d4dfab7](https://github.com/pawamoy/copier-uv/commit/d4dfab790dee59c335ac8907afd468a2cddd0169) by Timothée Mazzucotelli). +- Enable Git revision date docs plugin, remove Git committers plugin (vendor lock-in, requires GitHub token) ([c4907eb](https://github.com/pawamoy/copier-uv/commit/c4907eb96914914314bedf55d300179a790b827a) by Timothée Mazzucotelli). +- Don't show source code in docs when insiders ([5c57d92](https://github.com/pawamoy/copier-uv/commit/5c57d9213b22e3cebec01d3557ea779695bd50da) by Timothée Mazzucotelli). +- Clean up `check` duty (pre tasks) ([2e4dd5b](https://github.com/pawamoy/copier-uv/commit/2e4dd5b65ff49e45a6123a701ae572a6a15041aa) by Timothée Mazzucotelli). +- Use higher-level uv commands ([bf3c328](https://github.com/pawamoy/copier-uv/commit/bf3c328b8aefa1b5e33bb3bf55ff0039c9a436b1) by Timothée Mazzucotelli). + ## [1.4.0](https://github.com/pawamoy/copier-uv/releases/tag/1.4.0) - 2024-07-04 [Compare with 1.3.0](https://github.com/pawamoy/copier-uv/compare/1.3.0...1.4.0) From 46927885db4aad4658802707d1f34a129633b83e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Timoth=C3=A9e=20Mazzucotelli?= Date: Fri, 27 Sep 2024 14:52:26 +0200 Subject: [PATCH 10/21] refactor: Update ci and release workflows --- .github/workflows/ci.yml | 18 ++++++++++++++---- project/.github/workflows/ci.yml.jinja | 10 ++++++---- project/.github/workflows/release.yml.jinja | 6 +++--- 3 files changed, 23 insertions(+), 11 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 67cbfe5..379ac7b 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -81,8 +81,13 @@ jobs: python-version: ${{ matrix.python-version }} allow-prereleases: true - - name: Install Copier and uv - run: pip install copier copier-templates-extensions uv + - name: Setup uv + uses: astral-sh/setup-uv@v1 + with: + enable-cache: true + + - name: Install Copier + run: pip install copier copier-templates-extensions - name: Test project generation and workflow run: bash tests/test_project.sh @@ -106,8 +111,13 @@ jobs: with: python-version: "3.12" - - name: Install Copier and uv - run: pip install copier copier-templates-extensions uv + - name: Setup uv + uses: astral-sh/setup-uv@v1 + with: + enable-cache: true + + - name: Install Copier + run: pip install copier copier-templates-extensions - name: Trigger and wait project's own CI env: diff --git a/project/.github/workflows/ci.yml.jinja b/project/.github/workflows/ci.yml.jinja index 63136b8..5eb023e 100644 --- a/project/.github/workflows/ci.yml.jinja +++ b/project/.github/workflows/ci.yml.jinja @@ -29,13 +29,15 @@ jobs: - name: Fetch all tags run: git fetch --depth=1 --tags - - name: Set up Python + - name: Setup Python uses: actions/setup-python@v5 with: python-version: "3.11" - - name: Install uv - run: pip install uv + - name: Setup uv + uses: astral-sh/setup-uv@v1 + with: + enable-cache: true - name: Install dependencies run: make setup @@ -115,7 +117,7 @@ jobs: - name: Checkout uses: actions/checkout@v4 - - name: Set up Python + - name: Setup Python uses: actions/setup-python@v5 with: python-version: {% raw %}${{ matrix.python-version }}{% endraw %} diff --git a/project/.github/workflows/release.yml.jinja b/project/.github/workflows/release.yml.jinja index a869daa..c25597b 100644 --- a/project/.github/workflows/release.yml.jinja +++ b/project/.github/workflows/release.yml.jinja @@ -14,14 +14,14 @@ jobs: - name: Fetch all tags run: git fetch --depth=1 --tags - name: Setup Python - uses: actions/setup-python@v4 + uses: actions/setup-python@v5 {%- if insiders %} - name: Install build if: github.repository_owner == '{{ author_username }}-insiders' - run: python -m pip install build + run: pip install build - name: Build dists if: github.repository_owner == '{{ author_username }}-insiders' - run: python -m build + run: pyproject-build - name: Upload dists artifact uses: actions/upload-artifact@v4 if: github.repository_owner == '{{ author_username }}-insiders' From 896dfb39ea6710b3965fd3162fa9b621f916d166 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Timoth=C3=A9e=20Mazzucotelli?= Date: Fri, 27 Sep 2024 15:26:12 +0200 Subject: [PATCH 11/21] fix: Better handle `gh` command error (when fetching "Documentation" category ID for discussions) --- extensions.py | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/extensions.py b/extensions.py index f22af0e..078aa06 100644 --- a/extensions.py +++ b/extensions.py @@ -68,11 +68,21 @@ def hook(self, context): if self.repo_id is None: command = f"gh api repos/{repository_namespace}/{repository_name} --jq .node_id" - self.repo_id = subprocess.getoutput(command).strip() or self.repo_placeholder + try: + process = subprocess.run(command, shell=True, check=True, text=True, stdout=subprocess.PIPE, stderr=subprocess.DEVNULL) + except subprocess.CalledProcessError: + self.repo_id = self.repo_placeholder + else: + self.repo_id = process.stdout.strip() or self.repo_placeholder context["giscus_repo_id"] = self.repo_id if self.category_id is None: jq_filter = "--jq '.data.repository.discussionCategories.nodes[] | select(.name == \"Documentation\") | .id'" command = f"gh api graphql -f query='{self.query}' {jq_filter}" % {"owner": repository_namespace, "name": repository_name} - self.category_id = subprocess.getoutput(command).strip() or self.category_placeholder + try: + process = subprocess.run(command, shell=True, check=True, text=True, stdout=subprocess.PIPE, stderr=subprocess.DEVNULL) + except subprocess.CalledProcessError: + self.category_id = self.category_placeholder + else: + self.category_id = process.stdout.strip() or self.category_placeholder context["giscus_discussion_category_id"] = self.category_id From fb2d373b217c1d3c216b01f82e3db5c2f1542558 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Timoth=C3=A9e=20Mazzucotelli?= Date: Fri, 27 Sep 2024 15:26:35 +0200 Subject: [PATCH 12/21] fix: Better flush help message for make script --- project/scripts/make | 28 ++++++++++++++++++---------- 1 file changed, 18 insertions(+), 10 deletions(-) diff --git a/project/scripts/make b/project/scripts/make index c41840f..cbe6006 100755 --- a/project/scripts/make +++ b/project/scripts/make @@ -9,6 +9,7 @@ import subprocess import sys from contextlib import contextmanager from pathlib import Path +from textwrap import dedent from typing import Any, Iterator PYTHON_VERSIONS = os.getenv("PYTHON_VERSIONS", "3.8 3.9 3.10 3.11 3.12 3.13").split() @@ -113,17 +114,24 @@ def main() -> int: if len(args) > 1: run("default", "duty", "--help", args[1]) else: - print("Available commands") # noqa: T201 - print(" help Print this help. Add task name to print help.") # noqa: T201 - print(" setup Setup all virtual environments (install dependencies).") # noqa: T201 - print(" run Run a command in the default virtual environment.") # noqa: T201 - print(" multirun Run a command for all configured Python versions.") # noqa: T201 - print(" allrun Run a command in all virtual environments.") # noqa: T201 - print(" 3.x Run a command in the virtual environment for Python 3.x.") # noqa: T201 - print(" clean Delete build artifacts and cache files.") # noqa: T201 - print(" vscode Configure VSCode to work on this project.") # noqa: T201 + print( + dedent( + """ + Available commands + help Print this help. Add task name to print help. + setup Setup all virtual environments (install dependencies). + run Run a command in the default virtual environment. + multirun Run a command for all configured Python versions. + allrun Run a command in all virtual environments. + 3.x Run a command in the virtual environment for Python 3.x. + clean Delete build artifacts and cache files. + vscode Configure VSCode to work on this project. + """ + ), + flush=True, + ) # noqa: T201 if os.path.exists(".venv"): - print("\nAvailable tasks") # noqa: T201 + print("\nAvailable tasks", flush=True) # noqa: T201 run("default", "duty", "--list") return 0 From 4900e844cdcb8c56442d6a91499cfbd44771587d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Timoth=C3=A9e=20Mazzucotelli?= Date: Fri, 27 Sep 2024 16:08:00 +0200 Subject: [PATCH 13/21] docs: Update changelog for version 1.4.2 --- CHANGELOG.md | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 800a08d..58862af 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,19 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/) and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html). +## [1.4.2](https://github.com/pawamoy/copier-uv/releases/tag/1.4.2) - 2024-09-27 + +[Compare with 1.4.1](https://github.com/pawamoy/copier-uv/compare/1.4.1...1.4.2) + +### Bug Fixes + +- Better flush help message for make script ([fb2d373](https://github.com/pawamoy/copier-uv/commit/fb2d373b217c1d3c216b01f82e3db5c2f1542558) by Timothée Mazzucotelli). +- Better handle `gh` command error (when fetching "Documentation" category ID for discussions) ([896dfb3](https://github.com/pawamoy/copier-uv/commit/896dfb39ea6710b3965fd3162fa9b621f916d166) by Timothée Mazzucotelli). + +### Code Refactoring + +- Update ci and release workflows ([4692788](https://github.com/pawamoy/copier-uv/commit/46927885db4aad4658802707d1f34a129633b83e) by Timothée Mazzucotelli). + ## [1.4.1](https://github.com/pawamoy/copier-uv/releases/tag/1.4.1) - 2024-09-05 [Compare with 1.4.0](https://github.com/pawamoy/copier-uv/compare/1.4.0...1.4.1) From d26e9fa99f715e41642d26a32403fc934da4391d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Timoth=C3=A9e=20Mazzucotelli?= Date: Fri, 27 Sep 2024 19:54:10 +0200 Subject: [PATCH 14/21] refactor: Upgrade gh-release action version --- .github/workflows/release.yml | 2 +- project/.github/workflows/release.yml.jinja | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 9764e67..331aa50 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -23,6 +23,6 @@ jobs: - name: Prepare release notes run: git-changelog --release-notes > release-notes.md - name: Create release - uses: softprops/action-gh-release@v1 + uses: softprops/action-gh-release@v2 with: body_path: release-notes.md diff --git a/project/.github/workflows/release.yml.jinja b/project/.github/workflows/release.yml.jinja index c25597b..10324c8 100644 --- a/project/.github/workflows/release.yml.jinja +++ b/project/.github/workflows/release.yml.jinja @@ -35,12 +35,12 @@ jobs: if: github.repository_owner != '{{ author_username }}-insiders' run: git-changelog --release-notes > release-notes.md - name: Create release with assets - uses: softprops/action-gh-release@v1 + uses: softprops/action-gh-release@v2 if: github.repository_owner == '{{ author_username }}-insiders' with: files: ./dist/* - name: Create release - uses: softprops/action-gh-release@v1 + uses: softprops/action-gh-release@v2 if: github.repository_owner != '{{ author_username }}-insiders' with: body_path: release-notes.md @@ -50,7 +50,7 @@ jobs: - name: Prepare release notes run: git-changelog --release-notes > release-notes.md - name: Create release - uses: softprops/action-gh-release@v1 + uses: softprops/action-gh-release@v2 with: body_path: release-notes.md {%- endif %} From 61a575a88cd9f4ec0411e03444187dc7cf379136 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Timoth=C3=A9e=20Mazzucotelli?= Date: Fri, 27 Sep 2024 19:54:22 +0200 Subject: [PATCH 15/21] ci: Ignore failure to delete release in testing repository --- tests/wait_ci.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/wait_ci.sh b/tests/wait_ci.sh index fda9991..328f9ce 100644 --- a/tests/wait_ci.sh +++ b/tests/wait_ci.sh @@ -36,5 +36,5 @@ done echo "Deleting all testing releases..." for tag in $(gh release list --repo pawamoy/pawamoy-testing --json tagName --jq ".[].tagName"); do - gh release delete "${tag}" --repo pawamoy/pawamoy-testing --yes --cleanup-tag + gh release delete "${tag}" --repo pawamoy/pawamoy-testing --yes --cleanup-tag || true done \ No newline at end of file From cd71812b76297ce8b6596f2c299788423100b654 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Timoth=C3=A9e=20Mazzucotelli?= Date: Fri, 27 Sep 2024 19:54:35 +0200 Subject: [PATCH 16/21] docs: Update changelog for version 1.4.3 --- CHANGELOG.md | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 58862af..079709c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,14 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/) and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html). +## [1.4.3](https://github.com/pawamoy/copier-uv/releases/tag/1.4.3) - 2024-09-27 + +[Compare with 1.4.2](https://github.com/pawamoy/copier-uv/compare/1.4.2...1.4.3) + +### Code Refactoring + +- Upgrade gh-release action version ([d26e9fa](https://github.com/pawamoy/copier-uv/commit/d26e9fa99f715e41642d26a32403fc934da4391d) by Timothée Mazzucotelli). + ## [1.4.2](https://github.com/pawamoy/copier-uv/releases/tag/1.4.2) - 2024-09-27 [Compare with 1.4.1](https://github.com/pawamoy/copier-uv/compare/1.4.1...1.4.2) From cc2c350d6f2c42025ed84afa5740a767ff82510b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Timoth=C3=A9e=20Mazzucotelli?= Date: Fri, 27 Sep 2024 20:01:02 +0200 Subject: [PATCH 17/21] refactor: Upgrade setup-uv action version --- .github/workflows/ci.yml | 4 ++-- project/.github/workflows/ci.yml.jinja | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 379ac7b..962b47c 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -82,7 +82,7 @@ jobs: allow-prereleases: true - name: Setup uv - uses: astral-sh/setup-uv@v1 + uses: astral-sh/setup-uv@v3 with: enable-cache: true @@ -112,7 +112,7 @@ jobs: python-version: "3.12" - name: Setup uv - uses: astral-sh/setup-uv@v1 + uses: astral-sh/setup-uv@v3 with: enable-cache: true diff --git a/project/.github/workflows/ci.yml.jinja b/project/.github/workflows/ci.yml.jinja index 5eb023e..e06e6e1 100644 --- a/project/.github/workflows/ci.yml.jinja +++ b/project/.github/workflows/ci.yml.jinja @@ -35,7 +35,7 @@ jobs: python-version: "3.11" - name: Setup uv - uses: astral-sh/setup-uv@v1 + uses: astral-sh/setup-uv@v3 with: enable-cache: true @@ -124,7 +124,7 @@ jobs: allow-prereleases: true - name: Setup uv - uses: astral-sh/setup-uv@v1 + uses: astral-sh/setup-uv@v3 with: enable-cache: true From 078fd1dde963db83615bf156d93f8d19686f5b64 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Timoth=C3=A9e=20Mazzucotelli?= Date: Fri, 27 Sep 2024 20:01:12 +0200 Subject: [PATCH 18/21] docs: Update changelog for version 1.4.4 --- CHANGELOG.md | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 079709c..08d8778 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,14 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/) and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html). +## [1.4.4](https://github.com/pawamoy/copier-uv/releases/tag/1.4.4) - 2024-09-27 + +[Compare with 1.4.3](https://github.com/pawamoy/copier-uv/compare/1.4.3...1.4.4) + +### Code Refactoring + +- Upgrade setup-uv action version ([cc2c350](https://github.com/pawamoy/copier-uv/commit/cc2c350d6f2c42025ed84afa5740a767ff82510b) by Timothée Mazzucotelli). + ## [1.4.3](https://github.com/pawamoy/copier-uv/releases/tag/1.4.3) - 2024-09-27 [Compare with 1.4.2](https://github.com/pawamoy/copier-uv/compare/1.4.2...1.4.3) From b78ce880c56b3e346d5b414bda89ac4a8cd22335 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Timoth=C3=A9e=20Mazzucotelli?= Date: Fri, 27 Sep 2024 21:46:28 +0200 Subject: [PATCH 19/21] fix: Invalidate uv cache based on pyproject.toml --- .github/workflows/ci.yml | 3 +++ project/.github/workflows/ci.yml.jinja | 3 +++ 2 files changed, 6 insertions(+) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 962b47c..762a449 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -85,6 +85,8 @@ jobs: uses: astral-sh/setup-uv@v3 with: enable-cache: true + cache-dependency-glob: project/pyproject.toml.jinja + cache-suffix: py${{ matrix.python-version }} - name: Install Copier run: pip install copier copier-templates-extensions @@ -115,6 +117,7 @@ jobs: uses: astral-sh/setup-uv@v3 with: enable-cache: true + cache-dependency-glob: project/pyproject.toml.jinja - name: Install Copier run: pip install copier copier-templates-extensions diff --git a/project/.github/workflows/ci.yml.jinja b/project/.github/workflows/ci.yml.jinja index e06e6e1..80bc2b6 100644 --- a/project/.github/workflows/ci.yml.jinja +++ b/project/.github/workflows/ci.yml.jinja @@ -38,6 +38,7 @@ jobs: uses: astral-sh/setup-uv@v3 with: enable-cache: true + cache-dependency-glob: pyproject.toml - name: Install dependencies run: make setup @@ -127,6 +128,8 @@ jobs: uses: astral-sh/setup-uv@v3 with: enable-cache: true + cache-dependency-glob: pyproject.toml + cache-suffix: {% raw %}py${{ matrix.python-version }}{% endraw %} - name: Install dependencies env: From addb51ed8daaeb19d40cd02665f8fc68bb02f4b8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Timoth=C3=A9e=20Mazzucotelli?= Date: Fri, 27 Sep 2024 21:58:20 +0200 Subject: [PATCH 20/21] fix: Fix make help message indentation --- project/scripts/make | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/project/scripts/make b/project/scripts/make index cbe6006..cf02221 100755 --- a/project/scripts/make +++ b/project/scripts/make @@ -118,14 +118,14 @@ def main() -> int: dedent( """ Available commands - help Print this help. Add task name to print help. - setup Setup all virtual environments (install dependencies). - run Run a command in the default virtual environment. - multirun Run a command for all configured Python versions. - allrun Run a command in all virtual environments. - 3.x Run a command in the virtual environment for Python 3.x. - clean Delete build artifacts and cache files. - vscode Configure VSCode to work on this project. + help Print this help. Add task name to print help. + setup Setup all virtual environments (install dependencies). + run Run a command in the default virtual environment. + multirun Run a command for all configured Python versions. + allrun Run a command in all virtual environments. + 3.x Run a command in the virtual environment for Python 3.x. + clean Delete build artifacts and cache files. + vscode Configure VSCode to work on this project. """ ), flush=True, From 537a2c5294adb4e849ab5ba4bbfa7140eed336e7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Timoth=C3=A9e=20Mazzucotelli?= Date: Fri, 27 Sep 2024 21:58:30 +0200 Subject: [PATCH 21/21] docs: Update changelog for version 1.4.5 --- CHANGELOG.md | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 08d8778..374f6ca 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,15 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/) and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html). +## [1.4.5](https://github.com/pawamoy/copier-uv/releases/tag/1.4.5) - 2024-09-27 + +[Compare with 1.4.4](https://github.com/pawamoy/copier-uv/compare/1.4.4...1.4.5) + +### Bug Fixes + +- Fix make help message indentation ([addb51e](https://github.com/pawamoy/copier-uv/commit/addb51ed8daaeb19d40cd02665f8fc68bb02f4b8) by Timothée Mazzucotelli). +- Invalidate uv cache based on pyproject.toml ([b78ce88](https://github.com/pawamoy/copier-uv/commit/b78ce880c56b3e346d5b414bda89ac4a8cd22335) by Timothée Mazzucotelli). + ## [1.4.4](https://github.com/pawamoy/copier-uv/releases/tag/1.4.4) - 2024-09-27 [Compare with 1.4.3](https://github.com/pawamoy/copier-uv/compare/1.4.3...1.4.4)