Skip to content

Commit

Permalink
feat: adds mypy type checking
Browse files Browse the repository at this point in the history
  • Loading branch information
Justintime50 committed Nov 29, 2021
1 parent b9c335b commit 22d0b8b
Show file tree
Hide file tree
Showing 9 changed files with 28 additions and 28 deletions.
8 changes: 2 additions & 6 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,20 +11,16 @@ jobs:
- name: Set up Python
uses: actions/setup-python@v2
with:
python-version: 3.9
python-version: "3.10"
- name: Install Dependencies
run: make install
- name: Run linting
run: make lint
- name: Check format
run: make format-check
- name: Check imports
run: make isort-check
test:
runs-on: ubuntu-latest
strategy:
matrix:
pythonversion: ["3.7", "3.8", "3.9"]
pythonversion: ["3.7", "3.8", "3.9", "3.10"]
steps:
- name: Checkout Repository
uses: actions/checkout@v2
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ jobs:
- name: Set up Python
uses: actions/setup-python@v2
with:
python-version: 3.9
python-version: "3.10"
- name: Install pypa/build
run: >-
python -m
Expand Down
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
# CHANGELOG

## v1.7.0 (2021-11-29)

* Adds `mypy` and type hinting via `py.typed`
* Simplifies template module (removes unused class)
* Adds missing `__all__` variable to `__init__.py`
* Simplifies the lint step of the build by only running checks once (previously some checks were getting run twice)
* Tests against Python `3.10`

## v1.6.0 (2021-10-08)

* Adds `Black` and `iSort` as dev dependencies
Expand Down
8 changes: 6 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,10 @@ black-check:
$(VIRTUAL_BIN)/black $(PROJECT_NAME)/ test/ --check

## format - Runs all formatting tools against the project
format: black isort lint
format: black isort lint mypy

## format-check - Checks if the project is formatted correctly against all formatting rules
format-check: black-check isort-check lint
format-check: black-check isort-check lint mypy

## install - Install the project locally
install:
Expand All @@ -54,6 +54,10 @@ isort-check:
lint:
$(VIRTUAL_BIN)/flake8 $(PROJECT_NAME)/ test/

## mypy - Run mypy type checking on the project
mypy:
$(VIRTUAL_BIN)/mypy $(PROJECT_NAME)/ test/

## test - Test the project
test:
$(VIRTUAL_BIN)/pytest
Expand Down
7 changes: 5 additions & 2 deletions project_name/__init__.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,5 @@
# flake8: noqa
from project_name.my_module import MyModule
from project_name.my_module import main

__all__ = [
'main',
]
7 changes: 1 addition & 6 deletions project_name/my_module.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,6 @@
class MyModule:
def my_function():
pass


def main():
"""The main entrypoint for this script used in the setup.py file."""
MyModule.my_function()
pass


if __name__ == '__main__':
Expand Down
Empty file added project_name/py.typed
Empty file.
2 changes: 2 additions & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
'coveralls == 3.*',
'flake8',
'isort',
'mypy',
'pytest == 6.*',
'pytest-cov == 2.*',
]
Expand All @@ -27,6 +28,7 @@
author='USERNAME',
license='MIT',
packages=setuptools.find_packages(),
package_data={'PROJECT_NAME_URL': ['py.typed']},
classifiers=[
"Programming Language :: Python :: 3",
"License :: OSI Approved :: MIT License",
Expand Down
14 changes: 3 additions & 11 deletions test/unit/test_my_module.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,5 @@
from unittest.mock import patch
import project_name

from project_name.my_module import MyModule, main


def test_my_function():
MyModule.my_function()


@patch('project_name.my_module.MyModule.my_function')
def test_main(mock_my_function):
main()
mock_my_function.assert_called_once()
def test_main():
project_name.main()

0 comments on commit 22d0b8b

Please sign in to comment.