Skip to content

Commit

Permalink
Migrate from cookiecutter to copier
Browse files Browse the repository at this point in the history
This migrates from cookiecutter template to copier while keeping all
original features.

Closes #348

Co-authored-by: Olga Lyashevska <olga.lyashevska@gmail.com>
Co-authored-by: Sander van Rijn <s.vanrijn@esciencecenter.nl>
  • Loading branch information
lyashevska and sjvrijn committed Jul 26, 2024
1 parent 780e6a4 commit ef8d95a
Show file tree
Hide file tree
Showing 57 changed files with 2,679 additions and 51 deletions.
Empty file added .copier-answers.yml
Empty file.
2 changes: 1 addition & 1 deletion .github/ISSUE_TEMPLATE/10_generated_package.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,5 @@ assignees: ''

---
<!--
Whatever you write here must have something to do with the code you get from running `cookiecutter`.
Whatever you write here must have something to do with the code you get from running `copier`.
-->
2 changes: 1 addition & 1 deletion .github/ISSUE_TEMPLATE/20_template.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,5 @@ assignees: ''

---
<!--
Whatever you write here must have something to do with the code of the template itself, i.e. before you run `cookiecutter`.
Whatever you write here must have something to do with the code of the template itself, i.e. before you run `copier`.
-->
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,5 @@ env
env3
venv
venv3

.swp
2 changes: 1 addition & 1 deletion CITATION.cff
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ cff-version: "1.2.0"
date-released: 2018-07-17
doi: 10.5281/zenodo.1310751
keywords:
- cookiecutter
- copier
- template
- Python
license: Apache-2.0
Expand Down
14 changes: 0 additions & 14 deletions cookiecutter.json

This file was deleted.

70 changes: 70 additions & 0 deletions copier.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
# Essential questions

package_name:
type: str
default: my_python_package
help: Enter the name of the Python package.
validator: >-
{% if not (package_name | regex_search('^[a-z][a-z0-9\_]+$')) %}
package_name must start with a letter, followed one or more letters, digits or underscores all lowercase.
{% endif %}
package_short_description:
type: str
default: Short description of package
# validator: >-
# {% if '"' in package_short_description %}
# package_short_description must not contain unescaped double quotes. Use \\" for double quotes.
# {% endif %}
keyword1:
type: str
default: keyword1
keyword2:
type: str
default: keyword2
version:
type: str
default: 0.1.0
github_organization:
type: str
default: "<my-github-organization>"
license:
type: str
choices:
- "Apache Software License 2.0"
- "MIT license"
- "BSD license"
- "ISC license"
- "GNU General Public License v3 or later"
- "GNU Lesser General Public License v3 or later"
- "Not open source"
default: "MIT license"
full_name:
type: str
default: Jane Smith
help: Enter your full name.
# validator: >-
# {% if '"' in full_name %}
# full_name must not contain unescaped double quotes. Use \\" for double quotes.
# {% endif %}
email:
type: str
default: yourname@esciencecenter.nl
copyright_holder:
type: str
default: Netherlands eScience Center
code_of_conduct_email:
type: str
default: "{{ email }}"

_subdirectory: template

repository:
default: git@github.com:{{ github_organization }}/{{ directory_name }}
when: false

repository_url:
default: https://github.com/{{ github_organization }}/{{ directory_name }}
when: false


# Optional questions
1 change: 0 additions & 1 deletion hooks/post_gen_project.py

This file was deleted.

11 changes: 0 additions & 11 deletions hooks/pre_gen_project.py

This file was deleted.

7 changes: 4 additions & 3 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ include_package_data = True
python_requires = >=3.8
packages =
install_requires =
cookiecutter==1.7.2
copier==9.2.0

[options.data_files]
# This section requires setuptools>=40.6.0
Expand All @@ -45,9 +45,10 @@ install_requires =
dev =
coverage [toml]
pytest
pytest-cookies
pytest-copie
pyprojroot


[tool:pytest]
testpaths = tests
norecursedirs = .git .github hooks {{cookiecutter.directory_name}}
norecursedirs = .git .github hooks {{directory_name}}
26 changes: 26 additions & 0 deletions template/.editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# EditorConfig is awesome: http://EditorConfig.org

# top-most EditorConfig file
root = true

# Unix-style newlines with a newline ending every file
[*]
end_of_line = lf
insert_final_newline = true
trim_trailing_whitespace = true
charset = utf-8

# 4 space indentation
[*.{py,java,r,R}]
indent_style = space
indent_size = 4

# 2 space indentation
[*.{js,json,y{a,}ml,html,cwl}]
indent_style = space
indent_size = 2

