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.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.3
2
2
  Name: muffin
3
- Version: 1.0.2
3
+ Version: 1.1.1
4
4
  Summary: Muffin is a fast, simple and asyncronous web-framework for Python 3 (asyncio, trio, curio)
5
5
  License: MIT
6
6
  Keywords: asgi,web,web framework,asyncio,trio,curio
@@ -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's shell.
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
- """Start the application's server."""
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: PLR0912, C901
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(command_name, description=description)
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
@@ -1,6 +1,6 @@
1
1
  [tool.poetry]
2
2
  name = "muffin"
3
- version = "1.0.2"
3
+ version = "1.1.1"
4
4
  description = "Muffin is a fast, simple and asyncronous web-framework for Python 3 (asyncio, trio, curio)"
5
5
  readme = "README.rst"
6
6
  license = "MIT"
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