From 199c7e56e0b8f17aa36ab0624a44fd0ef16f1c0d Mon Sep 17 00:00:00 2001 From: Kyle King Date: Sun, 17 Nov 2024 20:11:49 -0500 Subject: [PATCH 1/6] test(#34): add CI for Windows --- .github/workflows/usage_test.yml | 35 +++++++++++++++++++++ tests/data/ci_usage_test/copier.yaml | 5 +++ tests/data/ci_usage_test/ctt.toml | 3 ++ tests/data/ci_usage_test/template/README.md | 3 ++ 4 files changed, 46 insertions(+) create mode 100644 .github/workflows/usage_test.yml create mode 100644 tests/data/ci_usage_test/copier.yaml create mode 100644 tests/data/ci_usage_test/ctt.toml create mode 100644 tests/data/ci_usage_test/template/README.md diff --git a/.github/workflows/usage_test.yml b/.github/workflows/usage_test.yml new file mode 100644 index 0000000..f80342c --- /dev/null +++ b/.github/workflows/usage_test.yml @@ -0,0 +1,35 @@ +--- +name: CI Pipeline + +"on": + push: + branches: [main] + pull_request: + branches: [main] + paths: + - .github/workflows/usage_test.yml + - copier_template_tester/** + - tests/** + - poetry.lock + - pyproject.toml + +jobs: + lint: + runs-on: ${{ matrix.os }} + strategy: + matrix: + os: [windows-latest] + python-version: ["3.10"] + steps: + - uses: actions/checkout@v4 + - uses: ./.github/actions/setup + with: + os: ${{ matrix.os }} + python-version: ${{ matrix.python-version }} + + - name: "Run Usage Test (Specifically addresses #34 for Windows)" + run: | + poetry run ctt --base-dir="$TEST_DIR" + cat "$TEST_DIR/.ctt/README.md" + env: + TEST_DIR: tests/data/ci_usage_test diff --git a/tests/data/ci_usage_test/copier.yaml b/tests/data/ci_usage_test/copier.yaml new file mode 100644 index 0000000..7f90f4f --- /dev/null +++ b/tests/data/ci_usage_test/copier.yaml @@ -0,0 +1,5 @@ +_subdirectory: template +# questionnaire here... +_tasks: + - git init + - git add . diff --git a/tests/data/ci_usage_test/ctt.toml b/tests/data/ci_usage_test/ctt.toml new file mode 100644 index 0000000..b391ce4 --- /dev/null +++ b/tests/data/ci_usage_test/ctt.toml @@ -0,0 +1,3 @@ +# Minimal Configuration + +[output.".ctt"] diff --git a/tests/data/ci_usage_test/template/README.md b/tests/data/ci_usage_test/template/README.md new file mode 100644 index 0000000..811230b --- /dev/null +++ b/tests/data/ci_usage_test/template/README.md @@ -0,0 +1,3 @@ +# CI Usage Test + +Test usage as part of CI. See associated Github Action From 147657b87f67affda034020d088167f74117cd46 Mon Sep 17 00:00:00 2001 From: Kyle King Date: Sun, 17 Nov 2024 20:17:51 -0500 Subject: [PATCH 2/6] ci: fix usage test --- .github/workflows/usage_test.yml | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/.github/workflows/usage_test.yml b/.github/workflows/usage_test.yml index f80342c..24be24a 100644 --- a/.github/workflows/usage_test.yml +++ b/.github/workflows/usage_test.yml @@ -1,5 +1,5 @@ --- -name: CI Pipeline +name: CTT Usage Test "on": push: @@ -14,7 +14,7 @@ name: CI Pipeline - pyproject.toml jobs: - lint: + usage-test: runs-on: ${{ matrix.os }} strategy: matrix: @@ -29,7 +29,5 @@ jobs: - name: "Run Usage Test (Specifically addresses #34 for Windows)" run: | - poetry run ctt --base-dir="$TEST_DIR" - cat "$TEST_DIR/.ctt/README.md" - env: - TEST_DIR: tests/data/ci_usage_test + poetry run ctt --base-dir="tests/data/ci_usage_test" + cat "tests/data/ci_usage_test/.ctt/README.md" From 223f0a7838cfd81de8d2e7add475592ba67454f5 Mon Sep 17 00:00:00 2001 From: Kyle King Date: Tue, 19 Nov 2024 06:23:49 -0500 Subject: [PATCH 3/6] fix(#34): remove readonly directories --- copier_template_tester/_write_output.py | 23 ++++++++++++++++++++++- docs/docs/DEVELOPER_GUIDE.md | 6 +++--- 2 files changed, 25 insertions(+), 4 deletions(-) diff --git a/copier_template_tester/_write_output.py b/copier_template_tester/_write_output.py index 9c9e7ad..0af06da 100644 --- a/copier_template_tester/_write_output.py +++ b/copier_template_tester/_write_output.py @@ -2,6 +2,8 @@ import re import shutil +import stat +import sys from contextlib import contextmanager, suppress from functools import lru_cache from pathlib import Path @@ -120,6 +122,22 @@ def _output_dir(*, src_path: Path, dst_path: Path): # noqa: ANN202 answers_path.unlink() +def _remove_readonly(func, path, _excinfo) -> None: # noqa: ANN001 + """Clear the readonly bit for `shutil.rmtree(..., onexc=_remove_readonly)`. + + Adapted from: https://docs.python.org/3/library/shutil.html#rmtree-example + + Resolves: https://github.com/KyleKing/copier-template-tester/issues/34 + + The first parameter, function, is the function which raised the exception; it depends on the platform and + implementation. The second parameter, path, will be the path name passed to function. The third parameter, + excinfo, is the exception that was raised. Exceptions raised by onexc will not be caught. + + """ + Path.chmod(path, stat.S_IWRITE) + func(path) + + def write_output(*, src_path: Path, dst_path: Path, data: dict[str, bool | int | float | str | None], **kwargs) -> None: """Copy the specified directory to the target location with provided data. @@ -141,4 +159,7 @@ def write_output(*, src_path: Path, dst_path: Path, data: dict[str, bool | int | git_path = dst_path / '.git' if git_path.is_dir(): # pragma: no cover logger.info('Removing git created by copier', git_path=git_path) - shutil.rmtree(git_path) + if sys.version_info >= (3, 12, 0): + shutil.rmtree(git_path, onexc=_remove_readonly) # type: ignore[call-arg] + else: + shutil.rmtree(git_path, onerror=_remove_readonly) diff --git a/docs/docs/DEVELOPER_GUIDE.md b/docs/docs/DEVELOPER_GUIDE.md index 9cc11ad..8d08691 100644 --- a/docs/docs/DEVELOPER_GUIDE.md +++ b/docs/docs/DEVELOPER_GUIDE.md @@ -51,9 +51,9 @@ poetry config pypi-token.pypi ... | `copier_template_tester/_config.py` | 14 | 0 | 3 | 100.0% | | `copier_template_tester/_pre_commit_support.py` | 13 | 0 | 0 | 93.3% | | `copier_template_tester/_runtime_type_check_setup.py` | 13 | 0 | 37 | 100.0% | -| `copier_template_tester/_write_output.py` | 76 | 0 | 13 | 100.0% | +| `copier_template_tester/_write_output.py` | 81 | 1 | 16 | 98.9% | | `copier_template_tester/main.py` | 30 | 4 | 20 | 86.7% | -| **Totals** | 150 | 4 | 73 | 97.0% | +| **Totals** | 155 | 5 | 76 | 96.4% | -Generated on: 2024-11-17 +Generated on: 2024-11-19 From d47cab59a953b58e55da2f5eb1e052d605f0fa90 Mon Sep 17 00:00:00 2001 From: Kyle King Date: Tue, 19 Nov 2024 06:24:34 -0500 Subject: [PATCH 4/6] docs: add code tags --- docs/docs/CODE_TAG_SUMMARY.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/docs/CODE_TAG_SUMMARY.md b/docs/docs/CODE_TAG_SUMMARY.md index 41b7731..8aaf7fd 100644 --- a/docs/docs/CODE_TAG_SUMMARY.md +++ b/docs/docs/CODE_TAG_SUMMARY.md @@ -2,7 +2,7 @@ | Type | Comment | Last Edit | Source File | |---------|-----------------------------------------------------------------------|------------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| -| PLANNED | In python 3.10, there is a Beartype error for this return annotation: | 2023-10-14 | [copier_template_tester/_write_output.py:96](https://github.com/KyleKing/copier-template-tester/blame/57f881822440c37e163312269c0d5893da21cd55/copier_template_tester/_write_output.py#L92) | +| PLANNED | In python 3.10, there is a Beartype error for this return annotation: | 2023-10-14 | [copier_template_tester/_write_output.py:98](https://github.com/KyleKing/copier-template-tester/blame/57f881822440c37e163312269c0d5893da21cd55/copier_template_tester/_write_output.py#L92) | | PLANNED | document | 2024-11-18 | [pyproject.toml:87](https://github.com/KyleKing/copier-template-tester/blame/d0e5d3c674c533d47cdec43aa4b18fce7ec0cb89/pyproject.toml#L87) | | PLANNED | document | 2024-11-18 | [pyproject.toml:88](https://github.com/KyleKing/copier-template-tester/blame/d0e5d3c674c533d47cdec43aa4b18fce7ec0cb89/pyproject.toml#L88) | | PLANNED | document | 2024-11-18 | [pyproject.toml:89](https://github.com/KyleKing/copier-template-tester/blame/d0e5d3c674c533d47cdec43aa4b18fce7ec0cb89/pyproject.toml#L89) | From 9abe5f60759d10ad2575ba22bf75cb67f5f7b265 Mon Sep 17 00:00:00 2001 From: Kyle King Date: Tue, 19 Nov 2024 06:31:26 -0500 Subject: [PATCH 5/6] ci: add missing [defaults] section --- tests/data/ci_usage_test/ctt.toml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tests/data/ci_usage_test/ctt.toml b/tests/data/ci_usage_test/ctt.toml index b391ce4..5758215 100644 --- a/tests/data/ci_usage_test/ctt.toml +++ b/tests/data/ci_usage_test/ctt.toml @@ -1,3 +1,5 @@ # Minimal Configuration +[defaults] + [output.".ctt"] From ad8dc5f89d3b2fc01a6aab0cea6808f1c5fa7255 Mon Sep 17 00:00:00 2001 From: Kyle King Date: Tue, 19 Nov 2024 06:59:44 -0500 Subject: [PATCH 6/6] fix: convert string to Path --- copier_template_tester/_write_output.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/copier_template_tester/_write_output.py b/copier_template_tester/_write_output.py index 0af06da..f1cb957 100644 --- a/copier_template_tester/_write_output.py +++ b/copier_template_tester/_write_output.py @@ -122,7 +122,7 @@ def _output_dir(*, src_path: Path, dst_path: Path): # noqa: ANN202 answers_path.unlink() -def _remove_readonly(func, path, _excinfo) -> None: # noqa: ANN001 +def _remove_readonly(func, path: str, _excinfo) -> None: # noqa: ANN001 """Clear the readonly bit for `shutil.rmtree(..., onexc=_remove_readonly)`. Adapted from: https://docs.python.org/3/library/shutil.html#rmtree-example @@ -134,7 +134,7 @@ def _remove_readonly(func, path, _excinfo) -> None: # noqa: ANN001 excinfo, is the exception that was raised. Exceptions raised by onexc will not be caught. """ - Path.chmod(path, stat.S_IWRITE) + Path.chmod(Path(path), stat.S_IWRITE) func(path)