Skip to content

Commit 5c0cd86

Browse files
hf-kkleinhf-krechanhf-aschloegl
authored
🎉An initial Draft (#1)
Co-authored-by: hf-krechan <[email protected]> Co-authored-by: hf-aschloegl <[email protected]>
1 parent a72cddd commit 5c0cd86

13 files changed

+391
-2
lines changed

.github/workflows/black.yml

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
name: "Black"
2+
3+
on: [push]
4+
jobs:
5+
black:
6+
runs-on: ${{ matrix.os }}
7+
strategy:
8+
matrix:
9+
python-version: [3.9]
10+
os: [ubuntu-latest]
11+
steps:
12+
- uses: actions/checkout@v2
13+
- name: Black Code Formatter
14+
uses: lgeiger/[email protected]
15+
with:
16+
args: ". --check"

.github/workflows/coverage.yml

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
name: "Coverage"
2+
3+
on: [push]
4+
jobs:
5+
coverage:
6+
runs-on: ${{ matrix.os }}
7+
strategy:
8+
matrix:
9+
python-version: [3.9]
10+
os: [ubuntu-latest]
11+
steps:
12+
- uses: actions/checkout@v2
13+
- name: Set up Python ${{ matrix.python-version }}
14+
uses: actions/setup-python@v2
15+
with:
16+
python-version: ${{ matrix.python-version }}
17+
- name: Install dependencies
18+
run: |
19+
python -m pip install --upgrade pip
20+
pip install tox
21+
- name: Run Tests and Record Coverage
22+
run: |
23+
tox -e coverage

.github/workflows/pythonlint.yml

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
name: "Linting"
2+
3+
on: [push]
4+
jobs:
5+
pylint:
6+
name: Python Code Quality and Lint
7+
runs-on: ${{ matrix.os }}
8+
strategy:
9+
matrix:
10+
python-version: [3.9]
11+
os: [ubuntu-latest]
12+
steps:
13+
- uses: actions/checkout@v2
14+
- name: Set up Python ${{ matrix.python-version }}
15+
uses: actions/setup-python@v2
16+
with:
17+
python-version: ${{ matrix.python-version }}
18+
- name: Install Dependencies
19+
run: |
20+
python -m pip install --upgrade pip
21+
pip install tox
22+
- name: Run Pylint via Tox
23+
run: |
24+
tox -e linting

.github/workflows/unittests.yml

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
name: "Unittests"
2+
3+
on: [push]
4+
jobs:
5+
pytest:
6+
runs-on: ${{ matrix.os }}
7+
strategy:
8+
matrix:
9+
python-version: [3.9]
10+
os: [ubuntu-latest]
11+
steps:
12+
- uses: actions/checkout@v2
13+
- name: Set up Python ${{ matrix.python-version }}
14+
uses: actions/setup-python@v2
15+
with:
16+
python-version: ${{ matrix.python-version }}
17+
- name: Install Dependencies
18+
run: |
19+
python -m pip install --upgrade pip
20+
pip install tox
21+
- name: Run the Unit Tests via Tox
22+
run: |
23+
tox -e tests

.gitignore

Lines changed: 134 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,134 @@
1+
# Byte-compiled / optimized / DLL files
2+
__pycache__/
3+
*.py[cod]
4+
*$py.class
5+
6+
# C extensions
7+
*.so
8+
9+
# Distribution / packaging
10+
.Python
11+
build/
12+
develop-eggs/
13+
dist/
14+
downloads/
15+
eggs/
16+
.eggs/
17+
lib/
18+
lib64/
19+
parts/
20+
sdist/
21+
var/
22+
wheels/
23+
pip-wheel-metadata/
24+
share/python-wheels/
25+
*.egg-info/
26+
.installed.cfg
27+
*.egg
28+
MANIFEST
29+
30+
# PyInstaller
31+
# Usually these files are written by a python script from a template
32+
# before PyInstaller builds the exe, so as to inject date/other infos into it.
33+
*.manifest
34+
*.spec
35+
36+
# Installer logs
37+
pip-log.txt
38+
pip-delete-this-directory.txt
39+
40+
# Unit test / coverage reports
41+
htmlcov/
42+
.tox/
43+
.nox/
44+
.coverage
45+
.coverage.*
46+
.cache
47+
nosetests.xml
48+
coverage.xml
49+
*.cover
50+
*.py,cover
51+
.hypothesis/
52+
.pytest_cache/
53+
54+
# Translations
55+
*.mo
56+
*.pot
57+
58+
# Django stuff:
59+
*.log
60+
local_settings.py
61+
db.sqlite3
62+
db.sqlite3-journal
63+
64+
# Flask stuff:
65+
instance/
66+
.webassets-cache
67+
68+
# Scrapy stuff:
69+
.scrapy
70+
71+
# Sphinx documentation
72+
docs/_build/
73+
74+
# PyBuilder
75+
target/
76+
77+
# Jupyter Notebook
78+
.ipynb_checkpoints
79+
80+
# IPython
81+
profile_default/
82+
ipython_config.py
83+
84+
# pyenv
85+
.python-version
86+
87+
# pipenv
88+
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
89+
# However, in case of collaboration, if having platform-specific dependencies or dependencies
90+
# having no cross-platform support, pipenv may install dependencies that don't work, or not
91+
# install all needed dependencies.
92+
#Pipfile.lock
93+
94+
# PEP 582; used by e.g. github.com/David-OConnor/pyflow
95+
__pypackages__/
96+
97+
# Celery stuff
98+
celerybeat-schedule
99+
celerybeat.pid
100+
101+
# SageMath parsed files
102+
*.sage.py
103+
104+
# Environments
105+
.env
106+
.venv
107+
env/
108+
venv/
109+
ENV/
110+
env.bak/
111+
venv.bak/
112+
113+
# Spyder project settings
114+
.spyderproject
115+
.spyproject
116+
117+
# Rope project settings
118+
.ropeproject
119+
120+
# mkdocs documentation
121+
/site
122+
123+
# mypy
124+
.mypy_cache/
125+
.dmypy.json
126+
dmypy.json
127+
128+
# Pyre type checker
129+
.pyre/
130+
131+
.idea/
132+
133+
# vscode settings
134+
.vscode/

.pre-commit-config.yaml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
repos:
2+
- repo: https://github.com/pre-commit/pre-commit-hooks
3+
rev: v2.3.0
4+
hooks:
5+
- id: check-yaml
6+
- id: end-of-file-fixer
7+
- id: trailing-whitespace
8+
- repo: https://github.com/psf/black
9+
rev: 20.8b1 # Replace by any tag/version: https://github.com/psf/black/tags
10+
hooks:
11+
- id: black
12+
language_version: python3

README.md

Lines changed: 66 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,66 @@
1-
# python_template_repository
2-
A template repository that comes up with a pre-defined tox setup and CI actions.
1+
# Python Template Repository including Unittests, Linting Actions and Coverage measurements
2+
<!--- you need to replace the `organization/repo_name` in the status badge URLs --->
3+
![Unittests status badge](https://github.com/Hochfrequenz/python_template_repository/workflows/Unittests/badge.svg)
4+
![Coverage status badge](https://github.com/Hochfrequenz/python_template_repository/workflows/Coverage/badge.svg)
5+
![Linting status badge](https://github.com/Hochfrequenz/python_template_repository/workflows/Linting/badge.svg)
6+
![Black status badge](https://github.com/Hochfrequenz/python_template_repository/workflows/Black/badge.svg)
7+
8+
This is a template repository. It doesn't contain any useful code but only a minimal working setup for a Python project including:
9+
10+
+ a basic **project structure** with
11+
+ tox.ini
12+
+ requirements.in
13+
+ and a requirements.txt derived from it
14+
+ an example class
15+
+ an example unit test (using pytest)
16+
+ ready to use **Github Actions** for
17+
+ [pytest](https://pytest.org)
18+
+ [code coverage measurement](https://coverage.readthedocs.io) (fails below 80% by default)
19+
+ [pylint](https://pylint.org/) (only accepts 10/10 code rating by default)
20+
+ [black](https://github.com/psf/black) code formatter check
21+
using [lgeiger/black-action](https://github.com/lgeiger/black-action)
22+
23+
By default it uses Python version 3.9.
24+
25+
## How to use this Repository on Your Machine
26+
27+
This introduction assumes that you have tox installed already (
28+
see [installation instructions](https://tox.readthedocs.io/en/latest/install.html)) and that a `.toxbase` environment
29+
has been created.
30+
31+
If this is the case, clone this repository and create the `dev` environment on your machine.
32+
33+
```bash
34+
tox -e dev
35+
```
36+
37+
### How to use with PyCharm
38+
39+
1. Create a new project using existing sources with your local working copy of this repository as root directory. Choose
40+
the path `your_repo/.tox/dev/` as path of the "previously configured interpreter".
41+
2. Set the
42+
default [test runner of your project](https://www.jetbrains.com/help/pycharm/choosing-your-testing-framework.html) to
43+
pytest.
44+
3. Set
45+
the [working directory of the unit tests](https://www.jetbrains.com/help/pycharm/creating-run-debug-configuration-for-tests.html)
46+
to the project root (instead of the unittest directory)
47+
48+
### How to use with VS Code
49+
50+
1. Open the folder with VS Code.
51+
2. **Select the python interpreter** which is created by tox. Open the command pallett with `CTRL + P` and type `Python: Select Interpreter`. Select the interpreter which is placed in `.tox/dev/Scripts/python.exe` under Windows or `.tox/dev/bin/python` under Linux and macOS.
52+
3. **Setup pytest and pylint**. Therefore we open the file `.vscode/settings.json` which should be automatically generated during the interpreter setup. Insert the following lines into the settings:
53+
```json
54+
"python.testing.unittestEnabled": false,
55+
"python.testing.nosetestsEnabled": false,
56+
"python.testing.pytestEnabled": true,
57+
"pythonTestExplorer.testFramework": "pytest",
58+
"python.testing.pytestArgs": [
59+
"unittests"
60+
],
61+
"python.linting.pylintEnabled": true
62+
```
63+
4. Enjoy 🤗
64+
65+
## Contribute
66+
You are very welcome to contribute to this template repository by opening a pull request against the main branch.

mymodule.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
"""
2+
This a docstring for the module.
3+
"""
4+
5+
6+
class MyClass: # pylint: disable=too-few-public-methods
7+
"""
8+
This is a docstring for the class.
9+
"""
10+
11+
def __init__(self):
12+
"""
13+
Initialize for the sake of initializing
14+
"""
15+
self.my_instance_var = "abc"
16+
17+
def do_something(self) -> str:
18+
"""
19+
Actually does nothing.
20+
:return: the value of an instance variable
21+
"""
22+
return self.my_instance_var

pyproject.toml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
[tool.black]
2+
line-length = 120
3+
4+
[tool.isort]
5+
line_length = 120

requirements.in

Whitespace-only changes.

requirements.txt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#
2+
# This file is autogenerated by pip-compile
3+
# To update, run:
4+
#
5+
# pip-compile requirements.in
6+
#

tox.ini

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
[tox]
2+
envlist =
3+
tests
4+
linting
5+
coverage
6+
skip_missing_interpreters = True
7+
skipsdist = True
8+
9+
[testenv]
10+
commands = python -m pip install --upgrade pip
11+
12+
[testenv:dev]
13+
# the dev environment contains everything you need to start developing on your local machine.
14+
deps =
15+
black
16+
pip-tools
17+
pylint
18+
pytest
19+
pre-commit
20+
commands =
21+
python -m pip install --upgrade pip
22+
pip-compile requirements.in
23+
pip install -r requirements.txt
24+
25+
[testenv:tests]
26+
# the tests environment is called by the Github action that runs the unit tests
27+
deps =
28+
-rrequirements.txt
29+
pytest
30+
commands = python -m pytest --basetemp={envtmpdir} {posargs}
31+
32+
[testenv:linting]
33+
# the linting environment is called by the Github Action that runs the linter
34+
deps =
35+
-rrequirements.txt
36+
pylint
37+
# add your fixtures like e.g. pytest_datafiles here
38+
commands =
39+
pylint mymodule.py
40+
# add single files (ending with .py) or packages here
41+
42+
[testenv:coverage]
43+
# the coverage environment is called by the Github Action that runs the coverage measurement
44+
deps =
45+
{[testenv:tests]deps}
46+
coverage
47+
commands =
48+
coverage run -m pytest --basetemp={envtmpdir} {posargs}
49+
coverage report --fail-under 80 --omit .tox/*,unittests/*

0 commit comments

Comments
 (0)