Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Several improvements #8

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 35 additions & 0 deletions LICENSES/pyrepo-LICENSE
Original file line number Diff line number Diff line change
@@ -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.
3 changes: 1 addition & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.



Expand Down
2 changes: 2 additions & 0 deletions cookiecutter.json
Original file line number Diff line number Diff line change
Expand Up @@ -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/*"
]
Expand Down
20 changes: 20 additions & 0 deletions hooks/post_gen_project.py
Original file line number Diff line number Diff line change
@@ -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"])
14 changes: 14 additions & 0 deletions hooks/pre_gen_project.py
Original file line number Diff line number Diff line change
@@ -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)
34 changes: 34 additions & 0 deletions {{cookiecutter.github_project_name}}/.pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -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]
34 changes: 29 additions & 5 deletions {{cookiecutter.github_project_name}}/LICENSE
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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
Expand All @@ -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 %}
5 changes: 4 additions & 1 deletion {{cookiecutter.github_project_name}}/docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 ---------------------------------------------------
Expand Down
27 changes: 25 additions & 2 deletions {{cookiecutter.github_project_name}}/setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -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 %}
17 changes: 6 additions & 11 deletions {{cookiecutter.github_project_name}}/setup.py
Original file line number Diff line number Diff line change
@@ -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)
Original file line number Diff line number Diff line change
Expand Up @@ -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",
]

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
__version__ = "0.1.0"