Skip to content

🎉An initial Draft #1

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

Merged
merged 33 commits into from
Mar 26, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
2367f1e
add initial draft
hf-kklein Mar 8, 2021
5e9ec0e
tox -e instead of tox -r on initial setup
hf-kklein Mar 10, 2021
4e07db6
add a distinction between class and module
hf-kklein Mar 10, 2021
2e51298
make tests a bit more "interesting" and thus avoid pylint-warnings ;)
hf-kklein Mar 10, 2021
0f27cb0
foo is blacklisted by pylint
hf-kklein Mar 10, 2021
b1edfa8
q: how hard could it be to write a working example test? a: yes.
hf-kklein Mar 10, 2021
fd824a6
highlight the highlights
hf-kklein Mar 10, 2021
ffbf77a
Update README.md
hf-kklein Mar 10, 2021
07672f4
Update README.md
hf-kklein Mar 10, 2021
3e89c4e
add status badges
hf-kklein Mar 10, 2021
a4c942b
🙈 Ignore VS Code settings
hf-krechan Mar 10, 2021
e866670
📝 Add manual for VS Code
hf-krechan Mar 10, 2021
b6230e5
Merge remote-tracking branch 'origin/initial_draft' into initial_draft
hf-krechan Mar 10, 2021
3e63e31
➕ Add pre-commit to template
hf-krechan Mar 10, 2021
bfbba7f
Update tox.ini
hf-kklein Mar 10, 2021
5050d7e
Update tox.ini
hf-kklein Mar 10, 2021
aa0da03
Update tox.ini
hf-kklein Mar 10, 2021
2ad80b1
Update README.md
hf-kklein Mar 10, 2021
990019a
Update README.md
hf-kklein Mar 10, 2021
ca755e5
Update README.md
hf-kklein Mar 10, 2021
7caad6f
rename to "Linting"
hf-kklein Mar 10, 2021
b2b6f53
rename to "Unittests"
hf-kklein Mar 10, 2021
3fced65
reference the correct/renamed badge in readme
hf-kklein Mar 10, 2021
f94a6f5
Update .github/workflows/coverage.yml
hf-kklein Mar 10, 2021
b0c451e
Update .github/workflows/pythonlint.yml
hf-kklein Mar 10, 2021
f49f868
Update .github/workflows/pythonlint.yml
hf-kklein Mar 10, 2021
6e78bc6
Update .github/workflows/unittests.yml
hf-kklein Mar 10, 2021
a276301
Update .github/workflows/unittests.yml
hf-kklein Mar 10, 2021
752f5ef
Update .gitignore
hf-kklein Mar 10, 2021
841687c
introduce a pyproject.toml
hf-kklein Mar 25, 2021
9c2f455
remove CLI argument of black action
hf-kklein Mar 25, 2021
675dd3a
Update tox.ini
hf-kklein Mar 26, 2021
c309d74
fix broken tox file
hf-kklein Mar 26, 2021
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
16 changes: 16 additions & 0 deletions .github/workflows/black.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
name: "Black"

on: [push]
jobs:
black:
runs-on: ${{ matrix.os }}
strategy:
matrix:
python-version: [3.9]
os: [ubuntu-latest]
steps:
- uses: actions/checkout@v2
- name: Black Code Formatter
uses: lgeiger/[email protected]
with:
args: ". --check"
23 changes: 23 additions & 0 deletions .github/workflows/coverage.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
name: "Coverage"

on: [push]
jobs:
coverage:
runs-on: ${{ matrix.os }}
strategy:
matrix:
python-version: [3.9]
os: [ubuntu-latest]
steps:
- uses: actions/checkout@v2
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v2
with:
python-version: ${{ matrix.python-version }}
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install tox
- name: Run Tests and Record Coverage
run: |
tox -e coverage
24 changes: 24 additions & 0 deletions .github/workflows/pythonlint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
name: "Linting"

