Skip to content

Commit

Permalink
Merge pull request #85 from TGoddessana/configure-mypy
Browse files Browse the repository at this point in the history
make package pass mypy test
  • Loading branch information
TGoddessana authored Feb 11, 2024
2 parents 6c458c6 + aad4f37 commit dca77f4
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 23 deletions.
4 changes: 3 additions & 1 deletion noxfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,9 @@ def mypy(session: Session) -> None:
"""Type-check using mypy."""
args = session.posargs or ["src", "tests", "docs/conf.py"]
session.install(".")
session.install("mypy", "pytest")
session.install(
"mypy", "pytest", "flask", "ipython", "bpython", "ptpython", "black"
)
session.run("mypy", *args)
if not session.posargs:
session.run("mypy", f"--python-executable={sys.executable}", "noxfile.py")
Expand Down
4 changes: 2 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "flask-moreshell"
version = "0.1.3"
version = "0.1.4"
description = "Flask Moreshell"
authors = ["JAEGYUN JUNG <[email protected]>"]
license = "MIT"
Expand Down Expand Up @@ -68,7 +68,7 @@ source = ["flask_moreshell", "tests"]

[tool.coverage.report]
show_missing = true
fail_under = 100
fail_under = 80

[tool.isort]
profile = "black"
Expand Down
45 changes: 25 additions & 20 deletions src/flask_moreshell/__main__.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,27 @@
import importlib
import sys
from importlib import import_module

import click
from flask.cli import with_appcontext

from flask_moreshell.shells.base_shell import BaseShell


def _get_shell_instance(shelltype: str, shell_classes: dict[str, str]) -> BaseShell:
shell_class_name = shell_classes[shelltype]
shell_module = import_module(f"flask_moreshell.shells.{shelltype}_shell")
shell_class: type[BaseShell] = getattr(shell_module, shell_class_name)
return shell_class()


def _find_available_shell(shell_classes: dict[str, str]) -> BaseShell:
for shell_class in shell_classes.keys():
try:
return _get_shell_instance(shell_class, shell_classes)
except ModuleNotFoundError:
continue
return _get_shell_instance("python", shell_classes)


@click.command(context_settings=dict(ignore_unknown_options=True))
@click.option(
Expand Down Expand Up @@ -31,23 +49,10 @@ def shell(shelltype: str) -> None:
}

if shelltype:
shell_class = shell_classes[shelltype]
try:
shell_module = importlib.import_module(
f"flask_moreshell.shells.{shelltype}_shell"
)
shell_class = getattr(shell_module, shell_class)
shell_class().load()
except ModuleNotFoundError as e:
print(e)
_shell = _get_shell_instance(shelltype, shell_classes)
_shell.load()
sys.exit(0)
else:
for shell_class in shell_classes.keys():
try:
shell_module = importlib.import_module(
f"flask_moreshell.shells.{shell_class}_shell"
)
shell_class = getattr(shell_module, shell_classes[shell_class])
shell_class().load()
sys.exit(0)
except ModuleNotFoundError:
continue
_shell = _find_available_shell(shell_classes)
_shell.load()
sys.exit(0)

0 comments on commit dca77f4

Please sign in to comment.