Skip to content

Commit 7d6371e

Browse files
author
Dominik Falkner
committed
Init basic cookiecutter template
0 parents  commit 7d6371e

18 files changed

Lines changed: 537 additions & 0 deletions

File tree

‎.gitignore‎

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
# Coverage.py
2+
htmlcov/
3+
reports/
4+
5+
# cruft
6+
*.rej
7+
8+
# Data
9+
*.csv*
10+
*.dat*
11+
*.pickle*
12+
*.xls*
13+
*.zip*
14+
*.parquet*
15+
data/
16+
17+
# direnv
18+
.envrc
19+
20+
# dotenv
21+
.env
22+
23+
# Hypothesis
24+
.hypothesis/
25+
26+
# Jupyter
27+
*.ipynb
28+
.ipynb_checkpoints/
29+
notebooks/
30+
31+
# macOS
32+
.DS_Store
33+
34+
# mypy
35+
.dmypy.json
36+
.mypy_cache/
37+
38+
# Node.js
39+
node_modules/
40+
41+
# Poetry
42+
.venv/
43+
dist/
44+
45+
# PyCharm
46+
.idea/
47+
48+
# pyenv
49+
.python-version
50+
51+
# pytest
52+
.pytest_cache/
53+
54+
# Python
55+
__pycache__/
56+
*.py[cdo]
57+
58+
# Ruff
59+
.ruff_cache/
60+
61+
# Terraform
62+
.terraform/
63+
64+
# VS Code
65+
.vscode/

‎LICENSE‎

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
The MIT License (MIT)
2+
3+
Copyright © 2023
4+
5+
6+
Permission is hereby granted, free of charge, to any person obtaining a copy
7+
of this software and associated documentation files (the “Software”), to deal
8+
in the Software without restriction, including without limitation the rights
9+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10+
copies of the Software, and to permit persons to whom the Software is
11+
furnished to do so, subject to the following conditions:
12+
13+
The above copyright notice and this permission notice shall be included in
14+
all copies or substantial portions of the Software.
15+
16+
THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22+
THE SOFTWARE.

