Skip to content

Commit

Permalink
Merge pull request #352 from NLeSC/pyproject-toml-351
Browse files Browse the repository at this point in the history
move setup.cfg to pyproject.toml
  • Loading branch information
egpbos authored Oct 19, 2023
2 parents 795794e + 3d9889c commit d1086f8
Show file tree
Hide file tree
Showing 18 changed files with 107 additions and 101 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

### Changed

* Moved from setup.cfg/.py to pyproject.toml [#351](https://github.com/NLeSC/python-template/issues/351)
* Moved from prospector to ruff [#336](https://github.com/NLeSC/python-template/issues/336)
* Renamed `project_name` to `directory_name` in cookiecutter questionnaire
* Initial linting is error free [#227](https://github.com/NLeSC/python-template/issues/227)
Expand Down
1 change: 1 addition & 0 deletions hooks/pre_gen_project.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,6 @@
"directory_name": cookiecutter.directory_name.lower().replace(" ", "-"),
"full_name": cookiecutter.full_name.replace('\"', '\\\"'),
"repository": "git@github.com:" + cookiecutter.github_organization + "/" + cookiecutter.directory_name.lower().replace(" ", "-"),
"repository_url": "https://github.com/" + cookiecutter.github_organization + "/" + cookiecutter.directory_name.lower().replace(" ", "-"),
"package_short_description": cookiecutter.package_short_description.replace('\"', '\\\"')
}) }}
6 changes: 3 additions & 3 deletions tests/test_project.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ def test_subpackage(baked_with_development_dependencies, project_env_bin_dir):

# sdist and bdist_wheel both call build command to create build/ dir
# So instead of looking in distribution archives we can look in build/ dir
result = run([f'{bin_dir}python', 'setup.py', 'build'], project_dir)
result = run([f'{bin_dir}python', '-m', 'build', '--sdist', '--wheel'], project_dir)
assert result.returncode == 0
assert (project_dir / 'build' / 'lib' / 'my_python_package' / 'mysub' / '__init__.py').exists()
assert (project_dir / 'build' / 'lib' / 'my_python_package' / 'mysub' / 'mysub2' / '__init__.py').exists()
Expand Down Expand Up @@ -172,7 +172,7 @@ def test_bumpversion(baked_with_development_dependencies, project_env_bin_dir):
bin_dir = project_env_bin_dir

original_version = '0.1.0'
assert original_version in (project_dir / 'setup.cfg').read_text('utf-8')
assert original_version in (project_dir / 'pyproject.toml').read_text('utf-8')
assert original_version in (project_dir / 'CITATION.cff').read_text('utf-8')
assert original_version in (project_dir / 'my_python_package' / '__init__.py').read_text('utf-8')
assert original_version in (project_dir / 'docs' / 'conf.py').read_text('utf-8')
Expand All @@ -181,7 +181,7 @@ def test_bumpversion(baked_with_development_dependencies, project_env_bin_dir):
assert result.returncode == 0
assert '' in result.stdout
expected_version = '1.0.0'
assert expected_version in (project_dir / 'setup.cfg').read_text('utf-8')
assert expected_version in (project_dir / 'pyproject.toml').read_text('utf-8')
assert expected_version in (project_dir / 'CITATION.cff').read_text('utf-8')
assert expected_version in (project_dir / 'my_python_package' / '__init__.py').read_text('utf-8')
assert expected_version in (project_dir / 'docs' / 'conf.py').read_text('utf-8')
6 changes: 3 additions & 3 deletions {{cookiecutter.directory_name}}/.bumpversion.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ comment = The contents of this file cannot be merged with that of setup.cfg unti
search = __version__ = "{current_version}"
replace = __version__ = "{new_version}"

[bumpversion:file:setup.cfg]
search = version = {current_version}
replace = version = {new_version}
[bumpversion:file:pyproject.toml]
search = version = "{current_version}"
replace = version = "{new_version}"

