Skip to content

Commit 37f59bb

Browse files
ojeda-eorbeckst
andauthored
Feat: Modernize license options (#156)
* Feat: Add license options in prompt * Feat: Extend supported licenses: GPL-3, MIT, BSD-3, Apace-2.0 * set default license to MIT * Chore: Delete obsolete/nan files * Docs: Update with new extended license support * Fix: Delete leftover licenses dir - post gen * Feat: Add tests support license options; modernize type hints * Chore: update CHANGELOG + AUTHORS * Refact: Use SPDX as lookup in setup * Chore: Remove deprecated classifiers * Fix: Set license w/ SPDX - PEP639 * Add AUTHORS to pyproject.toml license files * Update {{cookiecutter.repo_name}}/devtools/conda-envs/test_env.yaml * use conda instead of mamba in {{cookiecutter._ci_name}}.yaml (see MDAnalysis/install-mdanalysis#11 ) --------- Co-authored-by: Oliver Beckstein <orbeckst@gmail.com>
1 parent 938abd0 commit 37f59bb

21 files changed

Lines changed: 1064 additions & 378 deletions

File tree

.github/actions/run-cookie-ci/action.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ runs:
4848
- name: Install act
4949
uses: actionsflow/setup-act@v1
5050
with:
51-
version: '0.2.63'
51+
version: '0.2.81'
5252

5353
- name: Build Act image
5454
shell: bash

AUTHORS.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,5 +29,5 @@ The rules for this file:
2929
**2024**
3030
- Lawson Woods \<@ljwoods2\>
3131

32-
**2024**
32+
**2026**
3333
- Estefania Barreto-Ojeda \<@ojeda-e\>

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ The rules for this file:
3131

3232
### Added
3333
<!-- New added features -->
34+
- Extend license options to MIT (default), GPLv3+, BSD 3-clause and Apache 2 (PR #156)
3435
- Add black configurartion to `pyproject.toml` (Issue #73, PR #75)
3536
- Cookiecutter version dependency (Issue #33, PR #46)
3637
- Configuration files for external hooks (PR #9)

cookiecutter.json

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,25 @@
1717
"n"
1818
],
1919
"template_analysis_class": "Class name to template (e.g. {{ cookiecutter.project_name.title().replace(' ', '').replace('-', '').replace('_', '') }} ). Press Enter to skip including analysis templates",
20+
"license": [
21+
"MIT License",
22+
"GNU General Public License v3 or later (GPL-3.0+)",
23+
"BSD 3-Clause License",
24+
"Apache License 2.0"
25+
],
26+
"_license_SPDX_identifiers": {
27+
"MIT License":"MIT",
28+
"GNU General Public License v3 or later (GPL-3.0+)":"GPL-3.0-or-later",
29+
"BSD 3-Clause License":"BSD-3-Clause",
30+
"Apache License 2.0":"Apache-2.0"
31+
},
32+
"_license_details": {
33+
"MIT": ["MIT License", "yellow", "https://opensource.org/licenses/MIT", "MIT"],
34+
"GPL-3.0-or-later": ["GNU General Public License v3 or later", "blue", "https://www.gnu.org/licenses/gpl-3.0", "GPLv3"],
35+
"BSD-3-Clause": ["BSD 3-Clause License", "blue", "https://opensource.org/licenses/BSD-3-Clause", "BSD 3--Clause"],
36+
"Apache-2.0": ["Apache License 2.0", "green", "https://opensource.org/licenses/Apache-2.0", "Apache 2.0"]
37+
},
38+
"__license": "{{ cookiecutter.license }}",
2039
"_mda_cc_version": 0.1,
2140
"_ci_name": "gh-ci",
2241
"_central_branch_name": "main",
@@ -27,4 +46,4 @@
2746
},
2847
"__dependency_source": "{{ cookiecutter._dependency_source_keys[cookiecutter.dependency_source] }}",
2948
"_copy_without_render": []
30-
}
49+
}

docs/scripts/file_descriptions.yaml

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,7 @@ README.md: Description of project which GitHub will render
2020

2121
# packaging
2222
MANIFEST.in: Packaging information for pip
23-
pyproject.toml: Dependencies for pip
24-
setup.cfg: Near-master config file settings for Coverage, Flake8, YAPF, etc
25-
setup.py: Your package's setup file for installing with additional options that can be set
26-
versioneer.py: Automatic version control with Versioneer
23+
pyproject.toml: Standard configuration file for Python projects.
2724

2825
# config
2926
.codecov.yml: Settings for Codecov

docs/scripts/generate_cookiecutter_cli.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -97,12 +97,13 @@ def generate_cli_output(self) -> str:
9797
self.package_name, # package_name
9898
"A package to do MD analysis", # description
9999
"my-github-username", # github_username,
100-
"", # github_host_account
100+
"my-github-username", # github_host_account
101101
"My Name", # author_name
102102
"my_example_email@gmail.com", # author_email
103-
"", # dependency_source
104-
"", # include_ReadTheDocs
103+
"3", # dependency_source
104+
"1", # include_ReadTheDocs
105105
"MyAnalysisClass", # template_analysis_class
106+
"1", # license
106107
]
107108

108109
with tempfile.TemporaryDirectory() as tmpdir:
@@ -114,7 +115,9 @@ def generate_cli_output(self) -> str:
114115
capture_output=True,
115116
input="\n".join(inputs),
116117
cwd=tmpdir,
118+
check=True
117119
)
120+
118121
source_repo = os.path.join(tmpdir, self.repo_name)
119122
destination_repo = str(self.example_repo_path.resolve())
120123
shutil.rmtree(destination_repo, ignore_errors=True)