[*.{md,Rmd,rst}]
trim_trailing_whitespace = false
indent_style = space
indent_size = 2
19 changes: 19 additions & 0 deletions template/.githooks/pre-commit
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#!/bin/sh

echo "Script $0 triggered ..."

# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
echo "Starting ruff analysis..."

# quietly run ruff
ruff . --fix

# use return code to abort commit if necessary
if [ $? != "0" ]; then
echo "Commit aborted. Fix linter issues found by ruff before committing."
exit 1
fi

# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
echo "Pre-commit checks completed successfully."
exit 0
16 changes: 16 additions & 0 deletions template/.github/next_steps/01_sonarcloud_integration.md.jinja
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
---
title: 'Next step: Sonarcloud integration'
---

Continuous code quality can be handled by [Sonarcloud](https://sonarcloud.io/). This repository is configured to use Sonarcloud to perform quality analysis and code coverage report on each push.

In order to configure Sonarcloud analysis [GitHub Action workflow]({{repository_url}}/blob/main/.github/workflows/sonarcloud.yml) you must follow the steps below:

1. go to [Sonarcloud](https://sonarcloud.io/projects/create) to create a new Sonarcloud project
1. login with your GitHub account
1. add Sonarcloud organization or reuse existing one
1. set up a repository
1. go to [new code definition administration page](https://sonarcloud.io/project/new_code?id={{github_organization}}_{{directory_name}}) and select `Number of days` option
1. To be able to run the analysis:
1. a token must be created at [Sonarcloud account](https://sonarcloud.io/account/security/)
1. the created token must be added as `SONAR_TOKEN` to [secrets on GitHub](https://github.com/{{github_organization}}/{{directory_name}}/settings/secrets/actions)
28 changes: 28 additions & 0 deletions template/.github/next_steps/02_citation.md.jinja
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
---
title: 'Next step: Citation data'
---

It is likely that your `CITATION.cff` currently doesn't pass validation. The error messages you get from the [`cffconvert`]({{repository_url}}/actions/workflows/cffconvert.yml) GitHub Action are unfortunately a bit cryptic, but doing the following helps:

- [ ] Check if the `given-name` and `family-name` keys need updating. If your family name has a name particle like `von` or `van` or `de`, use the `name-particle` key; if your name has a suffix like `Sr` or `IV`, use `name-suffix`. For details, refer to the schema description: https://github.com/citation-file-format/citation-file-format
- [ ] Update the value of the `orcid` key. If you do not have an orcid yet, you can get one here [https://orcid.org/](https://orcid.org/).
- [ ] Add more authors if needed
- [ ] Update `date-released` using the YYYY-MM-DD format.
- [ ] Update the `doi` key with the conceptDOI for your repository (see [https://help.zenodo.org](https://help.zenodo.org/) for more information on what a conceptDOI is). If your project doesn't have a DOI yet, you can use the string `10.0000/FIXME` to pass validation.
- [ ] Verify that the `keywords` array accurately describes your project.

Afterwards, the `cffconvert` GitHub Action should be green.

To make sure services like [Zenodo](https://zenodo.org) and the [Research Software Directory](https://research-software-directory.org/) can keep your citation data up to date, the [`cffconvert`]({{repository_url}}/actions/workflows/cffconvert.yml) GitHub Action checks the following:

1. Whether your repository includes a `CITATION.cff` file.

_By including this file, authors of the software can receive credit for the work they put in._

1. Whether your `CITATION.cff` is valid YAML.

_Visit http://www.yamllint.com/ to see if the contents of your CITATION.cff are valid YAML._

1. Whether your `CITATION.cff` adheres to the schema (as listed in the `CITATION.cff` file itself under key `cff-version`).

_The Citation File Format schema can be found [here](https://github.com/citation-file-format/citation-file-format), along with an explanation of all the keys. You're advised to use the latest available schema version._
20 changes: 20 additions & 0 deletions template/.github/next_steps/03_readthedocs.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
---
title: 'Next step: Read the Docs'
---

Your Python package should have publicly available documentation, including API documentation for your users.
[Read the Docs](https://readthedocs.org) can host your user documentation for you.

To host the documentation of this repository please perform the following instructions:

1. go to [Read the Docs](https://readthedocs.org/dashboard/import/?)
1. log in with your GitHub account
1. find `{{ github_organization }}/{{ directory_name }}` in list and press `+` button.
* If repository is not listed,
1. go to [Read the Docs GitHub app](https://github.com/settings/connections/applications/fae83c942bc1d89609e2)
2. make sure {{ github_organization }} has been granted access.
3. reload repository list on Read the Docs import page
1. wait for the first build to be completed at <https://readthedocs.org/projects/{{ directory_name }}/builds>
1. check that the link of the documentation badge in the [README.md]({{ repository_url }}) works

See [README.dev.md#]({{repository_url}}/blob/main/README.dev.md#generating-the-api-docs) how to build documentation site locally.
22 changes: 22 additions & 0 deletions template/.github/next_steps/04_zenodo_integration.md.jinja
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
---
title: 'Next step: Enable Zenodo integration'
---

By enabling Zenodo integration, your package will automatically get a DOI which can be used to cite your package. After enabling Zenodo integration for your GitHub repository, Zenodo will create a snapshot and archive each release you make on GitHub. Moreover, Zenodo will create a new DOI for each GitHub release of your code.

To enable Zenodo integration:

1. Go to http://zenodo.org and login with your GitHub account. When you are redirected to GitHub, *Authorize application* to give permission to Zenodo to access your account.
1. Go to <https://zenodo.org/account/settings/github/> and enable Zenodo integration of your repository by clicking on `On` toggle button.
2. Your package will get a DOI only after you make a release. Create a new release as described in [README.dev.md]({{repository_url}}/blob/main/README.dev.md#33-github)
3. At this point you should have a DOI. To find out the DOI generated by Zenodo:
1. Visit https://zenodo.org/deposit and click on your repository link
2. You will find the latest DOI in the right column in Versions box in **Cite all versions?** section
3. Copy the text of the link. For example `10.5281/zenodo.1310751`
4. Update the badge in your repository
1. Edit README.md and replace the badge placeholder with the badge link you copied in previous step.
The badge placeholder is shown below.

`[![DOI](https://zenodo.org/badge/DOI/<replace-with-created-DOI>.svg)](https://doi.org/<replace-with-created-DOI>)`

For FAQ about Zenodo please visit <https://help.zenodo.org/>.
17 changes: 17 additions & 0 deletions template/.github/next_steps/05_linting.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
---
title: 'Next step: Linting'
---

Your repository has a [workflow]({{ repository_url }}/blob/main/.github/workflows/build.yml) which [lints](https://en.wikipedia.org/wiki/Lint_(software)) your code after every push and when creating a pull request.

Linter workflow may fail if `description` or `keywords` field in [pyproject.toml]({{ repository_url }}/blob/main/pyproject.toml) is empty. Please update these fields. To validate your changes run:

```shell
ruff .
```

Enabling [githook](https://git-scm.com/docs/githooks) will automatically lint your code in every commit. You can enable it by running the command below.

```shell
git config --local core.hooksPath .githooks
```
62 changes: 62 additions & 0 deletions template/.github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
name: Python package

on:
push:
branches:
- main
pull_request:
branches:
- main

jobs:

build:
name: Build for (${{ '{{ ' -}} matrix.python-version }}, ${{ '{{ ' -}} matrix.os }})
runs-on: ${{ '{{ ' -}} matrix.os }}
strategy:
fail-fast: false
matrix:
os: ['ubuntu-latest', 'macos-latest', 'windows-latest']
python-version: ['3.8', '3.9', '3.10', '3.11', '3.12']
steps:
- uses: actions/checkout@v3
- name: Set up Python ${{ '{{ ' -}} matrix.python-version }}
uses: actions/setup-python@v3
with:
python-version: ${{ '{{ ' -}} matrix.python-version }}
- name: Python info
shell: bash -e {0}
run: |
which python
python --version
- name: Upgrade pip and install dependencies
run: |
python -m pip install --upgrade pip setuptools
python -m pip install .[dev,publishing]
- name: Run unit tests
run: python -m pytest -v
- name: Verify that we can build the package
run: python -m build

lint:
name: Linting build
runs-on: ubuntu-latest
strategy:
fail-fast: false
steps:
- uses: actions/checkout@v3
- name: Set up Python 3.9
uses: actions/setup-python@v3
with:
python-version: 3.9
- name: Python info
shell: bash -e {0}
run: |
which python
python --version
- name: Upgrade pip and install dependencies
run: |
python -m pip install --upgrade pip setuptools
python -m pip install .[dev,publishing]
- name: Check style against standards using ruff
run: ruff .
23 changes: 23 additions & 0 deletions template/.github/workflows/cffconvert.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
name: cffconvert

on:
push:
branches:
- main
pull_request:
branches:
- main

jobs:

verify:
name: "cffconvert"
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
name: Check out a copy of the repository

- name: Check whether the citation metadata from CITATION.cff is valid
uses: citation-file-format/cffconvert-github-action@2.0.0
with:
args: "--validate"
Loading

0 comments on commit ef8d95a

Please sign in to comment.