Skip to content

Commit

Permalink
test: fix mypy session pass, fix #31
Browse files Browse the repository at this point in the history
  • Loading branch information
TGoddessana committed Feb 11, 2024
1 parent 9606d2b commit cdca980
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 21 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
44 changes: 24 additions & 20 deletions src/flask_moreshell/__main__.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,26 @@
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


@click.command(context_settings=dict(ignore_unknown_options=True))
@click.option(
Expand Down Expand Up @@ -31,23 +48,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 cdca980

Please sign in to comment.