Skip to content

Commit

Permalink
Add demo code
Browse files Browse the repository at this point in the history
  • Loading branch information
avnes committed Jun 9, 2021
1 parent b88a340 commit e78fdc7
Show file tree
Hide file tree
Showing 8 changed files with 170 additions and 14 deletions.
33 changes: 22 additions & 11 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,14 +1,25 @@
# See https://pre-commit.com for more information
# See https://pre-commit.com/hooks.html for more hooks
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v3.2.0
files: '*.py'
hooks:
- id: trailing-whitespace
- id: end-of-file-fixer
- id: check-added-large-files
- repo: https://github.com/psf/black
rev: 19.3b0
hooks:
- id: black
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.0.1
hooks:
- id: check-added-large-files
- id: check-ast
- id: check-case-conflict
- id: check-docstring-first
- id: check-merge-conflict
- id: check-added-large-files
- id: debug-statements
- id: detect-aws-credentials
- id: detect-private-key
- id: end-of-file-fixer
- id: trailing-whitespace
- repo: https://github.com/psf/black
rev: 21.5b2
hooks:
- id: black
- repo: https://github.com/pycqa/flake8
rev: 3.9.2
hooks:
- id: flake8
24 changes: 24 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
.PHONY: run install dev lint test coverage check

PACKAGE_DIR:=python_template_project

run:
poetry run python main.py

install:
poetry install --no-dev

dev:
poetry install

lint:
poetry run flake8 $(PACKAGE_DIR) tests

test:
poetry run pytest

coverage:
poetry run pytest --cov=$(PACKAGE_DIR) tests

check:
poetry run pre-commit
6 changes: 6 additions & 0 deletions main.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
from python_template_project.demo import Demo


if __name__ == "__main__":
d: Demo = Demo()
d.print_joke()
87 changes: 86 additions & 1 deletion poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ pytest = "^5.2"
flake8 = "^3.9.2"
black = "^21.5b2"
pre-commit = "^2.13.0"
pytest-cov = "^2.12.1"

[build-system]
requires = ["poetry-core>=1.0.0"]
Expand Down
2 changes: 1 addition & 1 deletion python_template_project/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = '0.1.0'
__version__ = "0.1.0"
29 changes: 29 additions & 0 deletions python_template_project/demo.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import requests
from requests import Response

API_URL: str = "http://api.icndb.com/jokes/random"


class Demo:
"""
This class is used to demo a templated Python project.
"""

def __init__(self) -> None:
"""Class Constructor"""
pass

@staticmethod
def _get_joke() -> dict:
"""
Get a random joke from the internet Chuck Norris database.
return: dict
"""
response: Response = requests.get(API_URL)
return response.json()

def print_joke(self) -> None:
"""Print the joke to standard out."""
joke: dict = self._get_joke()
print(joke.get("value").get("joke"))
2 changes: 1 addition & 1 deletion tests/test_python_template_project.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@


def test_version():
assert __version__ == '0.1.0'
assert __version__ == "0.1.0"

0 comments on commit e78fdc7

Please sign in to comment.