Skip to content

Commit

Permalink
Add precommit hooks
Browse files Browse the repository at this point in the history
  • Loading branch information
StefanUlbrich committed Mar 9, 2022
1 parent bb4a795 commit 4e99e28
Show file tree
Hide file tree
Showing 5 changed files with 171 additions and 4 deletions.
51 changes: 51 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
# See https://pre-commit.com for more information
# See https://pre-commit.com/hooks.html for more hooks
# where are the environments stored https://stackoverflow.com/a/62539529
# inspired by https://github.com/pronovic/apologies
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v3.2.0
hooks:
- id: trailing-whitespace
files: '.*\.(py|rst|json|yaml)'
- id: end-of-file-fixer
files: '.*\.(py|rst|json|yaml)'
- id: check-yaml
- id: check-added-large-files
- repo: local
hooks:
- id: system
name: Black
entry: poetry run black src tests
pass_filenames: false
language: system
- repo: local
hooks:
- id: system
name: isort
entry: poetry run isort src --profile black
pass_filenames: false
language: system
# - repo: local
# hooks:
# - id: system
# name: Safety
# entry: poetry run safety check
# pass_filenames: false
# language: system

# Disabled until mypy support structural pattern matching
# - repo: local
# hooks:
# - id: system
# name: MyPy
# entry: poetry run mypy -p design_by_contract
# pass_filenames: false
# language: system
- repo: local
hooks:
- id: system
name: Pylint
entry: poetry run pylint -j0 design_by_contract --disable=R,C,W
pass_filenames: false
language: system
3 changes: 3 additions & 0 deletions Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,9 @@ Note that evaluation is not optimized. In production, you might consider disabli
* [x] Tested with pytest
* [x] Type annotations
* [x] code formatted ([black](https://github.com/psf/black)), linted ([pylint](https://pylint.org/)). Linting with [mypy](http://www.mypy-lang.org/) does not support pattern matching yet.
* [x] GitHub action for GitHub pages
* [ ] GitHub action for linting and formatting
* [x] Precommit for linting and formatting
* [ ] Speed. Well.. maybe. I haven't tested it yet.

## Why?
Expand Down
111 changes: 110 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 @@ -30,6 +30,7 @@ pytest = "^6.2.5"
ipykernel = "^6.9.1"
sphinx-book-theme = "^0.2.0"
myst-parser = "^0.17.0"
pre-commit = "^2.17.0"

[build-system]
requires = ["poetry-core>=1.0.0"]
Expand Down
9 changes: 6 additions & 3 deletions src/design_by_contract.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
from dataclasses import dataclass
import logging
from dataclasses import dataclass
from inspect import get_annotations, getfullargspec
from typing import Annotated, Callable, Any, TypeVar, ParamSpec, Optional
from typing import Annotated, Any, Callable, Optional, ParamSpec, TypeVar

from decorator import decorator

logger = logging.getLogger(__name__)
Expand Down Expand Up @@ -124,7 +125,9 @@ def evaluate_annotations(annotations: dict[str, Any]) -> None:
raise ContractViolationError(f"Contract violated for argument: `{arg_name}`")

if any([i.value is None for i in symbols.values()]):
raise ContractLogicError(f"Not all symbols were resolved `{symbols}`", )
raise ContractLogicError(
f"Not all symbols were resolved `{symbols}`",
)

injectables |= {k: v.value for k, v in symbols.items()}

Expand Down

0 comments on commit 4e99e28

Please sign in to comment.