Skip to content

Commit 7548239

Browse files
authored
Merge pull request #444 from NLeSC/416-instructions-update-existing
README: Update usage instructions
2 parents 83c590d + 399a7a1 commit 7548239

File tree

3 files changed

+73
-38
lines changed

3 files changed

+73
-38
lines changed

.github/PULL_REQUEST_TEMPLATE.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ Create a `python-template-test` repo on GitHub (will be overwritten if existing)
1818
```
1919
# Create a temporary directory by running the following command. Keep the XXXXXX in the directory name.
2020
cd $(mktemp -d --tmpdir py-tmpl-XXXXXX)
21-
# Use --vcs-ref <pr-branch> to point to the branch to you want to test
21+
# Use --vcs-ref <pr-branch> to point to the branch you want to test
2222
copier copy --vcs-ref <pr-branch> https://github.com/<pr-user>/python-template .
2323
# Fill with python-template-test info
2424
# Create a local git repo to push to GitHub to trigger CI actions

ADD_TO_EXISTING_PACKAGE.md

Lines changed: 0 additions & 29 deletions
This file was deleted.

README.md

Lines changed: 72 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -42,20 +42,38 @@ Use this [Copier](https://copier.readthedocs.io) template to generate an empty P
4242

4343
## How to use
4444

45-
### Step 1/3: Install `copier`
45+
There are multiple scenarios to use this template:
4646

47+
- [Scenario 1](#scenario-1-create-a-new-package): Generating a new package using template
48+
- [Scenario 2](#scenario-2-apply-to-pre-existing-code): Applying the template to some pre-existing code
49+
- [Scenario 3](#scenario-3-updating-a-template-made-package): Updating a package made with the template
50+
51+
In all three scenarios, you will need to install Copier first, which we
52+
recommend doing with [`pipx`](https://github.com/pypa/pipx):
4753
```shell
54+
python3 -m pip install --user pipx
55+
python3 -m pipx ensurepath
4856
pipx install copier
4957
```
5058

51-
### Step 2/3: Generate the files and directory structure
59+
> [!NOTE]
60+
> Note that it is also possible to install Copier with regular `pip`, but that
61+
> Copier will then be installed in your common environment and may cause
62+
> conflicts with its dependencies, while `pipx` will install Copier in a
63+
> separate and dedicated environment.
64+
65+
### Scenario 1: Create a new package
66+
5267

53-
Run `copier` with the template:
68+
#### Step 1/2: Create the files and directory structure
69+
70+
Run `copier copy` with the template:
5471

5572
```shell
5673
# Notes:
57-
# 1. See table below for explanation of each question
58-
# 2. The files will be generated in a new directory
74+
# 1. Make sure that `path/to/destination` is an empty directory
75+
# 2. See table below for explanation of each question
76+
# 3. The files will be generated in the specified destination directory
5977
copier copy https://github.com/nlesc/python-template.git path/to/destination
6078
```
6179

@@ -74,9 +92,9 @@ copier copy https://github.com/nlesc/python-template.git path/to/destination
7492
| code_of_conduct_email | [email protected] | Email address of the person who should be contacted in case of violations of the Code of Conduct. |
7593

7694
Once the project files have been generated, follow the steps outlined in
77-
[template/next_steps.md](template/next_steps.md).
95+
[next_steps.md](template/next_steps.md).
7896

79-
### Step 3/3: Read about what was just generated
97+
#### Step 2/2: Read about what was just generated
8098

8199
Good job! You have now generated the skeleton for your package:
82100

@@ -135,7 +153,53 @@ Good job! You have now generated the skeleton for your package:
135153
```
136154

137155
For an explanation of what's there, read on in the [project_setup.md](template/project_setup.md) file.
138-
There are also instructions on how to [apply the template to an existing Python package](ADD_TO_EXISTING_PACKAGE.md).
156+
157+
### Scenario 2: Apply to pre-existing code
158+
159+
To apply the template to pre-existing code, you can use the same `copier copy`
160+
command as when creating a new package, except that you point to the folder
161+
containing your existing code rather than a new one:
162+
163+
```shell
164+
copier copy https://github.com/nlesc/python-template.git path/to/existing/code
165+
```
166+
167+
This works because if `path/to/destination` already exists, Copier will
168+
update what is already there by either adding new files or updating
169+
existing files. Copier will ask to overwrite any files that resulted in
170+
conflicts. Especially if your files are already under version control, it is
171+
recommended to answer 'yes' for all files, you will still be able to review
172+
the changes suggested by the template.
173+
174+
### Scenario 3. Updating a template-made package
175+
176+
Copier provides the functionality for re-applying the template to a previously
177+
created project using the `copier update` command. This has two effects:
178+
179+
1. Your project will be updated according to the latest version of the template
180+
2. You can change any of your previous answers to apply these changes
181+
throughout your entire project.
182+
183+
> [!CAUTION]
184+
> Do not manually update answers in `.copier-answers.yml`,
185+
> as it will result in unexpected behavior.
186+
187+
```shell
188+
cd path/to/project
189+
copier update
190+
```
191+
192+
If you don't want to change any of your answers, but only want to update your
193+
project according to the latest template updates, you can provide the
194+
`--skip-answered` option. This tells Copier to reuse all of your previous
195+
answers, and simply bring in all updates from the template into
196+
your current project, such as updating which Python versions are supported.
197+
You will still be asked to answer any new questions that have been added to
198+
the template since you last applied it.
199+
200+
```shell
201+
copier update --skip-answered
202+
```
139203

140204
## Examples
141205

0 commit comments

Comments
 (0)