From 9606d2b7865c1e21479ea97b071748322f833e21 Mon Sep 17 00:00:00 2001 From: goddessana Date: Sun, 11 Feb 2024 20:35:59 +0900 Subject: [PATCH 1/4] test: fix coverage percentage --- pyproject.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyproject.toml b/pyproject.toml index 28396b7..bbf31fe 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -68,7 +68,7 @@ source = ["flask_moreshell", "tests"] [tool.coverage.report] show_missing = true -fail_under = 100 +fail_under = 80 [tool.isort] profile = "black" From cdca98047fe204b2cde11fcec5ff539eb4818793 Mon Sep 17 00:00:00 2001 From: goddessana Date: Sun, 11 Feb 2024 20:39:34 +0900 Subject: [PATCH 2/4] test: fix mypy session pass, fix #31 --- noxfile.py | 4 ++- src/flask_moreshell/__main__.py | 44 ++++++++++++++++++--------------- 2 files changed, 27 insertions(+), 21 deletions(-) diff --git a/noxfile.py b/noxfile.py index 5de71f1..302140e 100644 --- a/noxfile.py +++ b/noxfile.py @@ -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") diff --git a/src/flask_moreshell/__main__.py b/src/flask_moreshell/__main__.py index 3939f19..c5306fa 100644 --- a/src/flask_moreshell/__main__.py +++ b/src/flask_moreshell/__main__.py @@ -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( @@ -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) From 48570d2f6b42089b432917df39b876d1e0d2b2bc Mon Sep 17 00:00:00 2001 From: goddessana Date: Sun, 11 Feb 2024 20:44:26 +0900 Subject: [PATCH 3/4] test: fix `No return statement` error --- src/flask_moreshell/__main__.py | 1 + 1 file changed, 1 insertion(+) diff --git a/src/flask_moreshell/__main__.py b/src/flask_moreshell/__main__.py index c5306fa..36255db 100644 --- a/src/flask_moreshell/__main__.py +++ b/src/flask_moreshell/__main__.py @@ -20,6 +20,7 @@ def _find_available_shell(shell_classes: dict[str, str]) -> BaseShell: 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)) From aad4f375f2e82e47a0cb152ae86d6fd93ac2e946 Mon Sep 17 00:00:00 2001 From: goddessana Date: Sun, 11 Feb 2024 20:56:03 +0900 Subject: [PATCH 4/4] feat: version 0.1.4 --- pyproject.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyproject.toml b/pyproject.toml index bbf31fe..93dba00 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [tool.poetry] name = "flask-moreshell" -version = "0.1.3" +version = "0.1.4" description = "Flask Moreshell" authors = ["JAEGYUN JUNG "] license = "MIT"