Skip to content

Commit 8af8059

Browse files
committed
Merge remote-tracking branch 'origin/main' into 238-linting-template
2 parents d3493a4 + c8e1e52 commit 8af8059

File tree

17 files changed

+770
-46
lines changed

17 files changed

+770
-46
lines changed

.github/workflows/tests.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ jobs:
1313
strategy:
1414
fail-fast: false
1515
matrix:
16-
os: ['ubuntu-latest', 'macos-latest']
16+
os: ['ubuntu-latest', 'macos-latest', 'windows-latest']
1717
python-version: ['3.6', '3.7', '3.8', '3.9']
1818
steps:
1919
- uses: actions/checkout@v2

.mlc-config.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,5 +18,6 @@
1818
}
1919
],
2020
"replacementPatterns": [
21-
]
21+
],
22+
"timeout": "20s"
2223
}

ADD_TO_EXISTING_PACKAGE.md

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
# Add your existing code to directory generated by the NLeSC Python template
2+
3+
The following steps requires that your existing code is in a GitHub repository.
4+
5+
1. Follow the [instructions to create a new package](https://github.com/NLeSC/python-template#how-to-use) with the Python template, while answering the questions like you would for the existing package.
6+
7+
2. Create a Git structure for the new directory: (replace `<NEW_DIRECTORY>` with directory name you used during cookiecutter questionnaire)
8+
```shell
9+
$ cd <NEW_DIRECTORY>
10+
$ git init
11+
$ git add --all
12+
$ git commit -m "Added code generated by cookiecutter"
13+
$ git branch -M main
14+
```
15+
16+
3. Import the existing repository from GitHub (Replace `<ORGANIZATION>` with your GitHub organization name , `<REPOSITORY>` with your GitHub repository name and `<BRANCH>` with your default branch for example `main` or `master`):
17+
```shell
18+
$ git remote add -f existing_code https://github.com/<ORGANIZATION>/<REPOSITORY>
19+
$ git fetch existing_code
20+
$ git merge existing_code/<BRANCH> --allow-unrelated-histories
21+
```
22+
23+
4. The previous step will likely result in several merge conflicts. Solve the conflicts by editing the files.
24+
5. Once all conflicts have been resolved then add all the files to GitHub:
25+
```shell
26+
$ git add --all
27+
$ git commit -m "Merged existing code with code generated by cookiecutter"
28+
$ git push
29+
```

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,8 @@ cookiecutter https://github.com/nlesc/python-template.git
6161
| package_name | my_python_package | Name of the package. Avoid using spaces, dashes, or uppercase letters for the best experience across operating systems. |
6262
| project_name | my-python-project | Name of the project that contains the package. Avoid using spaces or uppercase letters for the best experience across operating systems. |
6363
| package_short_description | &nbsp; | The information that you enter here will end up in the README, documentation, license, and setup.cfg, so it may be a good idea to prepare something in advance. |
64+
| keyword1 | keyword1 | A term that describes your package. |
65+
| keyword2 | keyword2 | Another term that describes your package. |
6466
| version | 0.1.0 | &nbsp; |
6567
| github_organization | &lt;my-github-organization&gt; | GitHub organization that will contain this project's repository. This can also be your GitHub user name. |
6668
| license | Apache Software License 2.0 | The software license under which the code is made available. |
@@ -107,6 +109,7 @@ my-python-project/
107109
```
108110

109111
For an explanation of what's there, read on in the [project_setup.md]({{cookiecutter.project_name}}/project_setup.md) file.
112+
There are also instructions on how to [apply the template to an existing Python package](ADD_TO_EXISTING_PACKAGE.md).
110113

111114
## Examples
112115

cookiecutter.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
{
22
"package_name": "my_python_package",
33
"project_name": "my-python-project",
4-
"_copy_without_render": [".github/*"],
4+
"_copy_without_render": [".github/workflows/*"],
55
"package_short_description": "",
6+
"keyword1": "keyword1",
7+
"keyword2": "keyword2",
68
"version": "0.1.0",
79
"github_organization": "<my-github-organization>",
810
"license": ["Apache Software License 2.0", "MIT license", "BSD license", "ISC license", "GNU General Public License v3 or later", "Not open source"],

tests/test_project.py

Lines changed: 41 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,15 @@
11
import os
22
import subprocess
3+
from pathlib import Path
4+
from shutil import which
35
from sys import platform
46
from typing import Sequence
57

68
import pytest
79

10+
IS_WINDOWS = platform.startswith("win")
11+
IS_WINDOWS_CI = IS_WINDOWS and os.environ.get('CI', False)
12+
813

914
def test_project_folder(cookies):
1015
project = cookies.bake()
@@ -16,37 +21,46 @@ def test_project_folder(cookies):
1621

1722

1823
def run(args: Sequence[str], dirpath: os.PathLike) -> subprocess.CompletedProcess:
19-
return subprocess.run(args=args,
20-
stdout=subprocess.PIPE,
21-
stderr=subprocess.PIPE,
22-
cwd=dirpath,
23-
encoding="utf-8")
24+
completed_process = subprocess.run(args=args,
25+
stdout=subprocess.PIPE,
26+
stderr=subprocess.PIPE,
27+
cwd=dirpath,
28+
encoding="utf-8")
29+
print(completed_process.stdout)
30+
print(completed_process.stderr)
31+
return completed_process
2432

2533

2634
@pytest.fixture
2735
def baked_with_development_dependencies(cookies):
2836
result = cookies.bake()
29-
env_output = run(['python3', '-m', 'venv', 'env'], result.project)
30-
assert env_output.returncode == 0
31-
env_bin = 'env/Scripts/' if platform.startswith("win") else 'env/bin/'
32-
latest_pip_output = run([f'{env_bin}pip3', 'install', '--upgrade', 'pip', 'setuptools'], result.project)
37+
if IS_WINDOWS_CI:
38+
# Creating virtualenv does not work on Windows CI,
39+
# falling back to using current pip3 dir
40+
pip = Path(which('pip3'))
41+
bin_dir = str(pip.parent) + '\\'
42+
else:
43+
env_output = run(['python3', '-m', 'venv', 'env'], result.project)
44+
assert env_output.returncode == 0
45+
bin_dir = 'env/Scripts/' if IS_WINDOWS else 'env/bin/'
46+
latest_pip_output = run([f'{bin_dir}pip3', 'install', '--upgrade', 'pip', 'setuptools'], result.project)
3347
assert latest_pip_output.returncode == 0
34-
pip_output = run([f'{env_bin}pip3', 'install', '--editable', '.[dev]'], result.project)
48+
pip_output = run([f'{bin_dir}pip3', 'install', '--editable', '.[dev]'], result.project)
3549
assert pip_output.returncode == 0
36-
return result.project, env_bin
50+
return result.project, bin_dir
3751

3852

3953
def test_pytest(baked_with_development_dependencies):
40-
project_dir, env_bin = baked_with_development_dependencies
41-
pytest_output = run([f'{env_bin}pytest'], project_dir)
54+
project_dir, bin_dir = baked_with_development_dependencies
55+
pytest_output = run([f'{bin_dir}pytest'], project_dir)
4256
assert pytest_output.returncode == 0
4357
assert '== 4 passed in' in pytest_output.stdout
4458
assert (project_dir / 'coverage.xml').exists()
4559
assert (project_dir / 'htmlcov/index.html').exists()
4660

4761

4862
def test_subpackage(baked_with_development_dependencies):
49-
project_dir, env_bin = baked_with_development_dependencies
63+
project_dir, bin_dir = baked_with_development_dependencies
5064
subpackage = (project_dir / 'my_python_package' / 'mysub')
5165
subpackage.mkdir()
5266
(subpackage / '__init__.py').write_text('FOO = "bar"', encoding="utf-8")
@@ -55,7 +69,19 @@ def test_subpackage(baked_with_development_dependencies):
5569
subsubpackage.mkdir()
5670
(subsubpackage / '__init__.py').write_text('FOO = "bar"', encoding="utf-8")
5771

58-
build_output = run([f'{env_bin}python3', 'setup.py', 'build'], project_dir)
72+
if IS_WINDOWS_CI:
73+
# On Windows CI python and pip executable are in different paths
74+
bin_dir = ''
75+
build_output = run([f'{bin_dir}python', 'setup.py', 'build'], project_dir)
5976
assert build_output.returncode == 0
6077
assert (project_dir / 'build' / 'lib' / 'my_python_package' / 'mysub' / '__init__.py').exists()
6178
assert (project_dir / 'build' / 'lib' / 'my_python_package' / 'mysub' / 'mysub2' / '__init__.py').exists()
79+
80+
81+
def test_generate_api_docs(baked_with_development_dependencies):
82+
project_dir, bin_dir = baked_with_development_dependencies
83+
84+
build_output = run([f'{bin_dir}sphinx-build', '-b', 'html', 'docs', 'docs/_build/html'], project_dir)
85+
assert build_output.returncode == 0
86+
assert 'build succeeded' in build_output.stdout
87+
assert (project_dir / 'docs' / '_build' / 'html' / 'index.html').exists()
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
---
2+
title: 'Next step: Citation data'
3+
---
4+
5+
It is likely that your `CITATION.cff` currently doesn't pass validation. The error messages you get from the [`cffconvert`]({{cookiecutter.repository}}/actions/workflows/cffconvert.yml) GitHub Action are unfortunately a bit cryptic, but doing the following helps:
6+
7+
- [ ] 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
8+
- [ ] 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/).
9+
- [ ] Add more authors if needed
10+
- [ ] Update `date-released` using the YYYY-MM-DD format.
11+
- [ ] 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.
12+
- [ ] Verify that the `keywords` array accurately describes your project.
13+
14+
Once you do all the steps above, the `cffconvert` workflow will tell you what content it expected to see in `.zenodo.json`. Copy-paste from the GitHub Action log into a new file `.zenodo.json`. Afterwards, the `cffconvert` GitHub Action should be green.
15+
16+
17+
To help you keep the citation metadata up to date and synchronized, the [`cffconvert`]({{cookiecutter.repository}}/actions/workflows/cffconvert.yml) GitHub Action checks the following 6 aspects:
18+
19+
1. Whether your repository includes a `CITATION.cff` file.
20+
21+
_By including this file, authors of the software can receive credit for the work they put in._
22+
23+
1. Whether your `CITATION.cff` is valid YAML.
24+
25+
_Visit http://www.yamllint.com/ to see if the contents of your CITATION.cff are valid YAML._
26+
27+
1. Whether your `CITATION.cff` adheres to the schema (as listed in the `CITATION.cff` file itself under key `cff-version`).
28+
29+
_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._
30+
31+
1. Whether your repository includes a `.zenodo.json` file.
32+
33+
_With this file, you can control what metadata should be associated with any future releases of your software on Zenodo: things like the author names, along with their affiliations and their ORCIDs, the license under which the software has been released, as well as the name of your software and a short description. If your repository doesn't have a .zenodo.json file, Zenodo will take a somewhat crude guess to assign these metadata._
34+
35+
_The `cffconvert` GitHub action will tell you what it expects to find in `.zenodo.json`, just copy and paste it to a new file named `.zenodo.json`. The suggested text ignores CITATION.cff's `version`, `commit`, and `date-released`. `cffconvert` considers these keys `suspect` in the sense that they are often out of date, and there is little purpose to telling Zenodo about these properties: Zenodo already knows._
36+
37+
1. Whether `.zenodo.json` is valid JSON.
38+
39+
_Currently unimplemented, but you can check for yourself on [https://jsonlint.com/](https://jsonlint.com/)._
40+
41+
1. Whether `CITATION.cff` and `.zenodo.json` contain equivalent data.
42+
43+
_This final check verifies that the two files are in sync. The check ignores CITATION.cff's `version`, `commit`, and `date-released`._

{{cookiecutter.project_name}}/.github/next_steps/02_zenodo_integration.md

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

{{cookiecutter.project_name}}/.github/next_steps/04_citation.md

Lines changed: 0 additions & 5 deletions
This file was deleted.
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
---
2+
title: 'Next step: Enable Zenodo integration'
3+
---
4+
5+
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.
6+
7+
To enable Zenodo integration:
8+
9+
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.
10+
1. Go to <https://zenodo.org/account/settings/github/> and enable Zenodo integration of your repository by clicking on `On` toggle button.
11+
2. Your package will get a DOI only after you make a release. Create a new release as described in [README.dev.md]({{cookiecutter.repository}}/blob/main/README.dev.md#33-github)
12+
3. At this point you should have a DOI. To find out the DOI generated by Zenodo:
13+
1. Visit https://zenodo.org/deposit and click on your repository link
14+
2. You will find the latest DOI in the right column in Versions box in **Cite all versions?** section
15+
3. Copy the text of the link. For example `10.5281/zenodo.1310751`
16+
4. Update the badge in your repository
17+
1. Edit README.md and replace the badge placeholder with the badge link you copied in previous step.
18+
The badge placeholder is shown below.
19+
20+
`[![DOI](https://zenodo.org/badge/DOI/<replace-with-created-DOI>.svg)](https://doi.org/<replace-with-created-DOI>)`
21+
22+
For FAQ about Zenodo please visit <https://help.zenodo.org/>.

0 commit comments

Comments
 (0)