Skip to content

Commit ded4cec

Browse files
committed
✨ Template | repo_url: add repository URL to generated files
Several files in generated packages benefit from knowing the source repository URL: the MkDocs/MyST docs sites get a header link to the repo, `pyproject.toml` gets `[project.urls]` entries that surface on PyPI, and other downstream uses (README badges, changelog commit links) can hook into the same value. Today the URL is hardcoded in a few places or missing entirely, and there's no single source of truth users can set without editing template output by hand. Add a hidden `repo_url` Copier question (default empty, `when: false`) so nothing is prompted on initial copy — the template still works fine without a remote — and wire it into: - `mkdocs.yml.jinja`: `repo_url`, `repo_name` (derived via Jinja from the URL), and the Material GitHub icon, all wrapped in `{% if repo_url %}` so empty values render a clean config. - `myst.yml.jinja`: set `github:` to `repo_url` when present; keep the existing commented-out placeholder otherwise. - `pyproject.toml.jinja`: add `[project.urls]` with `Repository` and `Issues` entries (the well-known PyPI labels) when `repo_url` is set. Document the workflow in `docs/index.md` next steps: users create the remote, then run `copier update -A -d repo_url=https://github.com/<user>/<repo>` to populate every wired-in spot in one shot. The `-A` (`--skip-answered`) flag keeps the update non-interactive for already-answered questions, mirroring the pattern already used by the hidden `auto_update` question.
1 parent 29ca952 commit ded4cec

5 files changed

Lines changed: 37 additions & 0 deletions

File tree

copier.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,12 @@ coverage:
4040
- codecov
4141
default: none
4242

43+
repo_url:
44+
type: str
45+
help: 'URL of the source repository (e.g. https://github.com/user/repo).'
46+
default: ''
47+
when: false
48+
4349
# github-token: uses the default GITHUB_TOKEN (zero setup, but PRs won't trigger CI).
4450
# pat: uses a PAT stored as COPIER_UPDATE_TOKEN secret (PRs trigger CI normally).
4551
auto_update:

docs/index.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,20 @@ To get this working:
5959
No repository secret is needed for public repos.
6060
For private repos, add a `CODECOV_TOKEN` secret to your repository and pass it in the workflow's `codecov-action` step.
6161

62+
### Repository URL
63+
64+
Several files in the generated package reference the source repository URL: the docs site (GitHub icon + link), `[project.urls]` in `pyproject.toml`, the README badges, and commit links in the generated changelog.
65+
The URL is controlled by the hidden `repo_url` question, which is empty by default so the template works without a remote.
66+
67+
Once you have created the remote repository, set it via:
68+
69+
```
70+
copier update -A -d repo_url=https://github.com/<user>/<repo>
71+
```
72+
73+
The `-A` flag (`--skip-answered`) skips questions you already answered, so only `repo_url` is applied.
74+
To change the URL later, run the same command with the new value.
75+
6276
### Automatic template updates
6377

6478
The template can optionally add a `copier-update.yaml` workflow that checks for upstream template changes every week, runs `copier update`, and opens a PR with the proposed changes.

template/docs/{% if docs == 'myst' %}myst.yml{% endif %}.jinja

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,11 @@ project:
44
title: {{ package_name }}
55
# keywords: []
66
# authors: []
7+
{%- if repo_url %}
8+
github: {{ repo_url }}
9+
{%- else %}
710
# github: https://github.com/
11+
{%- endif %}
812
# To autogenerate a Table of Contents, run "myst init --write-toc"
913
site:
1014
template: book-theme

template/pyproject.toml.jinja

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,12 @@ classifiers = [
2020
"Programming Language :: Python :: 3.13",
2121
"Programming Language :: Python :: 3.14",
2222
]
23+
{% if repo_url %}
24+
[project.urls]
25+
Repository = "{{ repo_url }}"
26+
Issues = "{{ repo_url }}/issues"
2327

28+
{% endif -%}
2429
[project.optional-dependencies]
2530
docs = [
2631
{% if docs == 'myst'-%}

template/{% if docs == 'mkdocs' %}mkdocs.yml{% endif %}.jinja

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,15 @@
11
site_name: {{package_name}}
2+
{%- if repo_url %}
3+
repo_url: {{ repo_url }}
4+
repo_name: {{ repo_url.rstrip('/').split('/')[-2:] | join('/') }}
5+
{%- endif %}
26

37
theme:
48
name: material
9+
{%- if repo_url %}
10+
icon:
11+
repo: fontawesome/brands/github
12+
{%- endif %}
513

614
markdown_extensions:
715
- admonition

0 commit comments

Comments
 (0)