Skip to content

Commit e4a4fc4

Browse files
ebolyengregcaporaso
authored andcommitted
cookiecutter -> Copier transition
1 parent c06953d commit e4a4fc4

29 files changed

Lines changed: 183 additions & 143 deletions

.github/workflows/ci.yml

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,15 +25,17 @@ jobs:
2525
- name: install dependencies
2626
run: |
2727
python -m pip install --upgrade pip
28-
pip install -q cookiecutter
28+
pip install -q pipx
29+
pipx install copier
30+
pipx inject copier copier_templates_extensions
2931
pip install -q flake8
3032
pip install -q https://github.com/qiime2/q2lint/archive/master.zip
3133
3234
- name: build plugin from default template
3335
run: |
3436
git config --global user.email "q2dev@example.com"
3537
git config --global user.name "A QIIME 2 Plugin Developer"
36-
cookiecutter . --no-input
38+
copier copy --defaults --trust . .
3739
3840
- name: Set up Conda
3941
uses: conda-incubator/setup-miniconda@v3
@@ -49,6 +51,11 @@ jobs:
4951
cd q2-hello-world
5052
make install
5153
54+
- name: Call info on the deployment
55+
shell: bash -l {0}
56+
run: |
57+
qiime info
58+
5259
- name: Call --help on plugin
5360
shell: bash -l {0}
5461
run: |

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
# QIIME 2 Plugin [Cookiecutter](https://cookiecutter.readthedocs.io/) template
1+
# QIIME 2 Plugin [Copier](https://copier.readthedocs.io) template
22

3-
This is a cookiecutter template for creating new QIIME 2 plugins.
3+
This is a Copier template for creating new QIIME 2 plugins.
44
To learn how to use this, refer to the [Plugin Development Tutorial](https://develop.qiime2.org/en/latest/plugins/tutorials/intro.html) in *Developing with QIIME 2* (https://develop.qiime2.org).
55
Specific usage instructions can be found [here](https://develop.qiime2.org/en/latest/plugins/tutorials/create-from-template.html).
66

cookiecutter.json

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

copier.yaml

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
# Prompts
2+
package_name:
3+
default: q2-hello-world
4+
help: Package name (e.g., used as the top-level directory name)
5+
module_name:
6+
default: "{{ package_name.replace('-', '_') }}"
7+
help: Module name (must be a valid Python identifier)
8+
validator: >-
9+
{% if not module_name.isidentifier() %}
10+
The module name must be a valid Python identifier.
11+
{% endif %}
12+
plugin_name:
13+
default: "{{ package_name.removeprefix('q2-') }}"
14+
help: Plugin name (often a shortened version of the package name)
15+
author_name:
16+
default: A QIIME 2 Plugin Developer
17+
help: Author name
18+
author_email:
19+
default: q2-dev@example.com
20+
help: Author email
21+
project_url:
22+
default: https://example.com
23+
help: Main plugin website
24+
plugin_description:
25+
default: A QIIME 2 plugin template.
26+
help: Longer description, shown when information is requested on plugin
27+
plugin_short_description:
28+
default: Plugin template.
29+
help: Shorter description, shown when plugin is presented in a list
30+
target_distro:
31+
default: tiny
32+
choices: [tiny, amplicon, metagenome]
33+
help: Target distribution (if you're not sure, stick with the default).
34+
dev_target:
35+
default: stable
36+
choices: [stable, latest]
37+
help: Do you want to test against the current release (stable) or the upcoming release (latest).
38+
license:
39+
default: skip-license
40+
choices: [BSD-3-Clause, MIT, Apache-2.0, skip-license]
41+
help: Some common open source licenses. Use "skip-license" to use a custom license (or retain all rights).
42+
43+
# Config
44+
_templates_suffix: ""
45+
_tasks:
46+
- command: >-
47+
cd "{{ package_name }}" &&
48+
git init &&
49+
git add . &&
50+
git commit \
51+
-m "initial commit" \
52+
-m "Created from https://github.com/caporaso-lab/cookiecutter-qiime2-plugin." \
53+
-m "See https://develop.qiime2.org to learn more."
54+
when: "{{ has_git and first_run }}"
55+
_subdirectory: template/
56+
_jinja_extensions:
57+
- copier_templates_extensions.TemplateExtensionLoader
58+
- extensions/context.py:ContextUpdater

extensions/context.py

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
import urllib.request
2+
import subprocess
3+
4+
import yaml
5+
from copier_templates_extensions import ContextHook
6+
7+
# Download the data only once (because of sys.module cache),
8+
# instead of on each template event.
9+
DIST_DATA = 'https://raw.githubusercontent.com/qiime2/distributions/dev/data.yaml'
10+
with urllib.request.urlopen(DIST_DATA) as response:
11+
yaml_file = response.read()
12+
distributions_data = yaml.safe_load(yaml_file)
13+
14+
15+
def _check_git_installed():
16+
try:
17+
_ = subprocess.run("git --version",
18+
shell=True, check=True, capture_output=True)
19+
except subprocess.CalledProcessError:
20+
return False
21+
return True
22+
23+
24+
class ContextUpdater(ContextHook):
25+
def hook(self, context):
26+
if context["_copier_phase"] == "prompt": return {}
27+
28+
stable_epoch = distributions_data['released_epoch']
29+
latest_epoch = distributions_data['active_epoch']
30+
31+
target = context["dev_target"]
32+
if target == 'stable':
33+
target_epoch = stable_epoch
34+
else:
35+
target_epoch = latest_epoch
36+
37+
update = {
38+
"target_epoch": target_epoch,
39+
"has_git": _check_git_installed(),
40+
"first_run": not (context['_copier_conf']['dst_path']
41+
/ context['package_name'] / '.git/').exists()
42+
}
43+
return update

hooks/post_gen_project.py

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

hooks/pre_prompt.py

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

{{ cookiecutter.package_name }}/.github/workflows/ci.yml renamed to template/{{ package_name }}/.github/workflows/ci.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ on:
77
branches: ["main"]
88

99
jobs:
10-
build-and-test-qiime2-{{ cookiecutter.target_distro }}-{{ cookiecutter.target_epoch.replace('.', '-') }}:
10+
build-and-test-qiime2-{{ target_distro }}-{{ target_epoch.replace('.', '-') }}:
1111
runs-on: ${{ '{{' }} matrix.os {{ '}}' }}
1212
strategy:
1313
matrix:
@@ -19,8 +19,8 @@ jobs:
1919
- name: Set up Conda
2020
uses: conda-incubator/setup-miniconda@v3
2121
with:
22-
activate-environment: {{ cookiecutter.package_name }}-qiime2-{{ cookiecutter.target_distro }}-{{ cookiecutter.target_epoch }}
23-
environment-file: environment-files/{{ cookiecutter.package_name }}-qiime2-{{ cookiecutter.target_distro }}-{{ cookiecutter.target_epoch }}.yml
22+
activate-environment: {{ package_name }}-qiime2-{{ target_distro }}-{{ target_epoch }}
23+
environment-file: environment-files/{{ package_name }}-qiime2-{{ target_distro }}-{{ target_epoch }}.yml
2424
auto-activate-base: false
2525

2626
- name: Install plugin

template/{{ package_name }}/.github/workflows/test2.yml

Whitespace-only changes.
File renamed without changes.

0 commit comments

Comments
 (0)