Skip to content

Commit

Permalink
Added mypy (#35)
Browse files Browse the repository at this point in the history
* added mypy
  • Loading branch information
Florian Maas authored Apr 25, 2022
1 parent ad824f0 commit 05cc75d
Show file tree
Hide file tree
Showing 17 changed files with 149 additions and 251 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/run-checks/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ runs:
- name: Formatting check
run: |
source .venv/bin/activate
make lint
make check
shell: bash

- name: Test with pytest
Expand Down
3 changes: 2 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,11 @@ format: ## Format code using isort and black.
@isort .
@black .

lint: ## Check code formatting using isort and black.
check: ## Check code formatting using isort, black, and mypy.
@echo "🚀 Checking code formatting: Running isort and black"
@isort --check-only --diff .
@black --check .
@mypy .

test: ## Test the code with pytest
@echo "🚀 Testing code: Running pytest"
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ repository to generate the file structure for a Python project that uses
- Publishing to [Pypi](https://pypi.org) or [Artifactory](https://jfrog.com/artifactory) by creating a new release on GitHub
- Testing with [pytest](https://docs.pytest.org/en/7.1.x/)
- Documentation with [MkDocs](https://www.mkdocs.org/)
- Static type checking with [mypy](https://mypy.readthedocs.io/en/stable/)
- Compatibility testing for multiple versions of Python with [Tox](https://tox.wiki/en/latest/)

## Example CI/CD Pipeline
Expand Down
1 change: 1 addition & 0 deletions cookiecutter.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,6 @@
"publish_to": ["pypi", "artifactory", "none"],
"mkdocs": ["y", "n"],
"tox": ["y","n"],
"mypy" : ["y","n"],
"open_source_license": ["MIT license", "BSD license", "ISC license", "Apache Software License 2.0", "GNU General Public License v3", "Not open source"]
}
2 changes: 1 addition & 1 deletion cookiecutter_poetry/cli.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import os


def main():
def main() -> None:
cwd = os.path.dirname(__file__)
package_dir = os.path.abspath(os.path.join(cwd, ".."))
os.system(f"cookiecutter {package_dir}")
5 changes: 3 additions & 2 deletions docs/features/makefile.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,15 @@ title: Makefile

The generated repository will have a `Makefile` available. A list of all
available commands that are available can be obtained by running
`make help` in the terminal. Initially, the following commands are
`make help` in the terminal. Initially, if all features are selected, the following commands are
available:

```
install Install the poetry environment
format Format code using isort and black.
lint Check code formatting using isort and black.
check Check code formatting using isort, black and mypy.
test Test the code with pytest
mypy Check types with mypy
build Build wheel file using poetry
clean-build clean build artifacts
publish publish a release to pypi.
Expand Down
23 changes: 23 additions & 0 deletions docs/features/mypy.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
---
title: Mypy
---

If `mypy` is set to `"y"`, static type checking is added with [mypy](https://mypy.readthedocs.io/en/stable/).
If `"github_actions` is also set to `"y"`, the code is checked with `mypy` during every workflow that is triggered.
The default configuration is as shown below, and can be edited in `pyproject.toml`.

```
[tool.mypy]
disallow_untyped_defs = "True"
disallow_any_unimported = "True"
no_implicit_optional = "True"
check_untyped_defs = "True"
warn_return_any = "True"
warn_unused_ignores = "True"
show_error_codes = "True"
exclude = [
'\.venv',
'{{cookiecutter.project_name}}',
'tests'
]
```
1 change: 1 addition & 0 deletions docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ A project generated with ``cookiecutter-poetry`` supports the following features
- Publishing to [Pypi](https://pypi.org) or [Artifactory](https://jfrog.com/artifactory) by creating a new release on GitHub
- Testing with [pytest](https://docs.pytest.org/en/7.1.x/)
- Documentation with [MkDocs](https://www.mkdocs.org/)
- Static type checking with [mypy](https://mypy.readthedocs.io/en/stable/)
- Compatibility testing for multiple versions of Python with [Tox](https://tox.wiki/en/latest/)

An example of a repository generated with this package can be found [here](https://github.com/fpgmaas/cookiecutter-poetry-example).
Expand Down
4 changes: 4 additions & 0 deletions docs/prompt_arguments.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,10 @@ will be deployed to the `gh-pages` branch.
`"y"` or `"n"` Adds automatic [Tox](https://tox.wiki/) testing for
compatibility with multiple versions of Python.

**mypy**

`"y"` or `"n"` Adds automatic static type checking with [mypy](https://mypy.readthedocs.io/en/stable/).

**open_source_license**

Choose a [license](https://choosealicense.com/). Options:
Expand Down
4 changes: 2 additions & 2 deletions hooks/post_gen_project.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@
PROJECT_DIRECTORY = os.path.realpath(os.path.curdir)


def remove_file(filepath):
def remove_file(filepath: str) -> None:
os.remove(os.path.join(PROJECT_DIRECTORY, filepath))


def remove_dir(filepath):
def remove_dir(filepath: str) -> None:
shutil.rmtree(os.path.join(PROJECT_DIRECTORY, filepath))


Expand Down
1 change: 1 addition & 0 deletions mkdocs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ nav:
- Testing with Pytest: features/pytest.md
- Documentation with MkDocs: features/mkdocs.md
- Compatibility testing with Tox: features/tox.md
- Static type checking with mypy: features/mypy.md
- Tutorial: tutorial.md
- Prompt Arguments: prompt_arguments.md
plugins:
Expand Down
Loading

0 comments on commit 05cc75d

Please sign in to comment.