muffin 1.0.2__tar.gz → 1.1.1__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {muffin-1.0.2 → muffin-1.1.1}/PKG-INFO +1 -1
- {muffin-1.0.2 → muffin-1.1.1}/muffin/manage.py +22 -9
- {muffin-1.0.2 → muffin-1.1.1}/pyproject.toml +1 -1
- {muffin-1.0.2 → muffin-1.1.1}/README.rst +0 -0
- {muffin-1.0.2 → muffin-1.1.1}/muffin/__init__.py +0 -0
- {muffin-1.0.2 → muffin-1.1.1}/muffin/app.py +0 -0
- {muffin-1.0.2 → muffin-1.1.1}/muffin/constants.py +0 -0
- {muffin-1.0.2 → muffin-1.1.1}/muffin/errors.py +0 -0
- {muffin-1.0.2 → muffin-1.1.1}/muffin/handler.py +0 -0
- {muffin-1.0.2 → muffin-1.1.1}/muffin/plugins.py +0 -0
- {muffin-1.0.2 → muffin-1.1.1}/muffin/py.typed +0 -0
- {muffin-1.0.2 → muffin-1.1.1}/muffin/pytest.py +0 -0
- {muffin-1.0.2 → muffin-1.1.1}/muffin/types.py +0 -0
- {muffin-1.0.2 → muffin-1.1.1}/muffin/utils.py +0 -0
@@ -57,9 +57,7 @@ class Manager:
|
|
57
57
|
def __init__(self, app: "Application"):
|
58
58
|
"""Initialize the manager."""
|
59
59
|
self.app = app
|
60
|
-
self.parser = argparse.ArgumentParser(
|
61
|
-
description="Manage %s" % app.cfg.name.capitalize(),
|
62
|
-
)
|
60
|
+
self.parser = argparse.ArgumentParser(description="Manage %s" % app.cfg.name.capitalize())
|
63
61
|
|
64
62
|
if len(AIOLIBS) > 1:
|
65
63
|
self.parser.add_argument(
|
@@ -88,7 +86,7 @@ class Manager:
|
|
88
86
|
|
89
87
|
# We have to use sync mode here because of eventloop conflict with ipython/promt-toolkit
|
90
88
|
def shell(*, ipython: bool = True):
|
91
|
-
"""Start the application
|
89
|
+
"""Start an interactive shell with the application context.
|
92
90
|
|
93
91
|
:param ipython: Use IPython as a shell
|
94
92
|
"""
|
@@ -110,7 +108,7 @@ class Manager:
|
|
110
108
|
self(shell)
|
111
109
|
|
112
110
|
def run(host: str = "localhost", port: int = 5000):
|
113
|
-
"""
|
111
|
+
"""Run the application with the given host and port."""
|
114
112
|
from uvicorn.main import run as urun
|
115
113
|
|
116
114
|
cfg = self.app.cfg
|
@@ -141,7 +139,7 @@ class Manager:
|
|
141
139
|
def __call__(self, fn=None, *, lifespan=False): # noqa: C901
|
142
140
|
"""Register a command."""
|
143
141
|
|
144
|
-
def wrapper(fn): # noqa:
|
142
|
+
def wrapper(fn): # noqa: C901, PLR0912
|
145
143
|
if not inspect.iscoroutinefunction(fn) and lifespan:
|
146
144
|
raise AsyncRequiredError(fn)
|
147
145
|
|
@@ -155,7 +153,9 @@ class Manager:
|
|
155
153
|
self.app.logger.warning("Command %s already registered", command_name)
|
156
154
|
return fn
|
157
155
|
|
158
|
-
parser = self.subparsers.add_parser(
|
156
|
+
parser = self.subparsers.add_parser(
|
157
|
+
command_name, description=description, help=description
|
158
|
+
)
|
159
159
|
sig = inspect.signature(fn)
|
160
160
|
docs = dict(PARAM_RE.findall(fn.__doc__ or ""))
|
161
161
|
|
@@ -235,6 +235,14 @@ class Manager:
|
|
235
235
|
if prog:
|
236
236
|
self.parser.prog = prog
|
237
237
|
|
238
|
+
# Sort subparsers by name
|
239
|
+
choices_actions = getattr(self.subparsers, "_choices_actions", None)
|
240
|
+
if choices_actions:
|
241
|
+
sorted_actions = sorted(choices_actions, key=lambda a: a.dest)
|
242
|
+
choices_actions.clear()
|
243
|
+
choices_actions.extend(sorted_actions)
|
244
|
+
self.subparsers.metavar = "{" + ",".join(a.dest for a in sorted_actions) + "}"
|
245
|
+
|
238
246
|
ns, _ = self.parser.parse_known_args(args or sys.argv[1:])
|
239
247
|
kwargs = dict(ns._get_kwargs())
|
240
248
|
fn = self.commands.get(kwargs.pop("subparser"))
|
@@ -281,8 +289,13 @@ def cli():
|
|
281
289
|
try:
|
282
290
|
app = import_app(args_.app)
|
283
291
|
app.logger.info("Application is loaded: %s", app.cfg.name)
|
284
|
-
app.manage.run(*subargs_, prog="muffin %s" % args_.app)
|
285
292
|
|
293
|
+
except ImportError:
|
294
|
+
logging.exception("Failed to import application")
|
295
|
+
return sys.exit(1)
|
296
|
+
|
297
|
+
try:
|
298
|
+
app.manage.run(*subargs_, prog="muffin %s" % args_.app)
|
286
299
|
except Exception:
|
287
300
|
logging.exception("Command failed")
|
288
301
|
return sys.exit(1)
|
@@ -290,4 +303,4 @@ def cli():
|
|
290
303
|
sys.exit(0)
|
291
304
|
|
292
305
|
|
293
|
-
# ruff: noqa: T100
|
306
|
+
# ruff: noqa: T100, LOG015
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|