Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
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
2 changes: 1 addition & 1 deletion .github/pull_request_template.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@ Provide a description and/or bullet points to describe the changes in this PR.

- [ ] Reference issues which can be closed due to this PR with "Closes #x".
- [ ] Review whether the documentation needs to be updated.
- [ ] Document PR in CHANGES.rst.
- [ ] Document PR in docs/changes.rst.
1 change: 1 addition & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ repos:
rev: v1.0.1
hooks:
- id: tryceratops
exclude: "{{cookiecutter.project_slug}}/pyproject.toml"
- repo: https://github.com/pre-commit/mirrors-mypy
rev: 'v0.931'
hooks:
Expand Down
7 changes: 5 additions & 2 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ cookiecutter-pytask-project

.. image:: https://img.shields.io/github/license/pytask-dev/cookiecutter-pytask-project
:alt: MIT license
:target: https://pypi.org/project/pytask
:target: https://github.com/pytask-dev/cookiecutter-pytask-project

.. image:: https://readthedocs.org/projects/cookiecutter-pytask-project/badge/?version=latest
:target: https://cookiecutter-pytask-project.readthedocs.io/en/latest
Expand Down Expand Up @@ -53,4 +53,7 @@ A: This is called the src layout and the advantages are discussed in this `artic
Hynek Schlawack <https://hynek.me/articles/testing-packaging/>`_.

Although the article discusses the src layout in terms of Python packages, it is also
beneficial to structure a project the same way.
beneficial to structure a project the same way. Next to the reasons discussed there, it
is possible to use a single Python environment for multiple projects without messing
with your PYTHONPATH (via ``pip install -e .`` or ``conda develop .``) each time and
still import modules.
16 changes: 8 additions & 8 deletions cookiecutter.json
Original file line number Diff line number Diff line change
@@ -1,27 +1,27 @@
{
"author": "Arianna W. Rosenbluth",
"email": "{{ cookiecutter.author.lower().replace(' ', '') }}@mail.edu",
"email": "{{ cookiecutter.author.lower().replace(' ', '') }}@nowhere.edu",
"project_name": "Reproducible Research Template",
"project_slug": "{{ cookiecutter.project_name.lower().replace(' ', '_').replace('-', '_') }}",
"project_description": "A project for ...",
"github_username": "{{ cookiecutter.author.lower().replace(' ', '') }}",
"github_email": "{{ cookiecutter.email }}",
"version": "0.0.1",
"python_version": "3.8",
"add_tox": ["yes", "no"],
"add_github_actions": ["yes", "no"],
"add_mypy": ["yes", "no"],
"add_readthedocs": ["yes", "no"],
"add_codecov": ["yes", "no"],
"create_changelog": ["yes", "no"],
"open_source_license": [
"MIT", "BSD", "ISC", "Apache Software License 2.0",
"GNU General Public License v3", "Not open source"
"MIT",
"BSD",
"ISC",
"Apache Software License 2.0",
"GNU General Public License v3",
"Not open source"
],
"make_initial_commit": ["no", "yes"],
"conda_environment_name": "{{ cookiecutter.project_slug }}",
"create_conda_environment_at_finish": ["no", "yes"],
"_copy_without_render": [
".github/workflows/main.yml"
]
"_copy_without_render": [".github/workflows/main.yml"]
}
6 changes: 4 additions & 2 deletions docs/rtd_environment.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ channels:

dependencies:
- python >= 3.7
- pip
- pip >=21.1
- setuptools_scm
- toml

Expand All @@ -14,6 +14,8 @@ dependencies:
- nbsphinx
- sphinx
- sphinx-autoapi
- sphinx-click
- sphinx-copybutton
- sphinx-panels

- pip:
- -e ../
11 changes: 11 additions & 0 deletions docs/source/api.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
API Reference
=============

The following documents are auto-generated and not carefully edited. They provide direct
access to the source code and the docstrings.

.. toctree::
:titlesonly:

/autoapi/pre_gen_project/index
/autoapi/post_gen_project/index
9 changes: 8 additions & 1 deletion CHANGES.rst → docs/source/changes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,13 @@ Changes
This is a record of all past cookiecutter-pytask-project releases and what went into
them in reverse chronological order.

1.2.0 - 2022-xx-xx
------------------

- :gh:`7` skips concurrent CI builds.
- :gh:`8` harmonizes cookiecutter-pytask-project with econ-project-templates.
- :gh:`9` deprecates Python 3.6, add support for Python 3.10 and add mypy optionally.