on: [push]
jobs:
pylint:
name: Python Code Quality and Lint
runs-on: ${{ matrix.os }}
strategy:
matrix:
python-version: [3.9]
os: [ubuntu-latest]
steps:
- uses: actions/checkout@v2
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v2
with:
python-version: ${{ matrix.python-version }}
- name: Install Dependencies
run: |
python -m pip install --upgrade pip
pip install tox
- name: Run Pylint via Tox
run: |
tox -e linting
23 changes: 23 additions & 0 deletions .github/workflows/unittests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
name: "Unittests"

on: [push]
jobs:
pytest:
runs-on: ${{ matrix.os }}
strategy:
matrix:
python-version: [3.9]
os: [ubuntu-latest]
steps:
- uses: actions/checkout@v2
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v2
with:
python-version: ${{ matrix.python-version }}
- name: Install Dependencies
run: |
python -m pip install --upgrade pip
pip install tox
- name: Run the Unit Tests via Tox
run: |
tox -e tests
134 changes: 134 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,134 @@
# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
*$py.class

# C extensions
*.so

# Distribution / packaging
.Python
build/
develop-eggs/
dist/
downloads/
eggs/
.eggs/
lib/
lib64/
parts/
sdist/
var/
wheels/
pip-wheel-metadata/
share/python-wheels/
*.egg-info/
.installed.cfg
*.egg
MANIFEST

# PyInstaller
# Usually these files are written by a python script from a template
# before PyInstaller builds the exe, so as to inject date/other infos into it.
*.manifest
*.spec

# Installer logs
pip-log.txt
pip-delete-this-directory.txt

# Unit test / coverage reports
htmlcov/
.tox/
.nox/
.coverage
.coverage.*
.cache
nosetests.xml
coverage.xml
*.cover
*.py,cover
.hypothesis/
.pytest_cache/

# Translations
*.mo
*.pot

# Django stuff:
*.log
local_settings.py
db.sqlite3
db.sqlite3-journal

# Flask stuff:
instance/
.webassets-cache

# Scrapy stuff:
.scrapy

# Sphinx documentation
docs/_build/

# PyBuilder
target/

# Jupyter Notebook
.ipynb_checkpoints

# IPython
profile_default/
ipython_config.py

# pyenv
.python-version

# pipenv
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
# However, in case of collaboration, if having platform-specific dependencies or dependencies
# having no cross-platform support, pipenv may install dependencies that don't work, or not
# install all needed dependencies.
#Pipfile.lock

# PEP 582; used by e.g. github.com/David-OConnor/pyflow
__pypackages__/

# Celery stuff
celerybeat-schedule
celerybeat.pid

# SageMath parsed files
*.sage.py

# Environments
.env
.venv
env/
venv/
ENV/
env.bak/
venv.bak/

# Spyder project settings
.spyderproject
.spyproject

# Rope project settings
.ropeproject

# mkdocs documentation
/site

# mypy
.mypy_cache/
.dmypy.json
dmypy.json

# Pyre type checker
.pyre/

.idea/