docs/source/customising.rst

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,10 @@ ammend appropriately:
3131
.. _general-info:
3232

3333
* **License:** Your code needs to be clearly licensed so that users know if
34-
they can (legally) use it. The cookiecutter will apply the **GPLv2**
35-
license by default, included in the ``LICENSE`` file. If you decide to use a
36-
different license (see `ChooseALicense <https://choosealicense.com/>`_), also
37-
update the copyright infromation in ``README.md``.
34+
they can (legally) use it. During generation users choose one of the supported licenses
35+
(defaults to **MIT**) and the cookiecutter fills ``LICENSE`` from that choice.
36+
Users can later change licenses (see `ChooseALicense <https://choosealicense.com/>`_)
37+
and update the copyright information in ``README.md``.
3838

3939
* **README:** ``README.md`` is the introductory explanation to you project; it
4040
will be rendered on your GitHub repo's home page. It has been pre-filled with

docs/source/files.rst

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,8 @@ follow classifications:
4141
- Modify?
4242
* - ``LICENSE``
4343
- :ref:`GENERAL INFORMATION <general-info>`
44-
- File containing the details of the GPLv2 license, the default license for packages developed from the MDAKit cookiecutter
45-
- **YES** - without a clear license, *no-one* can legally use your code
46-
- **OPTIONAL** - you can opt for a license other than GPLv2
44+
- Generated license text from your chosen option (MIT, GPL-3.0+, BSD 3-Clause, or Apache 2.0).
45+
- **YES** - without a clear license, *no-one* can legally use your code.
4746
* - ``README.md``
4847
- :ref:`GENERAL INFORMATION <general-info>`
4948
- A basic introduction/overview of the package; this file will be rendered on the GitHub repo's home

hooks/post_gen_project.py

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,13 @@
1414
"{{ cookiecutter._mda_cc_version }}"
1515
)
1616

17+
LICENSE_OPTIONS = {
18+
"MIT": "MIT.txt",
19+
"GPL-3.0-or-later": "GPL-3.0.txt",
20+
"BSD-3-Clause": "BSD-3.txt",
21+
"Apache-2.0": "Apache-2.0.txt",
22+
}
23+
1724

1825
def remove_files(*paths):
1926
for path in paths:
@@ -103,7 +110,37 @@ def remove_placeholder_icons():
103110
remove_files("docs/source/_static/logo")
104111

105112

113+
def set_license():
114+
"""Set LICENSE from template"""
115+
license_name = "{{ cookiecutter.license }}"
116+
repo_root = pathlib.Path.cwd()
117+
dest = repo_root / "LICENSE"
118+
licenses_dir = repo_root / "licenses"
119+
120+
if license_name in LICENSE_OPTIONS:
121+
src = licenses_dir / LICENSE_OPTIONS[license_name]
122+
shutil.copy(src, dest)
123+
else:
124+
supported_licenses = ", ".join(LICENSE_OPTIONS.keys())
125+
raise ValueError(
126+
f"Unsupported license: {license_name!r}. "
127+
f"Supported licenses are: {supported_licenses}"
128+
)
129+
130+
for filename in LICENSE_OPTIONS.values():
131+
path = licenses_dir / filename
132+
if path.is_file():
133+
path.unlink()
134+
135+
if licenses_dir.is_dir():
136+
try:
137+
licenses_dir.rmdir()
138+
except OSError:
139+
pass
140+
141+
106142
if __name__ == "__main__":
143+
set_license()
107144
remove_rtd()
108145
remove_analysis()
109146
remove_placeholder_icons()

hooks/pre_gen_project.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,8 @@
3939
4040
=== LICENSE ===
4141
42-
{{ cookiecutter.update({"open_source_license": 'GNU Public License v2+'}) }}
42+
{% set _license_trimmed = cookiecutter.license | trim %}
43+
{{ cookiecutter.update({"license": cookiecutter._license_SPDX_identifiers[_license_trimmed] if _license_trimmed in cookiecutter._license_SPDX_identifiers else _license_trimmed}) }}
4344
4445
"""
4546

0 commit comments

Comments
 (0)