diff --git a/LICENSES/pyrepo-LICENSE b/LICENSES/pyrepo-LICENSE new file mode 100644 index 0000000..845bed3 --- /dev/null +++ b/LICENSES/pyrepo-LICENSE @@ -0,0 +1,35 @@ +The code from commits: +0826b3f1b60692baa689ca97881766879dfdf70b +9420e69b5ac53223947313b705f31d4db603f10f + +was taken nearly verbatim from https://github.com/tlambert03/pyrepo-cookiecutter + +BSD 3-Clause License + +Copyright (c) 2021, Talley Lambert +All rights reserved. + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions are met: + +1. Redistributions of source code must retain the above copyright notice, this + list of conditions and the following disclaimer. + +2. Redistributions in binary form must reproduce the above copyright notice, + this list of conditions and the following disclaimer in the documentation + and/or other materials provided with the distribution. + +3. Neither the name of the copyright holder nor the names of its + contributors may be used to endorse or promote products derived from + this software without specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE +FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR +SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER +CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, +OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. diff --git a/README.md b/README.md index c009efc..24f4d3d 100644 --- a/README.md +++ b/README.md @@ -77,8 +77,7 @@ A good rule of thumb is to ask yourself: If it were homework and you didn't acknowledge would it be cheating? -If the answer is yes, then you should leave a comment in the code and include a license file in a top level `LICENSE` folder. - +If the answer is yes, then you should leave a comment in the code and include a license file in a top level `LICENSE` folder. For example, this repo uses code from other projects so their licenses are included in the `LICENSE` folder. diff --git a/cookiecutter.json b/cookiecutter.json index f6618a0..cc22e6e 100644 --- a/cookiecutter.json +++ b/cookiecutter.json @@ -5,7 +5,9 @@ "github_project_name": "", "python_package_name": "{{ cookiecutter.github_project_name | replace('-', '_') }}", "project_short_description": "A 3rd party package for Matplotlib", + "version_control": ["setuptools-scm", "_version.py", "bump2version"], "year": "2021", + "license": ["BSD license", "MIT license", "No license"], "_copy_without_render": [ ".github/workflows/*" ] diff --git a/hooks/post_gen_project.py b/hooks/post_gen_project.py new file mode 100644 index 0000000..d07ba6e --- /dev/null +++ b/hooks/post_gen_project.py @@ -0,0 +1,20 @@ +#!/usr/bin/env python +import os +import subprocess +from contextlib import suppress + +PROJECT_DIRECTORY = os.path.realpath(os.path.curdir) + + +def remove_file(filepath): + os.remove(os.path.join(PROJECT_DIRECTORY, filepath)) + + +if __name__ == "__main__": + if "No license" == "{{ cookiecutter.license }}": + remove_file("LICENSE") + + with suppress(Exception): + subprocess.run(["git", "init", "-q"]) + subprocess.run(["git", "add", "."]) + subprocess.run(["git", "commit", "-q", "-m", "initial commit"]) diff --git a/hooks/pre_gen_project.py b/hooks/pre_gen_project.py new file mode 100644 index 0000000..893fc60 --- /dev/null +++ b/hooks/pre_gen_project.py @@ -0,0 +1,14 @@ +import re +import sys + +MODULE_REGEX = r"^[_a-zA-Z][_a-zA-Z0-9]+$" + +module_name = "{{ cookiecutter.project_slug}}" + +if not re.match(MODULE_REGEX, module_name): + print( + f"ERROR: The project slug ({module_name}) is not a valid Python module name. " + "Please do not use a - and use _ instead" + ) + + sys.exit(1) diff --git a/{{cookiecutter.github_project_name}}/.pre-commit-config.yaml b/{{cookiecutter.github_project_name}}/.pre-commit-config.yaml new file mode 100644 index 0000000..9dc202c --- /dev/null +++ b/{{cookiecutter.github_project_name}}/.pre-commit-config.yaml @@ -0,0 +1,34 @@ +repos: + - repo: https://github.com/pre-commit/pre-commit-hooks + rev: v4.0.1 + hooks: + - id: check-docstring-first + - id: end-of-file-fixer + - id: trailing-whitespace + - repo: https://github.com/asottile/setup-cfg-fmt + rev: v1.17.0 + hooks: + - id: setup-cfg-fmt + - repo: https://github.com/PyCQA/flake8 + rev: 3.9.2 + hooks: + - id: flake8 + additional_dependencies: [flake8-typing-imports==1.7.0] + - repo: https://github.com/myint/autoflake + rev: v1.4 + hooks: + - id: autoflake + args: ["--in-place", "--remove-all-unused-imports" "--ignore-init-module-imports", "--remove-unused-variables"] + - repo: https://github.com/PyCQA/isort + rev: 5.8.0 + hooks: + - id: isort + - repo: https://github.com/psf/black + rev: 21.5b2 + hooks: + - id: black + - repo: https://github.com/asottile/pyupgrade + rev: v2.19.0 + hooks: + - id: pyupgrade + args: [--py37-plus] \ No newline at end of file diff --git a/{{cookiecutter.github_project_name}}/LICENSE b/{{cookiecutter.github_project_name}}/LICENSE index 0499f9a..67886e3 100644 --- a/{{cookiecutter.github_project_name}}/LICENSE +++ b/{{cookiecutter.github_project_name}}/LICENSE @@ -1,6 +1,29 @@ -BSD 3-Clause License +{% if cookiecutter.license == 'MIT license' -%} +MIT License -Copyright (c) {{ cookiecutter.year }}, {{ cookiecutter.author_name }} +Copyright (c) {% now 'local', '%Y' %}, {{ cookiecutter.author_name }} + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. +{% elif cookiecutter.license == 'BSD license' %} +BSD License + +Copyright (c) {% now 'local', '%Y' %}, {{ cookiecutter.author_name }} All rights reserved. Redistribution and use in source and binary forms, with or without @@ -13,9 +36,9 @@ modification, are permitted provided that the following conditions are met: this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. -3. Neither the name of the copyright holder nor the names of its contributors - may be used to endorse or promote products derived from this software - without specific prior written permission. +3. Neither the name of the copyright holder nor the names of its + contributors may be used to endorse or promote products derived from + this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE @@ -27,3 +50,4 @@ SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +{% endif %} \ No newline at end of file diff --git a/{{cookiecutter.github_project_name}}/docs/conf.py b/{{cookiecutter.github_project_name}}/docs/conf.py index 318604f..1f5c5ba 100644 --- a/{{cookiecutter.github_project_name}}/docs/conf.py +++ b/{{cookiecutter.github_project_name}}/docs/conf.py @@ -22,7 +22,10 @@ author = '{{ cookiecutter.author_name }}' # The full version, including alpha/beta/rc tags -from _version import __version__ as release +try: + from _version import __version__ as release +except ImportError: + release = "unknown" # -- General configuration --------------------------------------------------- diff --git a/{{cookiecutter.github_project_name}}/setup.cfg b/{{cookiecutter.github_project_name}}/setup.cfg index cb3ccda..aa04611 100644 --- a/{{cookiecutter.github_project_name}}/setup.cfg +++ b/{{cookiecutter.github_project_name}}/setup.cfg @@ -35,5 +35,28 @@ doc = sphinx_gallery>=0.8.2 autoapi dev = - %(test)s - %(doc)s + black + pytest + pytest-mpl + sphinx + numpydoc + sphinx_rtd_theme + sphinx-copybutton + sphinx-autobuild + sphinx_gallery>=0.8.2 + autoapi + +{% if cookiecutter.version_control == 'bump2version' -%} +[bumpversion] +current_version = '0.0.1' +commit = True +tag = True + +[bumpversion:file:setup.cfg] +search = version='{current_version}' +replace = version='{new_version}' + +[bumpversion:file:{{ cookiecutter.python_package_name }}/__init__.py] +search = __version__ = '{current_version}' +replace = __version__ = '{new_version}' +{%- endif %} \ No newline at end of file diff --git a/{{cookiecutter.github_project_name}}/setup.py b/{{cookiecutter.github_project_name}}/setup.py index d051290..18613c8 100644 --- a/{{cookiecutter.github_project_name}}/setup.py +++ b/{{cookiecutter.github_project_name}}/setup.py @@ -1,17 +1,12 @@ -from os import path - -from setuptools import find_packages, setup - -# extract version -path = path.realpath("{{ cookiecutter.python_package_name }}/_version.py") -version_ns = {} -with open(path, encoding="utf8") as f: - exec(f.read(), {}, version_ns) -version = version_ns["__version__"] +from setuptools import setup +{% if cookiecutter.version_control == 'setuptools-scm' -%} setup_args = dict( - version=version, + use_scm_version={"write_to": "{{cookiecutter.python_package_name}}/_version.py"} ) +{%- else -%} +setup_args = dict() +{%- endif %} if __name__ == "__main__": setup(**setup_args) diff --git a/{{cookiecutter.github_project_name}}/{{cookiecutter.python_package_name}}/__init__.py b/{{cookiecutter.github_project_name}}/{{cookiecutter.python_package_name}}/__init__.py index 09af2ae..2f0efc5 100644 --- a/{{cookiecutter.github_project_name}}/{{cookiecutter.python_package_name}}/__init__.py +++ b/{{cookiecutter.github_project_name}}/{{cookiecutter.python_package_name}}/__init__.py @@ -4,9 +4,17 @@ # Copyright (c) {{ cookiecutter.author_name }}. # Distributed under the terms of the Modified BSD License. -# Must import __version__ first to avoid errors importing this file during the build process. +# Must import __version__ first to avoid errors importing this file during the build process. # See https://github.com/pypa/setuptools/issues/1724#issuecomment-627241822 -from ._version import __version__ +try: + from ._version import __version__ +except ImportError: + __version__ = "unknown" from .example import example_function + +__all__ = [ + "__version__", + "example_function", +] diff --git a/{{cookiecutter.github_project_name}}/{{cookiecutter.python_package_name}}/_version.py b/{{cookiecutter.github_project_name}}/{{cookiecutter.python_package_name}}/_version.py deleted file mode 100644 index 22ceed0..0000000 --- a/{{cookiecutter.github_project_name}}/{{cookiecutter.python_package_name}}/_version.py +++ /dev/null @@ -1,8 +0,0 @@ -#!/usr/bin/env python -# coding: utf-8 - -# Copyright (c) {{ cookiecutter.author_name }}. -# Distributed under the terms of the Modified BSD License. - -version_info = (0, 1, 0) -__version__ = ".".join(map(str, version_info)) diff --git a/{{cookiecutter.github_project_name}}/{{cookiecutter.python_package_name}}/{% if cookiecutter.version_control == '_version.py' %}_version.py{% endif %} b/{{cookiecutter.github_project_name}}/{{cookiecutter.python_package_name}}/{% if cookiecutter.version_control == '_version.py' %}_version.py{% endif %} new file mode 100644 index 0000000..a68927d --- /dev/null +++ b/{{cookiecutter.github_project_name}}/{{cookiecutter.python_package_name}}/{% if cookiecutter.version_control == '_version.py' %}_version.py{% endif %} @@ -0,0 +1 @@ +__version__ = "0.1.0" \ No newline at end of file