# vscode settings
.vscode/
12 changes: 12 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v2.3.0
hooks:
- id: check-yaml
- id: end-of-file-fixer
- id: trailing-whitespace
- repo: https://github.com/psf/black
rev: 20.8b1 # Replace by any tag/version: https://github.com/psf/black/tags
hooks:
- id: black
language_version: python3
68 changes: 66 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,66 @@
# python_template_repository
A template repository that comes up with a pre-defined tox setup and CI actions.
# Python Template Repository including Unittests, Linting Actions and Coverage measurements
<!--- you need to replace the `organization/repo_name` in the status badge URLs --->
![Unittests status badge](https://github.com/Hochfrequenz/python_template_repository/workflows/Unittests/badge.svg)
![Coverage status badge](https://github.com/Hochfrequenz/python_template_repository/workflows/Coverage/badge.svg)
![Linting status badge](https://github.com/Hochfrequenz/python_template_repository/workflows/Linting/badge.svg)
![Black status badge](https://github.com/Hochfrequenz/python_template_repository/workflows/Black/badge.svg)

This is a template repository. It doesn't contain any useful code but only a minimal working setup for a Python project including:

+ a basic **project structure** with
+ tox.ini
+ requirements.in
+ and a requirements.txt derived from it
+ an example class
+ an example unit test (using pytest)
+ ready to use **Github Actions** for
+ [pytest](https://pytest.org)
+ [code coverage measurement](https://coverage.readthedocs.io) (fails below 80% by default)
+ [pylint](https://pylint.org/) (only accepts 10/10 code rating by default)
+ [black](https://github.com/psf/black) code formatter check
using [lgeiger/black-action](https://github.com/lgeiger/black-action)

By default it uses Python version 3.9.

## How to use this Repository on Your Machine

This introduction assumes that you have tox installed already (
see [installation instructions](https://tox.readthedocs.io/en/latest/install.html)) and that a `.toxbase` environment
has been created.

If this is the case, clone this repository and create the `dev` environment on your machine.

```bash
tox -e dev
```

### How to use with PyCharm

1. Create a new project using existing sources with your local working copy of this repository as root directory. Choose
the path `your_repo/.tox/dev/` as path of the "previously configured interpreter".
2. Set the
default [test runner of your project](https://www.jetbrains.com/help/pycharm/choosing-your-testing-framework.html) to
pytest.
3. Set
the [working directory of the unit tests](https://www.jetbrains.com/help/pycharm/creating-run-debug-configuration-for-tests.html)
to the project root (instead of the unittest directory)

### How to use with VS Code

1. Open the folder with VS Code.
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.
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:
```json
"python.testing.unittestEnabled": false,
"python.testing.nosetestsEnabled": false,
"python.testing.pytestEnabled": true,
"pythonTestExplorer.testFramework": "pytest",
"python.testing.pytestArgs": [
"unittests"
],
"python.linting.pylintEnabled": true
```
4. Enjoy 🤗

## Contribute
You are very welcome to contribute to this template repository by opening a pull request against the main branch.
22 changes: 22 additions & 0 deletions mymodule.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
"""
This a docstring for the module.
"""


class MyClass: # pylint: disable=too-few-public-methods
"""
This is a docstring for the class.
"""

def __init__(self):
"""
Initialize for the sake of initializing
"""
self.my_instance_var = "abc"

def do_something(self) -> str:
"""
Actually does nothing.
:return: the value of an instance variable
"""
return self.my_instance_var
5 changes: 5 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
[tool.black]
line-length = 120

[tool.isort]
line_length = 120
Empty file added requirements.in
Empty file.
6 changes: 6 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#
# This file is autogenerated by pip-compile
# To update, run:
#
# pip-compile requirements.in
#
49 changes: 49 additions & 0 deletions tox.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
[tox]
envlist =
tests
linting
coverage
skip_missing_interpreters = True
skipsdist = True

[testenv]
commands = python -m pip install --upgrade pip

[testenv:dev]
# the dev environment contains everything you need to start developing on your local machine.
deps =
black
pip-tools
pylint
pytest
pre-commit
commands =
python -m pip install --upgrade pip
pip-compile requirements.in
pip install -r requirements.txt

[testenv:tests]
# the tests environment is called by the Github action that runs the unit tests
deps =
-rrequirements.txt
pytest
commands = python -m pytest --basetemp={envtmpdir} {posargs}

[testenv:linting]
# the linting environment is called by the Github Action that runs the linter
deps =
-rrequirements.txt
pylint
# add your fixtures like e.g. pytest_datafiles here
commands =
pylint mymodule.py
# add single files (ending with .py) or packages here

[testenv:coverage]
# the coverage environment is called by the Github Action that runs the coverage measurement
deps =
{[testenv:tests]deps}
coverage
commands =
coverage run -m pytest --basetemp={envtmpdir} {posargs}
coverage report --fail-under 80 --omit .tox/*,unittests/*
Loading