Skip to content

Lint sh cleanup #434

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 2 commits into from
Apr 25, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
14 changes: 14 additions & 0 deletions .codespellignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
__pycache__
*.pyc
.idea
*.egg-info/
.tox/
env/
venv/
.env
.venv
.vscode/
.python-version
.coverage
build/
dist/
20 changes: 11 additions & 9 deletions lint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,15 @@

pip install --upgrade pip
pip install black codespell flake8 isort mypy pytest pyupgrade tox
black --check .
codespell --quiet-level=2 # --ignore-words-list="" --skip=""
flake8 . --count --show-source --statistics
isort --profile black .
tox
pip install -e .
mypy --ignore-missing-imports . || true
pytest .
pytest --doctest-modules . || true
shopt -s globstar && pyupgrade --py37-plus **/*.py

source_dir="./patterns"

codespell --quiet-level=2 ./patterns # --ignore-words-list="" --skip=""
flake8 "${source_dir}" --count --show-source --statistics
isort --profile black "${source_dir}"
tox
mypy --ignore-missing-imports "${source_dir}" || true
pytest "${source_dir}"
pytest --doctest-modules "${source_dir}" || true
shopt -s globstar && pyupgrade --py37-plus ${source_dir}/*.py
41 changes: 40 additions & 1 deletion patterns/structural/mvc.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
"""

from abc import ABC, abstractmethod
from inspect import signature
from sys import argv


class Model(ABC):
Expand Down Expand Up @@ -113,6 +115,23 @@ def show_item_information(self, item_name):
self.view.show_item_information(item_type, item_name, item_info)


class Router:
def __init__(self):
self.routes = {}

def register(self, path, controller, model, view):
model = model()
view = view()
self.routes[path] = controller(model, view)

def resolve(self, path):
if self.routes.get(path):
controller = self.routes[path]
return controller
else:
return None


def main():
"""
>>> model = ProductModel()
Expand Down Expand Up @@ -147,6 +166,26 @@ def main():


if __name__ == "__main__":
import doctest
router = Router()
router.register("products", Controller, ProductModel, ConsoleView)
controller = router.resolve(argv[1])

command = str(argv[2]) if len(argv) > 2 else None
args = ' '.join(map(str, argv[3:])) if len(argv) > 3 else None

if hasattr(controller, command):
command = getattr(controller, command)
sig = signature(command)

if len(sig.parameters) > 0:
if args:
command(args)
else:
print("Command requires arguments.")
else:
command()
else:
print(f"Command {command} not found in the controller.")

import doctest
doctest.testmod()
4 changes: 2 additions & 2 deletions tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@ setenv =
deps =
-r requirements-dev.txt
commands =
flake8 . --exclude="./.*, venv"
flake8 --exclude="venv/,.tox/" patterns/
; `randomly-seed` option from `pytest-randomly` helps with deterministic outputs for examples like `other/blackboard.py`
pytest --randomly-seed=1234 --doctest-modules patterns/
pytest -s -vv --cov={envsitepackagesdir}/patterns --log-level=INFO tests/
pytest -s -vv --cov=patterns/ --log-level=INFO tests/


[testenv:cov-report]
Expand Down