Skip to content

Commit 0834473

Browse files
authored
Merge branch 'main' into refactor/extract-copier-test
2 parents 908fc10 + 44a5aeb commit 0834473

15 files changed

+115
-88
lines changed

.pre-commit-config.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,6 @@ repos:
2525
# sub-packages, which confuses pre-commit when it tries to find the latest
2626
# version
2727
- repo: https://github.com/adhtruong/mirrors-typos
28-
rev: v1.35.4
28+
rev: v1.35.5
2929
hooks:
3030
- id: typos

copier.yaml

Lines changed: 45 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -9,23 +9,31 @@ _tasks:
99
# Message to show after generating or regenerating the project successfully
1010
_message_after_copy: |
1111
12-
Your project "{{ package_name }}" has been created successfully!
12+
Your project "{{ github_repo }}" has been created successfully!
1313
14-
Next steps:
14+
See the [guide](https://template-python-package.seedcase-project.org/docs/guide) for more detail
15+
on the next steps. Briefly:
1516
1617
1. Change directory to the project root:
1718
18-
$ cd {{ _copier_conf.dst_path }}
19+
``` bash
20+
cd {{ _copier_conf.dst_path | realpath }}
21+
```
1922
20-
2. Install the pre-commit hooks:
23+
2. Install the pre-commit hooks, add (called "update" here) the Quarto extension,
24+
and build the README:
2125
22-
$ just install-precommit
26+
``` bash
27+
just install-precommit update-quarto-theme build-readme
28+
```
2329
24-
3. Install [`spaid`](https://github.com/seedcase-project/spaid) and run these commands to upload and configure your project on GitHub:
30+
3. Install [`spaid`](https://github.com/seedcase-project/spaid) and run these setup steps:
2531
26-
$ spaid_gh_create_repo_from_local -h
27-
$ spaid_gh_set_repo_settings -h
28-
$ spaid_gh_ruleset_basic_protect_main -h
32+
``` bash
33+
spaid_gh_create_repo_from_local -h
34+
spaid_gh_set_repo_settings -h
35+
spaid_gh_ruleset_basic_protect_main -h
36+
```
2937
3038
4. Configure GitHub following this
3139
[guide](https://guidebook.seedcase-project.org/operations/security#using-github-apps-to-generate-tokens):
@@ -37,46 +45,37 @@ _message_after_copy: |
3745
3846
5. List and complete all TODO items in the repository:
3947
40-
$ just list-todos
48+
``` bash
49+
just list-todos
50+
```
4151
4252
# Questions:
43-
package_github_repo:
44-
type: str
45-
help: "What is or will be the GitHub repository spec for the project?"
46-
placeholder: "user/repo"
47-
validator: |
48-
{% if package_github_repo and not (package_github_repo | regex_search('^[\w.-]+\/[\w.-]+$')) %}
49-
Must be in the format `user/repo` and contain only alphanumeric characters and `_`, `-`, or `.`.
50-
{% endif %}
53+
is_seedcase_project:
54+
type: bool
55+
help: "Is this package part of the Seedcase Project?"
56+
default: true
5157

52-
github_user:
58+
github_repo:
5359
type: str
54-
default: "{{ package_github_repo.split('/')[0] if package_github_repo else '' }}"
60+
default: "{{ _copier_conf.dst_path | realpath | basename }}"
5561
when: false
5662

57-
package_name:
63+
github_user:
5864
type: str
59-
help: "What is the name of the package?"
60-
default: "{{ _copier_conf.dst_path | basename }}"
61-
validator: |
62-
{% if package_name and not (package_name | regex_search('^[\w.-]+$')) %}
63-
Must contain only alphanumeric characters and `_`, `-`, or `.`.
64-
{% endif %}
65+
help: "What is the name of the GitHub user or organisation where the repository will be or is stored?"
66+
default: "{{ 'seedcase-project' if is_seedcase_project else '' }}"
6567

66-
package_name_snake_case:
68+
hosting_provider:
6769
type: str
68-
default: "{{package_name | replace('-', '_') | replace('.', '_')}}"
69-
when: false
70-
71-
is_seedcase_project:
72-
type: bool
73-
help: "Is this package part of the Seedcase Project?"
74-
default: "{{ github_user == 'seedcase-project' }}"
70+
help: "What hosting provider will you use for the documentation website?"
71+
choices:
72+
- netlify
73+
- gh-pages
7574

7675
homepage:
7776
type: str
7877
help: "What is the homepage of your project?"
79-
default: "{{ 'https://%s.seedcase-project.org' % package_name if is_seedcase_project else '' }}"
78+
default: "{{ 'https://%s.seedcase-project.org' % github_repo if is_seedcase_project else '' }}"
8079

8180
author_given_name:
8281
type: str
@@ -103,6 +102,16 @@ github_board_number:
103102
The board number must be an integer.
104103
{% endif %}
105104
105+
github_repo_snake_case:
106+
type: str
107+
default: "{{github_repo | replace('-', '_') | replace('.', '_')}}"
108+
when: false
109+
110+
github_repo_spec:
111+
type: str
112+
default: "{{ github_user }}/{{ github_repo }}"
113+
when: false
114+
106115
copyright_year:
107116
type: str
108117
default: "{{ copyright_year | default('%Y' | strftime) }}"

docs/guide.qmd

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -42,10 +42,15 @@ First, open a Terminal and move into the directory where you want to
4242
create the new Python package. Then run the following command:
4343

4444
``` bash
45-
# Copy into the current directory, which is the "."
46-
uvx copier copy --trust gh:seedcase-project/template-python-package .
45+
uvx copier copy --trust gh:seedcase-project/template-python-package new-package
4746
```
4847

48+
Here, `new-package` is the name of the new folder you will create from
49+
the template. The template assumes that the name of your new folder will
50+
also be the name of the GitHub repository for the Python package. So the
51+
new folder name should be a short, lowercase name without spaces or
52+
special characters.
53+
4954
::: callout-caution
5055
This template runs some post-copy commands using your terminal. In order
5156
to run them, you need to use the `--trust` option. Review the
@@ -64,12 +69,13 @@ to the existing package. This will add all the template's files and
6469
configurations to the existing package.
6570

6671
``` bash
67-
uvx copier copy --trust gh:seedcase-project/template-python-package .
72+
uvx copier copy --trust gh:seedcase-project/template-python-package new-package
6873
```
6974

70-
It will go through a series of prompts, as in the case of creating a new
71-
Python package, including asking if you want to overwrite existing
72-
files.
75+
See the comment above in the "Creating a new Python package" section
76+
about naming the new folder. It will go through a series of prompts, as
77+
in the case of creating a new Python package, including asking if you
78+
want to overwrite existing files.
7379

7480
::: callout-note
7581
To use the `copy` command, the Python package needs to be tracked by Git
@@ -129,8 +135,8 @@ just install-precommit
129135
This sets up the pre-commit hooks to run standard checks on your
130136
repository whenever you commit files to the history.
131137

132-
If you are using the template to create a Python package for the Seedcase
133-
Project, run:
138+
If you are using the template to create a Python package for the
139+
Seedcase Project, run:
134140

135141
``` bash
136142
just update-quarto-theme
@@ -140,9 +146,9 @@ Then set `seedcase-theme` as your project `type` in `_quarto.yml`.
140146

141147
This adds the `seedcase-theme` Quarto theme to the website, which
142148
provides a consistent look and feel across all Seedcase Project
143-
websites, including for Python package websites.
144-
It's called `update-quarto-theme` here since you can use this
145-
command to keep the theme updated.
149+
websites, including for Python package websites. It's called
150+
`update-quarto-theme` here since you can use this command to keep the
151+
theme updated.
146152

147153
Next, install [`spaid`](https://github.com/seedcase-project/spaid) and
148154
use the following commands to run the next setup steps:
@@ -175,5 +181,5 @@ additional setup are:
175181
GitHub App, along with the `ADD_TO_BOARD_TOKEN` secret and the
176182
`ADD_TO_BOARD_APP_ID` variable of the GitHub App's ID.
177183

178-
If you use Netlify, you will also need to add a `NETLIFY_AUTH_TOKEN` secret
179-
of your Netlify Token.
184+
If you use Netlify, you will also need to add a `NETLIFY_AUTH_TOKEN`
185+
secret of your Netlify Token.

template/.github/workflows/build-website.yml

Lines changed: 0 additions & 17 deletions
This file was deleted.
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
name: Build website
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
8+
# Limit token permissions for security
9+
permissions: read-all
10+
11+
jobs:
12+
build-website:
13+
uses: seedcase-project/.github/.github/workflows/reusable-build-docs-with-python.yml@main
14+
{%- if hosting_provider == 'gh-pages' %}
15+
with:
16+
hosting-provider: gh-pages
17+
permissions:
18+
contents: write
19+
pages: write
20+
{%- endif %}
21+
secrets:
22+
{% if hosting_provider == 'gh-pages' -%}
23+
github-token: {{ '${{ secrets.GITHUB_TOKEN }}' }}
24+
{%- elif hosting_provider == 'netlify' -%}
25+
netlify-token: {{ '${{ secrets.NETLIFY_AUTH_TOKEN }}' }}
26+
{%- endif %}

template/CITATION.cff.jinja

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,5 +20,5 @@ keywords:
2020
- ""
2121
license: MIT
2222
message: "If you use this Python package, please cite it using these metadata."
23-
repository-code: "https://github.com/{{ package_github_repo }}"
23+
repository-code: "https://github.com/{{ github_repo_spec }}"
2424
url: "{{ homepage }}"

template/LICENSE.md.jinja

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# MIT License
22

3-
Copyright (c) {{ copyright_year }} {{ package_name }} authors
3+
Copyright (c) {{ copyright_year }} {{ github_repo }} authors
44

55
Permission is hereby granted, free of charge, to any person obtaining a copy
66
of this software and associated documentation files (the "Software"), to deal

template/_publish.yml

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

template/_quarto.yml.jinja

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,19 +11,24 @@ project:
1111
website:
1212
# TODO: Fill in the title of the website.
1313
title: ""
14+
{% if hosting_provider == "gh-pages" -%}
15+
site-url: "https://{{ github_user }}.github.io/{{ github_repo }}/"
16+
{%- elif hosting_provider == "netlify" -%}
17+
# TODO: Set the Netlify custom domain URL
1418
site-url: "{{ homepage }}"
15-
repo-url: "https://github.com/{{ package_github_repo }}"
19+
{%- endif %}
20+
repo-url: "https://github.com/{{ github_repo_spec }}"
1621
page-navigation: true
1722
navbar:
1823
pinned: true
1924
title: false
2025
{%- if is_seedcase_project %}
21-
logo: "_extensions/seedcase-project/seedcase-theme/logos/navbar-logo-{{ package_name }}.svg"
22-
logo-alt: "{{ package_name }} logo: Main page"
26+
logo: "_extensions/seedcase-project/seedcase-theme/logos/navbar-logo-{{ github_repo }}.svg"
27+
logo-alt: "{{ github_repo }} logo: Main page"
2328
{%- else %}
2429
# TODO: add logo
2530
logo: ""
26-
logo-alt: "{{ package_name }} logo: Main page"
31+
logo-alt: "{{ github_repo }} logo: Main page"
2732
{%- endif %}
2833
left:
2934
- text: "Guide"
@@ -32,7 +37,7 @@ website:
3237
href: docs/design/index.qmd
3338
tools:
3439
- icon: github
35-
href: "https://github.com/{{ package_github_repo }}"
40+
href: "https://github.com/{{ github_repo_spec }}"
3641
aria-label: "GitHub icon: Source code"
3742
{%- if is_seedcase_project %}
3843
- icon: house
@@ -55,7 +60,7 @@ quartodoc:
5560
sidebar: "docs/reference/_sidebar.yml"
5661
style: "pkgdown"
5762
dir: "docs/reference"
58-
package: "{{ package_name_snake_case }}"
63+
package: "{{ github_repo_snake_case }}"
5964
parser: google
6065
dynamic: true
6166
renderer:
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
<!-- TODO: Set up GoatCounter -->
2-
<script data-goatcounter="https://{{ github_user }}-{{ package_name }}.goatcounter.com/count" async
2+
<script data-goatcounter="https://{{ github_user }}-{{ github_repo }}.goatcounter.com/count" async
33
src="//gc.zgo.at/count.js"></script>

0 commit comments

Comments
 (0)