Skip to content
Closed
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
86 changes: 48 additions & 38 deletions copier.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,23 +9,31 @@ _tasks:
# Message to show after generating or regenerating the project successfully
_message_after_copy: |

Your project "{{ package_name }}" has been created successfully!
Your project "{{ github_repo }}" has been created successfully!

Next steps:
See the [guide](https://template-python-package.seedcase-project.org/docs/guide) for more detail
on the next steps. Briefly:

1. Change directory to the project root:

$ cd {{ _copier_conf.dst_path }}
``` bash
cd {{ _copier_conf.dst_path | realpath }}
```

2. Install the pre-commit hooks:
2. Install the pre-commit hooks, add (called "update" here) the Quarto extension,
and build the README:

$ just install-precommit
``` bash
just install-precommit update-quarto-theme build-readme
```

3. Install [`spaid`](https://github.com/seedcase-project/spaid) and run these commands to upload and configure your project on GitHub:
3. Install [`spaid`](https://github.com/seedcase-project/spaid) and run these setup steps:

$ spaid_gh_create_repo_from_local -h
$ spaid_gh_set_repo_settings -h
$ spaid_gh_ruleset_basic_protect_main -h
``` bash
spaid_gh_create_repo_from_local -h
spaid_gh_set_repo_settings -h
spaid_gh_ruleset_basic_protect_main -h
```

4. Configure GitHub following this
[guide](https://guidebook.seedcase-project.org/operations/security#using-github-apps-to-generate-tokens):
Expand All @@ -37,46 +45,31 @@ _message_after_copy: |

5. List and complete all TODO items in the repository:

$ just list-todos
``` bash
just list-todos
```

# Questions:
package_github_repo:
type: str
help: "What is or will be the GitHub repository spec for the project?"
placeholder: "user/repo"
validator: |
{% if package_github_repo and not (package_github_repo | regex_search('^[\w.-]+\/[\w.-]+$')) %}
Must be in the format `user/repo` and contain only alphanumeric characters and `_`, `-`, or `.`.
{% endif %}
is_seedcase_project:
type: bool
help: "Is this package part of the Seedcase Project?"
default: true

github_user:
type: str
default: "{{ package_github_repo.split('/')[0] if package_github_repo else '' }}"
when: false
help: "What is the name of the GitHub user or organisation where the repository will be or is stored?"

package_name:
hosting_provider:
type: str
help: "What is the name of the package?"
default: "{{ _copier_conf.dst_path | basename }}"
validator: |
{% if package_name and not (package_name | regex_search('^[\w.-]+$')) %}
Must contain only alphanumeric characters and `_`, `-`, or `.`.
{% endif %}

package_name_snake_case:
type: str
default: "{{package_name | replace('-', '_') | replace('.', '_')}}"
when: false

is_seedcase_project:
type: bool
help: "Is this package part of the Seedcase Project?"
default: "{{ github_user == 'seedcase-project' }}"
help: "What hosting provider will you use for the documentation website?"
choices:
- netlify
- gh-pages

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

author_given_name:
type: str
Expand All @@ -103,6 +96,23 @@ github_board_number:
The board number must be an integer.
{% endif %}

# Configurations not asked

github_repo:
type: str
default: "{{ _copier_conf.dst_path | realpath | basename }}"
when: false
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Assuming this, like in template-website


github_repo_snake_case:
type: str
default: "{{github_repo | replace('-', '_') | replace('.', '_')}}"
when: false

github_repo_spec:
type: str
default: "{{ github_user }}/{{ github_repo }}"
when: false

copyright_year:
type: str
default: "{{ copyright_year | default('%Y' | strftime) }}"
Expand Down
59 changes: 4 additions & 55 deletions justfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

@_checks: check-spelling check-commits
# Test Seedcase and non-Seedcase projects
@_tests: (test "true") (test "false")
@_tests: (test "true" "netlify") (test "false" "netlify") (test "true" "gh-pages") (test "false" "gh-pages")
@_builds: build-contributors build-website build-readme

# Run all build-related recipes in the justfile
Expand Down Expand Up @@ -46,60 +46,9 @@ check-commits:
check-spelling:
uvx typos

# Test and check that a Python package can be created from the template
test is_seedcase_project:
#!/bin/zsh
test_name="test-python-package"
test_dir="$(pwd)/_temp/{{ is_seedcase_project }}/$test_name"
template_dir="$(pwd)"
commit=$(git rev-parse HEAD)
rm -rf $test_dir
# vcs-ref means the current commit/head, not a tag.
uvx copier copy $template_dir $test_dir \
--vcs-ref=$commit \
--defaults \
--trust \
--data package_github_repo="first-last/repo" \
--data is_seedcase_project={{ is_seedcase_project }} \
--data author_given_name="First" \
--data author_family_name="Last" \
--data author_email="[email protected]" \
--data review_team="@first-last/developers" \
--data github_board_number=22
# Run checks in the generated test Python package
cd $test_dir
git add .
git commit -m "test: initial copy"
just check-python check-spelling
# TODO: Find some way to test the `update` command
# Check that recopy works
echo "Testing recopy command -----------"
rm .cz.toml
git add .
git commit -m "test: preparing to recopy from the template"
uvx copier recopy \
--vcs-ref=$commit \
--defaults \
--overwrite \
--trust
# Check that copying onto an existing Python package works
echo "Using the template in an existing package command -----------"
rm .cz.toml .copier-answers.yml LICENSE.md
git add .
git commit -m "test: preparing to copy onto an existing package"
uvx copier copy \
$template_dir $test_dir \
--vcs-ref=$commit \
--defaults \
--trust \
--overwrite \
--data package_github_repo="first-last/repo" \
--data is_seedcase_project={{ is_seedcase_project }} \
--data author_given_name="First" \
--data author_family_name="Last" \
--data author_email="[email protected]" \
--data review_team="@first-last/developers" \
--data github_board_number=22
# Test that a Python package can be created from the template, with parameters for: `is_seedcase_project` (true or false) and `hosting_provider` (either "gh-pages" or "netlify")
test is_seedcase_project="true" hosting_provider="netlify":
sh ./test-template.sh {{ is_seedcase_project }} {{ hosting_provider }}

# Clean up any leftover and temporary build files
cleanup:
Expand Down
17 changes: 0 additions & 17 deletions template/.github/workflows/build-website.yml

This file was deleted.

26 changes: 26 additions & 0 deletions template/.github/workflows/build-website.yml.jinja
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
name: Build website

on:
push:
branches:
- main

# Limit token permissions for security
permissions: read-all

jobs:
build-website:
uses: seedcase-project/.github/.github/workflows/reusable-build-docs-with-python.yml@main
{% if hosting_provider == 'gh-pages' -%}
with:
hosting-provider: gh-pages
permissions:
contents: write
pages: write
{%- endif %}
secrets:
{% if hosting_provider == 'gh-pages' -%}
github-token: {{ '${{ secrets.GITHUB_TOKEN }}' }}
{%- elif hosting_provider == 'netlify' -%}
netlify-token: {{ '${{ secrets.NETLIFY_AUTH_TOKEN }}' }}
{%- endif %}
2 changes: 1 addition & 1 deletion template/CITATION.cff.jinja
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,5 @@ keywords:
- ""
license: MIT
message: "If you use this Python package, please cite it using these metadata."
repository-code: "https://github.com/{{ package_github_repo }}"
repository-code: "https://github.com/{{ github_repo_spec }}"
url: "{{ homepage }}"
2 changes: 1 addition & 1 deletion template/LICENSE.md.jinja
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# MIT License

Copyright (c) {{ copyright_year }} {{ package_name }} authors
Copyright (c) {{ copyright_year }} {{ github_repo }} authors

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
2 changes: 1 addition & 1 deletion template/README.md.jinja
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@


# {{ package_name }}
# {{ github_repo }}
2 changes: 1 addition & 1 deletion template/README.qmd.jinja
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
# {{ package_name }}
# {{ github_repo }}

<!-- TODO: Add README for project. -->
18 changes: 12 additions & 6 deletions template/_quarto.yml.jinja
Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,25 @@ project:
website:
# TODO: Fill in the title of the website.
title: ""
{% if hosting_provider == "gh-pages" -%}
site-url: "https://{{ github_user }}.github.io/{{ github_repo }}/"
{%- elif hosting_provider == "netlify" -%}
# TODO: Set the Netlify custom domain URL
site-url: ""
{%- endif %}
site-url: "{{ homepage }}"
repo-url: "https://github.com/{{ package_github_repo }}"
repo-url: "https://github.com/{{ github_repo_spec }}"
page-navigation: true
navbar:
pinned: true
title: false
{%- if is_seedcase_project %}
logo: "_extensions/seedcase-project/seedcase-theme/logos/navbar-logo-{{ package_name }}.svg"
logo-alt: "{{ package_name }} logo: Main page"
logo: "_extensions/seedcase-project/seedcase-theme/logos/navbar-logo-{{ github_repo }}.svg"
logo-alt: "{{ github_repo }} logo: Main page"
{%- else %}
# TODO: add logo
logo: ""
logo-alt: "{{ package_name }} logo: Main page"
logo-alt: "{{ github_repo }} logo: Main page"
{%- endif %}
left:
- text: "Guide"
Expand All @@ -30,7 +36,7 @@ website:
href: docs/design/index.qmd
tools:
- icon: github
href: "https://github.com/{{ package_github_repo }}"
href: "https://github.com/{{ github_repo_spec }}"
aria-label: "GitHub icon: Source code"
{% if is_seedcase_project -%}
- icon: house
Expand All @@ -53,7 +59,7 @@ quartodoc:
sidebar: "docs/reference/_sidebar.yml"
style: "pkgdown"
dir: "docs/reference"
package: "{{ package_name_snake_case }}"
package: "{{ github_repo_snake_case }}"
parser: google
dynamic: true
renderer:
Expand Down
2 changes: 1 addition & 1 deletion template/docs/site-counter.html.jinja
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
<!-- TODO: Set up GoatCounter -->
<script data-goatcounter="https://{{ github_user }}-{{ package_name }}.goatcounter.com/count" async
<script data-goatcounter="https://{{ github_user }}-{{ github_repo }}.goatcounter.com/count" async
src="//gc.zgo.at/count.js"></script>
2 changes: 1 addition & 1 deletion template/justfile.jinja
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ build-readme:

# Generate a Quarto include file with the contributors
build-contributors:
sh ./tools/get-contributors.sh {{ package_github_repo }}
sh ./tools/get-contributors.sh {{ github_repo_spec }}

# Check for and apply updates from the template
update-from-template:
Expand Down
10 changes: 4 additions & 6 deletions template/pyproject.toml.jinja
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[project]
name = "{{ package_name }}"
name = "{{ github_repo }}"
version = "0.1.0"
# TODO: Add a description of the package.
description = ""
Expand All @@ -19,11 +19,9 @@ dependencies = []

[project.urls]
homepage = "{{ homepage }}"
{%- if package_github_repo %}
repository = "https://github.com/{{ package_github_repo }}"
changelog = "https://github.com/{{ package_github_repo }}/blob/main/CHANGELOG.md"
issues = "https://github.com/{{ package_github_repo }}/issues"
{% endif %}
repository = "https://github.com/{{ github_repo_spec }}"
changelog = "https://github.com/{{ github_repo_spec }}/blob/main/CHANGELOG.md"
issues = "https://github.com/{{ github_repo_spec }}/issues"

[build-system]
requires = ["hatchling"]
Expand Down
Loading