[bumpversion:file:CITATION.cff]
search = version: "{current_version}"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ 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]({{cookiecutter.repository}}/blob/main/.github/workflows/sonarcloud.yml) you must follow the steps below:
In order to configure Sonarcloud analysis [GitHub Action workflow]({{cookiecutter.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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
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`]({{cookiecutter.repository}}/actions/workflows/cffconvert.yml) GitHub Action are unfortunately a bit cryptic, but doing the following helps:
It is likely that your `CITATION.cff` currently doesn't pass validation. The error messages you get from the [`cffconvert`]({{cookiecutter.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/).
Expand All @@ -14,7 +14,7 @@ It is likely that your `CITATION.cff` currently doesn't pass validation. The err
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.


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:
To help you keep the citation metadata up to date and synchronized, the [`cffconvert`]({{cookiecutter.repository_url}}/actions/workflows/cffconvert.yml) GitHub Action checks the following 6 aspects:

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,6 @@ To host the documentation of this repository please perform the following instru
2. make sure {{ cookiecutter.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/{{ cookiecutter.directory_name }}/builds>
1. check that the link of the documentation badge in the [README.md]({{ cookiecutter.repository }}) works
1. check that the link of the documentation badge in the [README.md]({{ cookiecutter.repository_url }}) works

See [README.dev.md#]({{cookiecutter.repository}}/blob/main/README.dev.md#generating-the-api-docs) how to build documentation site locally.
See [README.dev.md#]({{cookiecutter.repository_url}}/blob/main/README.dev.md#generating-the-api-docs) how to build documentation site locally.
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ 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]({{cookiecutter.repository}}/blob/main/README.dev.md#33-github)
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_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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
title: 'Next step: Linting'
---

Your repository has a [workflow]({{ cookiecutter.repository }}/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.
Your repository has a [workflow]({{ cookiecutter.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 [setup.cfg]({{ cookiecutter.repository }}/blob/main/setup.cfg) is empty. Please update these fields. To validate your changes run:
Linter workflow may fail if `description` or `keywords` field in [setup.cfg]({{ cookiecutter.repository_url }}/blob/main/setup.cfg) is empty. Please update these fields. To validate your changes run:

```shell
ruff .
Expand Down
2 changes: 1 addition & 1 deletion {{cookiecutter.directory_name}}/CITATION.cff
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ authors:
date-released: 20??-MM-DD
doi: <insert your DOI here>
version: "{{ cookiecutter.version }}"
repository-code: "{{ cookiecutter.repository }}"
repository-code: "{{ cookiecutter.repository_url }}"
keywords:
- {{ cookiecutter.keyword1 }}
- {{ cookiecutter.keyword2 }}
Expand Down
4 changes: 2 additions & 2 deletions {{cookiecutter.directory_name}}/CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,13 @@ The sections below outline the steps in each case.

## You have a question

1. use the search functionality [here]({{cookiecutter.repository}}/issues) to see if someone already filed the same issue;
1. use the search functionality [here]({{cookiecutter.repository_url}}/issues) to see if someone already filed the same issue;
2. if your issue search did not yield any relevant results, make a new issue;
3. apply the "Question" label; apply other labels when relevant.

## You think you may have found a bug

1. use the search functionality [here]({{cookiecutter.repository}}/issues) to see if someone already filed the same issue;
1. use the search functionality [here]({{cookiecutter.repository_url}}/issues) to see if someone already filed the same issue;
1. if your issue search did not yield any relevant results, make a new issue, making sure to provide enough information to the rest of the community to understand the cause and context of the problem. Depending on the issue, you may want to include:
- the [SHA hashcode](https://help.github.com/articles/autolinked-references-and-urls/#commit-shas) of the commit that is causing your problem;
- some identifying information (name and version number) for dependencies you're using;
Expand Down
2 changes: 1 addition & 1 deletion {{cookiecutter.directory_name}}/README.dev.md
Original file line number Diff line number Diff line change
Expand Up @@ -203,4 +203,4 @@ twine upload dist/*

### (3/3) GitHub

Don't forget to also make a [release on GitHub]({{cookiecutter.repository}}/releases/new). If your repository uses the GitHub-Zenodo integration this will also trigger Zenodo into making a snapshot of your repository and sticking a DOI on it.
Don't forget to also make a [release on GitHub]({{cookiecutter.repository_url}}/releases/new). If your repository uses the GitHub-Zenodo integration this will also trigger Zenodo into making a snapshot of your repository and sticking a DOI on it.
12 changes: 6 additions & 6 deletions {{cookiecutter.directory_name}}/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@

| fair-software.eu recommendations | |
| :-- | :-- |
| (1/5) code repository | [![github repo badge](https://img.shields.io/badge/github-repo-000.svg?logo=github&labelColor=gray&color=blue)]({{cookiecutter.repository}}) |
| (2/5) license | [![github license badge](https://img.shields.io/github/license/{{cookiecutter.github_organization}}/{{cookiecutter.directory_name}})]({{cookiecutter.repository}}) |
| (1/5) code repository | [![github repo badge](https://img.shields.io/badge/github-repo-000.svg?logo=github&labelColor=gray&color=blue)]({{cookiecutter.repository_url}}) |
| (2/5) license | [![github license badge](https://img.shields.io/github/license/{{cookiecutter.github_organization}}/{{cookiecutter.directory_name}})]({{cookiecutter.repository_url}}) |
| (3/5) community registry | [![RSD](https://img.shields.io/badge/rsd-{{cookiecutter.package_name}}-00a3e3.svg)](https://www.research-software.nl/software/{{cookiecutter.package_name}}) [![workflow pypi badge](https://img.shields.io/pypi/v/{{cookiecutter.package_name}}.svg?colorB=blue)](https://pypi.python.org/project/{{cookiecutter.package_name}}/) |
| (4/5) citation | [![DOI](https://zenodo.org/badge/DOI/<replace-with-created-DOI>.svg)](https://doi.org/<replace-with-created-DOI>) |
| (5/5) checklist | [![workflow cii badge](https://bestpractices.coreinfrastructure.org/projects/<replace-with-created-project-identifier>/badge)](https://bestpractices.coreinfrastructure.org/projects/<replace-with-created-project-identifier>) |
Expand All @@ -15,10 +15,10 @@
| Coverage | [![workflow scc badge](https://sonarcloud.io/api/project_badges/measure?project={{cookiecutter.github_organization}}_{{cookiecutter.directory_name}}&metric=coverage)](https://sonarcloud.io/dashboard?id={{cookiecutter.github_organization}}_{{cookiecutter.directory_name}}) |
| Documentation | [![Documentation Status](https://readthedocs.org/projects/{{cookiecutter.directory_name}}/badge/?version=latest)](https://{{cookiecutter.directory_name}}.readthedocs.io/en/latest/?badge=latest) |
| **GitHub Actions** | &nbsp; |
| Build | [![build]({{cookiecutter.repository}}/actions/workflows/build.yml/badge.svg)]({{cookiecutter.repository}}/actions/workflows/build.yml) |
| Citation data consistency | [![cffconvert]({{cookiecutter.repository}}/actions/workflows/cffconvert.yml/badge.svg)]({{cookiecutter.repository}}/actions/workflows/cffconvert.yml) |
| SonarCloud | [![sonarcloud]({{cookiecutter.repository}}/actions/workflows/sonarcloud.yml/badge.svg)]({{cookiecutter.repository}}/actions/workflows/sonarcloud.yml) |
| MarkDown link checker | [![markdown-link-check]({{cookiecutter.repository}}/actions/workflows/markdown-link-check.yml/badge.svg)]({{cookiecutter.repository}}/actions/workflows/markdown-link-check.yml) |
| Build | [![build]({{cookiecutter.repository_url}}/actions/workflows/build.yml/badge.svg)]({{cookiecutter.repository_url}}/actions/workflows/build.yml) |
| Citation data consistency | [![cffconvert]({{cookiecutter.repository_url}}/actions/workflows/cffconvert.yml/badge.svg)]({{cookiecutter.repository_url}}/actions/workflows/cffconvert.yml) |
| SonarCloud | [![sonarcloud]({{cookiecutter.repository_url}}/actions/workflows/sonarcloud.yml/badge.svg)]({{cookiecutter.repository_url}}/actions/workflows/sonarcloud.yml) |
| MarkDown link checker | [![markdown-link-check]({{cookiecutter.repository_url}}/actions/workflows/markdown-link-check.yml/badge.svg)]({{cookiecutter.repository_url}}/actions/workflows/markdown-link-check.yml) |

## How to use {{ cookiecutter.package_name }}

Expand Down
2 changes: 1 addition & 1 deletion {{cookiecutter.directory_name}}/next_steps.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ git push --set-upstream origin main
## Check automatically generated issues

A short while after you push your commits to GitHub for the first time, a few issues outlining next steps will added
automatically ([here]({{cookiecutter.repository}}/issues?q=author%3Aapp%2Fgithub-actions)). Resolve them to complete the
automatically ([here]({{cookiecutter.repository_url}}/issues?q=author%3Aapp%2Fgithub-actions)). Resolve them to complete the
setup of your repository.

## Project development documentation
Expand Down
78 changes: 77 additions & 1 deletion {{cookiecutter.directory_name}}/pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,70 @@
# see documentation, e.g.
# - https://packaging.python.org/en/latest/specifications/declaring-project-metadata/#declaring-project-metadata
# - https://setuptools.pypa.io/en/latest/userguide/pyproject_config.html
# - https://www.python.org/dev/peps/pep-0621/

[build-system]
requires = ["setuptools", "wheel"]
requires = ["setuptools>=64.0.0", "setuptools-scm", "wheel"]
build-backend = "setuptools.build_meta"

[project]
authors = [
{ name = "{{ cookiecutter.full_name }}", email = "{{ cookiecutter.email }}" }
]
classifiers = [
"Development Status :: 2 - Pre-Alpha",
"Intended Audience :: Developers",
"{{ {'Apache Software License 2.0': 'License :: OSI Approved :: Apache Software License',
'MIT license': 'License :: OSI Approved :: MIT License',
'BSD license': 'License :: OSI Approved :: BSD License',
'ISC license': 'License :: OSI Approved :: ISC License (ISCL)',
'GNU General Public License v3 or later': 'License :: OSI Approved :: GNU General Public License',
'Not open source': 'License :: Other/Proprietary License'
}[cookiecutter.license] }}",
"Natural Language :: English",
"Programming Language :: Python :: 3",
"Programming Language :: Python :: 3.7",
"Programming Language :: Python :: 3.8",
"Programming Language :: Python :: 3.9",
"Programming Language :: Python :: 3.10",
"Programming Language :: Python :: 3.11",
]
dependencies = []
description = "{{ cookiecutter.package_short_description }}"
keywords = [
"{{ cookiecutter.keyword1 }}",
"{{ cookiecutter.keyword2 }}",
]
license = {file = "LICENSE"}
name = "{{ cookiecutter.package_name }}"
readme = {file = "README.md", content-type = "text/markdown"}
requires-python = ">=3.7"
version = "{{ cookiecutter.version }}"

[project.optional-dependencies]
dev = [
"build",
"bump2version",
"coverage [toml]",
"pytest",
"pytest-cov",
"ruff",
"sphinx",
"sphinx_rtd_theme",
"sphinx-autoapi",
"tox",
"myst_parser",
]
publishing = [
"twine",
"wheel",
]

[project.urls]
Repository = "{{ cookiecutter.repository_url }}"
Issues = "{{ cookiecutter.repository_url }}/issues"
Changelog = "{{ cookiecutter.repository_url }}/CHANGELOG.md"

[tool.pytest.ini_options]
testpaths = ["tests"]

Expand All @@ -10,6 +73,19 @@ branch = true
source = ["{{ cookiecutter.package_name }}"]
command_line = "-m pytest"

[tool.isort]
lines_after_imports = 2
force_single_line = 1
no_lines_before = ["FUTURE", "STDLIB", "THIRDPARTY", "FIRSTPARTY", "LOCALFOLDER"]
known_first_party = "{{ cookiecutter.package_name }}"
src_paths = ["{{ cookiecutter.package_name }}", "tests"]
line_length = 120

# For completeness, until we move to an src-based layout
[tool.setuptools.packages.find]
include = ["{{ cookiecutter.package_name }}*"]
exclude = ["tests*"]

[tool.tox]
legacy_tox_ini = """
[tox]
Expand Down
Loading

0 comments on commit d1086f8

Please sign in to comment.