1.1.0 - 2022-01-16
------------------
Expand All @@ -13,7 +20,7 @@ them in reverse chronological order.
remove unnecessary packaging stuff.


1.0.0 - 2021-01-05
1.0.0 - 2022-01-05
------------------

- :gh:`1` creates first release of a minimal cookiecutter template for a pytask project.
Expand Down
48 changes: 44 additions & 4 deletions docs/source/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@
documentation: https://www.sphinx-doc.org/en/master/usage/configuration.html

"""
from importlib.metadata import version


# -- Project information -----------------------------------------------------


Expand All @@ -12,24 +15,58 @@
copyright = f"2021, {author}" # noqa: A001

# The version, including alpha/beta/rc tags, but not commit hash and datestamps
release = "1.1.0"
release = version("cookiecutter-pytask-project")
# The short X.Y version.
version = "1.1"
version = ".".join(release.split(".")[:2])


# -- General configuration ---------------------------------------------------

# Add any Sphinx extension module names here, as strings. They can be extensions coming
# with Sphinx (named 'sphinx.ext.*') or your custom ones.
extensions = []
extensions = [
"IPython.sphinxext.ipython_console_highlighting",
"IPython.sphinxext.ipython_directive",
"sphinx.ext.autodoc",
"sphinx.ext.autosummary",
"sphinx.ext.extlinks",
"sphinx.ext.intersphinx",
"sphinx.ext.napoleon",
"sphinx.ext.viewcode",
"sphinx_copybutton",
"sphinx_panels",
"autoapi.extension",
]

# Add any paths that contain templates here, relative to this directory.
templates_path = ["_templates"]

# List of patterns, relative to source directory, that match files and directories to
# ignore when looking for source files. This pattern also affects html_static_path and
# html_extra_path.
exclude_patterns = []
exclude_patterns = ["build", "Thumbs.db", ".DS_Store", "**.ipynb_checkpoints"]

# Configuration for autoapi to generate and API page.
autoapi_type = "python"
autoapi_dirs = ["../../hooks"]
autoapi_keep_files = False
autoapi_add_toctree_entry = False

# Remove prefixed $ for bash, >>> for Python prompts, and In [1]: for IPython prompts.
copybutton_prompt_text = r"\$ |>>> |In \[\d\]: "
copybutton_prompt_is_regexp = True

# Use these roles to create links to github users and pull requests.
extlinks = {
"ghuser": ("https://github.com/%s", "@"),
"gh": ("https://github.com/pytask-dev/cookiecutter-pytask-project/pull/%s", "#"),
}

# Link objects to other documentations.
intersphinx_mapping = {
"python": ("https://docs.python.org/3.9", None),
"pytask": ("https://pytask-dev.readthedocs.io/en/stable/", None),
}


# -- Options for HTML output -------------------------------------------------
Expand All @@ -38,6 +75,9 @@
# builtin themes.
html_theme = "furo"

pygments_style = "sphinx"
pygments_dark_style = "monokai"

# Add any paths that contain custom static files (such as style sheets) here, relative
# to this directory. They are copied after the builtin static files, so a file named
# "default.css" will overwrite the builtin "default.css".
Expand Down
8 changes: 8 additions & 0 deletions docs/source/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,11 @@ Welcome to cookiecutter-pytask-project's documentation!
=======================================================

.. include:: ../../README.rst


.. toctree::
:caption: Contents:
:maxdepth: 1

changes
api
3 changes: 2 additions & 1 deletion environment.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ channels:

dependencies:
- python >=3.7
- pip
- pip >=21.1
- setuptools_scm
- toml

Expand All @@ -16,6 +16,7 @@ dependencies:

# Misc
- black
- ipython
- mypy
- pre-commit
- pytest
Expand Down
11 changes: 5 additions & 6 deletions hooks/post_gen_project.py
Original file line number Diff line number Diff line change
@@ -1,19 +1,21 @@
"""This module contains hooks which are executed after the template is rendered."""
from __future__ import annotations

import shutil
import subprocess
import warnings
from pathlib import Path


def remove_file(*filepath):
def remove_file(*filepath: str | Path) -> None:
"""Remove a file."""
try:
Path(*filepath).unlink()
except FileNotFoundError:
pass


def remove_directory(*filepath):
def remove_directory(*filepath: str | Path) -> None:
"""Remove a directory."""
try:
path = Path(*filepath)
Expand All @@ -22,13 +24,10 @@ def remove_directory(*filepath):
pass


def main():
def main() -> None:
"""Apply post generation hooks."""
project_path = Path.cwd()

if "{{ cookiecutter.create_changelog }}" == "no":
remove_file(project_path, "CHANGES.rst")

if "{{ cookiecutter.open_source_license }}" == "Not open source":
remove_file(project_path, "LICENSE")

Expand Down
19 changes: 14 additions & 5 deletions hooks/pre_gen_project.py
Original file line number Diff line number Diff line change
@@ -1,24 +1,31 @@
"""This module contains hooks which are executed before the template is rendered."""
import re

MODULE_REGEX = r"^[-_a-zA-Z0-9]*$"
MODULE_REGEX = r"^[_a-zA-Z][_a-zA-Z0-9]*$"
ENVIRON_REGEX = r"^[-_a-zA-Z0-9]*$"
PYTHONVERSION_REGEX = r"^(3\.(10|[7-9])(\.[0-9]{1,2})?)$"
PYTHONVERSION_MIN = "3.7"

EXCEPTION_MSG_MODULE_NAME = """
ERROR: The project slug ({module_name}) is not a valid Python module name.
Please do not use anything other than letters, numbers, underscores '_',
and minus signs '-'.

