From 2379cbf767767f8a335e7c83071fb7da9fdb7927 Mon Sep 17 00:00:00 2001 From: "Ware, Joseph (DLSLtd,RAL,LSCI)" Date: Wed, 18 Jun 2025 16:15:44 +0100 Subject: [PATCH 1/4] fix: Remove need for --trust --- .github/workflows/_example.yml | 2 +- README.md | 6 +++--- copier.yml | 3 --- docs/how-to/update-template.md | 4 ++-- docs/tutorials/adopt-existing.md | 6 +++--- docs/tutorials/create-new.md | 4 ++-- tests/test_example.py | 2 +- 7 files changed, 12 insertions(+), 15 deletions(-) diff --git a/.github/workflows/_example.yml b/.github/workflows/_example.yml index ea14af9e..193691ac 100644 --- a/.github/workflows/_example.yml +++ b/.github/workflows/_example.yml @@ -16,7 +16,7 @@ jobs: - name: Regenerate example run: | - pipx run copier copy --data-file example-answers.yml --trust --vcs-ref=HEAD . example + pipx run copier copy --data-file example-answers.yml --vcs-ref=HEAD . example - name: Rewrite copier answers run: | diff --git a/README.md b/README.md index 082e48b0..3a2ae05c 100644 --- a/README.md +++ b/README.md @@ -46,9 +46,9 @@ Visit and you will see a list of templ You will need to `pip install copier` inside an activated `venv` from python3.11 or later, then you can create a new module via: ``` -mkdir /path/to/my-project -# The --trust argument is required to run setup tasks such as initializing a git repository -copier copy --trust https://github.com/DiamondLightSource/python-copier-template.git /path/to/my-project +git init --initial-branch=main /path/to/my-project +# $_ resolves to /path/to/my-project +copier copy https://github.com/DiamondLightSource/python-copier-template.git $_ ``` You can also use it via `pipx run copier` if you have that installed. diff --git a/copier.yml b/copier.yml index ea1ecc1e..ac63bfda 100644 --- a/copier.yml +++ b/copier.yml @@ -156,9 +156,6 @@ sphinx: _subdirectory: "template" -_tasks: - - "git init --initial-branch=main" - _migrations: - version: 2.0.0 before: diff --git a/docs/how-to/update-template.md b/docs/how-to/update-template.md index cfb5829b..5bd1de0f 100644 --- a/docs/how-to/update-template.md +++ b/docs/how-to/update-template.md @@ -5,7 +5,7 @@ To track changes to the upstream template, run ``` -copier update --trust +copier update ``` This will fetch the latest tagged release of the template, and apply any changes to your working copy. It will prompt for answers again, giving your previous answers as the defaults. @@ -32,7 +32,7 @@ The following steps are recommended to update your project, especially for infre - fix issues found by the above - commit the changes - update the template - - `copier update --trust` + - `copier update` - fix any merge conflicts - validate that the project still works - `tox -p` diff --git a/docs/tutorials/adopt-existing.md b/docs/tutorials/adopt-existing.md index 1832869b..626f97d1 100644 --- a/docs/tutorials/adopt-existing.md +++ b/docs/tutorials/adopt-existing.md @@ -18,11 +18,11 @@ Copier will *overwrite* files with the template files. Please check the changes If you have a [python3-pip-skeleton](https://github.com/DiamondLightSource/python3-pip-skeleton) based project then it is best to adopt the `1.0.0` release of this template, then `copier update` to get to the latest. This is because `copier update` will try and merge file changes across renames done between releases, while `copier copy` cannot. This looks like: ```shell -copier copy https://github.com/DiamondLightSource/python-copier-template.git --trust --vcs-ref=1.0.0 /path/to/existing-project +copier copy https://github.com/DiamondLightSource/python-copier-template.git --vcs-ref=1.0.0 /path/to/existing-project git diff # Examine the changes, put back anything you want to keep git commit -m "Adopt python-copier-template 1.0.0" -copier update --trust /path/to/existing-project +copier update /path/to/existing-project git diff # Examine the changes, resolve any merge conflicts git commit -m "Update to python-copier-template x.x.x" @@ -33,7 +33,7 @@ git commit -m "Update to python-copier-template x.x.x" If you have a project with a different structure then it is best to go straight to the latest release: ```shell -copier copy --trust https://github.com/DiamondLightSource/python-copier-template.git /path/to/existing-project +copier copy https://github.com/DiamondLightSource/python-copier-template.git /path/to/existing-project git diff # Examine the changes, put back anything you want to keep git commit -m "Adopt python-copier-template x.x.x" diff --git a/docs/tutorials/create-new.md b/docs/tutorials/create-new.md index ed5c49da..21d5474d 100644 --- a/docs/tutorials/create-new.md +++ b/docs/tutorials/create-new.md @@ -3,8 +3,8 @@ Once you have followed the [](./installation) tutorial, you can use `copier` to make a new project from the template: ``` -$ mkdir /path/to/my-project -$ copier copy --trust https://github.com/DiamondLightSource/python-copier-template.git /path/to/my-project +$ git init --initial-branch=main /path/to/my-project +$ copier copy https://github.com/DiamondLightSource/python-copier-template.git $_ ``` This will: diff --git a/tests/test_example.py b/tests/test_example.py index a8c0f9ac..f8d36109 100644 --- a/tests/test_example.py +++ b/tests/test_example.py @@ -170,7 +170,7 @@ def test_example_repo_updates(tmp_path: Path): run("git config user.email 'you@example.com'") run("git config user.name 'Your Name'") run("git commit -am 'Update src'") - run(f"copier update --trust --vcs-ref=HEAD --data-file {TOP}/example-answers.yml") + run(f"copier update --vcs-ref=HEAD --data-file {TOP}/example-answers.yml") output = run( # Git directory expected to be different "diff -ur --exclude=.git " From bdfb067aa1b57088856ebe7605980d7e3c845473 Mon Sep 17 00:00:00 2001 From: "Ware, Joseph (DLSLtd,RAL,LSCI)" Date: Wed, 18 Jun 2025 16:40:50 +0100 Subject: [PATCH 2/4] Fix tests that use current (i.e. trust-requiring) released version --- tests/test_example.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/tests/test_example.py b/tests/test_example.py index f8d36109..7bb49491 100644 --- a/tests/test_example.py +++ b/tests/test_example.py @@ -10,16 +10,17 @@ TOP = Path(__file__).absolute().parent.parent -def copy_project(project_path: Path, **kwargs): +def copy_project(project_path: Path, trust: bool = False, **kwargs): with open(TOP / "example-answers.yml") as f: answers = yaml.safe_load(f) answers.update(kwargs) + run_pipe(f"git init {project_path}") run_copy( src_path=str(TOP), dst_path=project_path, data=answers, vcs_ref="HEAD", - unsafe=True, + unsafe=trust, ) run_pipe("git add .", cwd=str(project_path)) @@ -159,7 +160,7 @@ def test_example_repo_updates(tmp_path: Path): "https://github.com/DiamondLightSource/python-copier-template-example.git" ) example_path = tmp_path / "example" - copy_project(generated_path) + copy_project(generated_path, trust=True) run_pipe(f"git clone {example_url} {example_path}") with open(example_path / ".copier-answers.yml") as f: d = yaml.safe_load(f) @@ -170,7 +171,7 @@ def test_example_repo_updates(tmp_path: Path): run("git config user.email 'you@example.com'") run("git config user.name 'Your Name'") run("git commit -am 'Update src'") - run(f"copier update --vcs-ref=HEAD --data-file {TOP}/example-answers.yml") + run(f"copier update --vcs-ref=HEAD --data-file {TOP}/example-answers.yml --trust") output = run( # Git directory expected to be different "diff -ur --exclude=.git " From 71af4a20b08ec8dbc1b91c89357da02020c3c69d Mon Sep 17 00:00:00 2001 From: Joseph Ware <53935796+DiamondJoseph@users.noreply.github.com> Date: Thu, 19 Jun 2025 09:44:17 +0100 Subject: [PATCH 3/4] Update tests/test_example.py --- tests/test_example.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/test_example.py b/tests/test_example.py index 7bb49491..3bfe1f61 100644 --- a/tests/test_example.py +++ b/tests/test_example.py @@ -171,7 +171,7 @@ def test_example_repo_updates(tmp_path: Path): run("git config user.email 'you@example.com'") run("git config user.name 'Your Name'") run("git commit -am 'Update src'") - run(f"copier update --vcs-ref=HEAD --data-file {TOP}/example-answers.yml --trust") + run(f"copier update --trust --vcs-ref=HEAD --data-file {TOP}/example-answers.yml") output = run( # Git directory expected to be different "diff -ur --exclude=.git " From 8d131f8a345dcb4a1d5e9afad844a0376892f9a3 Mon Sep 17 00:00:00 2001 From: Joseph Ware <53935796+DiamondJoseph@users.noreply.github.com> Date: Thu, 19 Jun 2025 09:44:24 +0100 Subject: [PATCH 4/4] Update docs/tutorials/adopt-existing.md --- docs/tutorials/adopt-existing.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/tutorials/adopt-existing.md b/docs/tutorials/adopt-existing.md index 626f97d1..7e4ff39b 100644 --- a/docs/tutorials/adopt-existing.md +++ b/docs/tutorials/adopt-existing.md @@ -18,7 +18,7 @@ Copier will *overwrite* files with the template files. Please check the changes If you have a [python3-pip-skeleton](https://github.com/DiamondLightSource/python3-pip-skeleton) based project then it is best to adopt the `1.0.0` release of this template, then `copier update` to get to the latest. This is because `copier update` will try and merge file changes across renames done between releases, while `copier copy` cannot. This looks like: ```shell -copier copy https://github.com/DiamondLightSource/python-copier-template.git --vcs-ref=1.0.0 /path/to/existing-project +copier copy https://github.com/DiamondLightSource/python-copier-template.git --trust --vcs-ref=1.0.0 /path/to/existing-project git diff # Examine the changes, put back anything you want to keep git commit -m "Adopt python-copier-template 1.0.0"