‎README.md‎

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
# Poetry Cookiecutter
2+
3+
A simple [Cookiecutter](https://github.com/cookiecutter/cookiecutter) template for scaffolding Python packages and apps. The goal is to provide sane defaults for any application.
4+
5+
## Batteries Included
6+
7+
- **Packaging and dependency management** with [Poetry](https://github.com/python-poetry/poetry)
8+
- **Task running** with [Poe the Poet](https://github.com/nat-n/poethepoet)
9+
- **Pre defined** tasks
10+
- **Code formatting** with [Black](https://github.com/psf/black), [isort](https://github.com/PyCQA/isort)
11+
- **Code linting** with [Ruff](https://github.com/charliermarsh/ruff)
12+
- **Tests and test coverage** with [Pytest](https://github.com/pytest-dev/pytest/)
13+
- **Scaffolding** updates with [Cookiecutter](https://github.com/cookiecutter/cookiecutter) and [Cruft](https://github.com/cruft/cruft)
14+
- **Documentation generation** with [Mkdocs](https://github.com/mkdocs/mkdocs) and `mkdocstrings`
15+
- Installing from and publishing to **RISCs private** [PyPI](https://pypi.org/)
16+
- Simple **Gitignore** for working with Python / PyCharm / VSCode / ...
17+
- Default **EditorConfig** for Python and miscellaneous files
18+
- Uses [Google-style docstrings](https://google.github.io/styleguide/pyguide.html#38-comments-and-docstrings) or [NumPy-style](https://numpydoc.readthedocs.io/en/latest/format.html)
19+
- Ready to use **Docker images** as a base CI/CD
20+
- Cross-platform support for Linux, macOS (Apple silicon and Intel), and Windows
21+
22+
### Extras
23+
- Optionally follows the [Conventional Commits](https://www.conventionalcommits.org/) standard to automate [Semantic Versioning](https://semver.org/) and [Keep A Changelog](https://keepachangelog.com/) with [Commitizen](https://github.com/commitizen-tools/commitizen)
24+
25+
### Planned
26+
- [ ] **Automatic dependency** updates with [RenovateBot]()
27+
28+
## Usage
29+
30+
### Creating a new Python project
31+
32+
1. Install [Cruft](https://github.com/cruft/cruft) and [Cookiecutter](https://github.com/cookiecutter/cookiecutter)
33+
2. Create a new repository locally
34+
3. In the directory that contains the cloned repository, run:
35+
```sh
36+
cruft create -f https://gitdma.risc-software.at/common/python-package-template
37+
```
38+
4. Install the environment with `poetry install` and create a container using `docker build -f Dockerfile-test .`
39+
5. [Optional] Update your project template by running `cruft update`
40+
41+
## Parameters
42+
43+
| Parameter | Description |
44+
| ----------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
45+
| `package_name` <br> "My Awesome Proect" | The name of the package. Will be slugified to `snake_case` for importing and `kebab-case` for installing. |
46+
| `package_description` <br> "A single sentence description" | A single-line description of the package. |
47+
| `package_url` <br> "https://gitdma.risc-software.at/<ID>/<package_name>" | The URL to the package's repository. |
48+
| `author_name` <br> "Sonja Sunshine" | The full name of the primary author of the package. |
49+
| `author_email` <br> "sonja.sunshine@risc-software.at" | The email address of the primary author of the package. |
50+
| `python_version` <br> "3.11" | The minimum Python version that the package requires. |
51+
| `docstring_style` <br> ["Google", "Numpy"] | Whether to use and validate [NumPy-style](https://numpydoc.readthedocs.io/en/latest/format.html) or [Google-style docstrings](https://google.github.io/styleguide/pyguide.html#38-comments-and-docstrings). |
52+
| `use_conventional_commits` <br> [true, false] | If true, [Commitizen](https://github.com/commitizen-tools/commitizen) will verify that your commits follow the [Conventional Commits](https://www.conventionalcommits.org/) standard. Then, `cz bump` may be used to automate [Semantic Versioning](https://semver.org/) and [Keep A Changelog](https://keepachangelog.com/). |
53+
54+
## Supported Poe Tasks
55+
56+
- **precommit** Runs formatting, linting, and import sorting
57+
- **check** Checks if formatting, linting and import sorting are corrcet
58+
- **test** Runs all unit tests and doctests
59+
- **docs** Serves documentation in the `docs` folder, also generates API docs from docstrings

‎cookiecutter.json‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
{
2+
"package_name": "My Package",
3+
"package_description": "One or Two sentence description of the package...",
4+
"package_url": "https://github.com/user/my-package",
5+
"author_name": "Sonja Sunshine",
6+
"author_email": "sonja.sunshine@risc-software.com",
7+
"python_version": "3.11",
8+
"docstring_style": ["Google", "Numpy"],
9+
"use_conventional_commits": true,
10+
"__package_name_kebab_case": "{{ cookiecutter.package_name|slugify }}",
11+
"__package_name_snake_case": "{{ cookiecutter.package_name|slugify(separator='_') }}"
12+
}

‎hooks/.gitkeep‎

Whitespace-only changes.
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# EditorConfig is awesome: https://EditorConfig.org
2+
3+
# top-most EditorConfig file
4+
root = true
5+
6+
# Unix-style newlines with a newline ending every file
7+
[*]
8+
charset = utf-8
9+
end_of_line = lf
10+
insert_final_newline = true
11+
trim_trailing_whitespace = true
12+
13+
# Python
14+
[*.py]
15+
indent_style = space
16+
indent_size = 4
17+
18+
# Matches the exact files either package.json or .travis.yml
19+
[{pyproject.toml,.gitlab-ci.yml}]
20+
indent_style = space
21+
indent_size = 2
Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
# Compiled
2+
*.so
3+
4+
# Coverage.py
5+
htmlcov/
6+
reports/
7+
8+
# cruft
9+
*.rej
10+
11+
# Data
12+
*.csv*
13+
*.dat*
14+
*.pickle*
15+
*.xls*
16+
*.zip*
17+
data/
18+
output/
19+
20+
# direnv
21+
.envrc
22+
23+
# dotenv
24+
.env
25+
26+
# Hypothesis
27+
.hypothesis/
28+
29+
# Jupyter
30+
*.ipynb
31+
.ipynb_checkpoints/
32+
notebooks/
33+
34+
# IPython
35+
profile_default/
36+
ipython_config.py
37+
38+
# mkdocs documentation
39+
/site
40+
41+
# macOS
42+
.DS_Store
43+
44+
# mypy
45+
.dmypy.json
46+
.mypy_cache/
47+
48+
# Node.js
49+
node_modules/
50+
51+
# Poetry
52+
.venv/
53+
dist/
54+
55+
# PyCharm
56+
.idea/
57+
58+
# pyenv
59+
.python-version
60+
61+
# pytest
62+
.pytest_cache/
63+
64+
# Python
65+
__pycache__/
66+
*.py[cdo]
67+
*$py.class
68+
69+
# Ruff
70+
.ruff_cache/
71+
72+
# Terraform
73+
.terraform/
74+
75+
# VS Code
76+
.vscode/
77+
78+
# Unit test / coverage reports
79+
htmlcov/
80+
.tox/
81+
.nox/
82+
.coverage
83+
.coverage.*
84+
.cache
85+
coverage.xml
86+
*.cover
87+
*.py,cover
88+
.hypothesis/
89+
.pytest_cache/
90+
cover/
91+
*-junit.xml
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
# This dockerfile serves as a base for all testing images.
2+
# It contains the minimal dependencies and is therefore smaller.
3+
from debian:stable-slim
4+
ARG PYTHON_VERSION={{cookiecutter.python_version}}
5+
ARG POETRY_VERSION=1.5.1
6+
7+
ENV DEBIAN_FRONTEND noninteractive
8+
LABEL maintainer="{{cookiecutter.author_name}} <{{cookiecutter.author_email}}>"
9+
10+
RUN apt-get update && apt-get install -yq \
11+
build-essential \
12+
libssl-dev \
13+
zlib1g-dev \
14+
libbz2-dev \
15+
libreadline-dev \
16+
libsqlite3-dev \
17+
curl \
18+
libncursesw5-dev \
19+
xz-utils \
20+
tk-dev \
21+
libxml2-dev \
22+
libxmlsec1-dev \
23+
libffi-dev \
24+
liblzma-dev \
25+
git \
26+
python3-distutils \
27+
&& rm -rf /var/lib/apt/lists/*
28+
29+
ENV PYENV_ROOT $HOME/.pyenv
30+
ENV PATH $PYENV_ROOT/shims:$PYENV_ROOT/bin:$PATH
31+
32+
# Install pyenv
33+
RUN set -ex \
34+
&& curl https://pyenv.run | bash \
35+
&& pyenv update \
36+
&& eval "$(pyenv init -)" && pyenv --versio
37+
38+
# Install python and set interpreter
39+
RUN pyenv install -s ${PYTHON_VERSION} && pyenv global ${PYTHON_VERSION}
40+
41+
# Install and configure Poetry
42+
ENV POETRY_VERSION=${POETRY_VERSION} \
43+
POETRY_HOME=/opt/poetry \
44+
POETRY_VIRTUALENVS_CREATE=false
45+
RUN curl -sSL https://install.python-poetry.org | python -
46+
ENV PATH="${PATH}:${POETRY_HOME}/bin"
47+
48+
# Setup directory structure
49+
RUN mkdir /repo
50+
WORKDIR /repo
51+
52+
# Install dependencies (package itself is not installed)
53+
COPY pyproject.toml poetry.lock .
54+
RUN poetry install --without dev --all-extras --no-root
55+
56+
# Copy the rest of the repository
57+
ADD . .
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
# This dockerfile serves as a base for all testing images.
2+
# It contains the minimal dependencies and is therefore smaller.
3+
from debian:stable-slim
4+
ARG PYTHON_VERSION={{cookiecutter.python_version}}
5+
ARG POETRY_VERSION=1.5.1
6+
7+
ENV DEBIAN_FRONTEND noninteractive
8+
LABEL maintainer="{{cookiecutter.author_name}} <{{cookiecutter.author_email}}>"
9+
10+
RUN apt-get update && apt-get install -yq \
11+
build-essential \
12+
libssl-dev \
13+
zlib1g-dev \
14+
libbz2-dev \
15+
libreadline-dev \
16+
libsqlite3-dev \
17+
curl \
18+
libncursesw5-dev \
19+
xz-utils \
20+
tk-dev \
21+
libxml2-dev \
22+
libxmlsec1-dev \
23+
libffi-dev \
24+
liblzma-dev \
25+
git \
26+
python3-distutils \
27+
&& rm -rf /var/lib/apt/lists/*
28+
29+
ENV PYENV_ROOT $HOME/.pyenv
30+
ENV PATH $PYENV_ROOT/shims:$PYENV_ROOT/bin:$PATH
31+
32+
# Install pyenv
33+
RUN set -ex \
34+
&& curl https://pyenv.run | bash \
35+
&& pyenv update \
36+
&& eval "$(pyenv init -)" && pyenv --versio
37+
38+
# Install python and set interpreter
39+
RUN pyenv install -s ${PYTHON_VERSION} && pyenv global ${PYTHON_VERSION}
40+
41+
# Install and configure Poetry
42+
ENV POETRY_VERSION=${POETRY_VERSION} \
43+
POETRY_HOME=/opt/poetry \
44+
POETRY_VIRTUALENVS_CREATE=false
45+
RUN curl -sSL https://install.python-poetry.org | python -
46+
ENV PATH="${PATH}:${POETRY_HOME}/bin"
47+
48+
# Setup directory structure
49+
RUN mkdir /repo
50+
WORKDIR /repo
51+
52+
# Install dependencies (package itself is not installed)
53+
COPY pyproject.toml poetry.lock .
54+
RUN poetry install --all-extras --no-root
55+
56+
# Copy the rest of the repository
57+
ADD . .

0 commit comments

Comments
 (0)