Please do not use anything other than letters, numbers, and underscores '_'.
The first character must not be a number.
"""

EXCEPTION_MSG_ENVIRON_NAME = """
ERROR: The project slug ({environment_name}) is not a valid conda environment name.

Please do not use anything other than letters, numbers, underscores '_',
and minus signs '-'.
"""

EXCEPTION_MSG_PYTHONVERSION = """
ERROR: The python version must be >= {PYTHONVERSION_MIN}, got {pythonversion}.
"""


def main():
def main() -> None:
"""Apply pre-generation hooks."""
module_name = "{{ cookiecutter.project_slug}}"

Expand All @@ -33,7 +40,9 @@ def main():
python_version = "{{ cookiecutter.python_version }}"

if not re.match(PYTHONVERSION_REGEX, python_version):
raise ValueError("ERROR: The python version must be >= 3.7") # noqa: TC003
raise ValueError(
EXCEPTION_MSG_PYTHONVERSION.format(PYTHONVERSION_MIN, python_version)
)


if __name__ == "__main__":
Expand Down
12 changes: 10 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,10 +1,18 @@
[build-system]
requires = ["setuptools>=45", "wheel", "setuptools_scm[toml]>=6.0"]


[tool.setuptools_scm]
write_to = "version.py"


[tool.tryceratops]
ignore = ["TC003"]


[tool.mypy]
files = ["{{cookiecutter.project_slug}}", "tests"]
exclude = "{{cookiecutter.project_slug}}/tests"
files = ["hooks", "tests"]
exclude = "{{cookiecutter.project_slug}}"
check_untyped_defs = true
disallow_any_generics = true
disallow_incomplete_defs = true
Expand Down
37 changes: 37 additions & 0 deletions setup.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
[metadata]
name = cookiecutter-pytask-project
description = A minimal cookiecutter template for a project with pytask.
long_description = file: README.rst
long_description_content_type = text/x-rst
url = https://cookiecutter-pytask-project.readthedocs.io/en/latest
author = Tobias Raabe
author_email = raabe@posteo.de
license = MIT
license_file = LICENSE
platforms = unix, linux, osx, cygwin, win32
classifiers =
Development Status :: 3 - Alpha
Environment :: Console
Intended Audience :: Science/Research
License :: OSI Approved :: MIT License
Operating System :: MacOS :: MacOS X
Operating System :: Microsoft :: Windows
Operating System :: POSIX
Programming Language :: Python :: 3
Programming Language :: Python :: 3 :: Only
Programming Language :: Python :: 3.7
Programming Language :: Python :: 3.8
Programming Language :: Python :: 3.9
Programming Language :: Python :: 3.10
Topic :: Scientific/Engineering
Topic :: Software Development :: Build Tools
project_urls =
Changelog = https://cookiecutter-pytask-project.readthedocs.io/en/latest/changes.html
Documentation = https://cookiecutter-pytask-project.readthedocs.io/en/latest
Github = https://github.com/pytask-dev/cookiecutter-pytask-project
Tracker = https://github.com/pytask-dev/cookiecutter-pytask-project/issues


[check-manifest]
ignore =
version.py
Loading