muffin 0.97.2__py3-none-any.whl → 0.98.1__py3-none-any.whl

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/app.py CHANGED
@@ -12,7 +12,7 @@ from asgi_tools._compat import aio_wait
12
12
  from modconfig import Config
13
13
 
14
14
  from muffin.constants import CONFIG_ENV_VARIABLE
15
- from muffin.utils import import_submodules
15
+ from muffin.utils import import_submodules, logger
16
16
 
17
17
  if TYPE_CHECKING:
18
18
  from collections.abc import Awaitable
@@ -75,7 +75,7 @@ class Application(BaseApp):
75
75
  self.manage = Manager(self)
76
76
 
77
77
  # Setup logging
78
- self.logger = logging.getLogger("muffin")
78
+ self.logger = logger
79
79
  self.logger.setLevel(self.cfg.LOG_LEVEL)
80
80
  self.logger.propagate = False
81
81
  if not self.logger.handlers:
@@ -114,7 +114,7 @@ class Application(BaseApp):
114
114
  await aio_wait(*bgtasks)
115
115
  BACKGROUND_TASK.set(None)
116
116
 
117
- def import_submodules(self, *submodules: str):
117
+ def import_submodules(self, *submodules: str, silent: bool = False):
118
118
  """Automatically import submodules.
119
119
 
120
120
  .. code-block:: python
@@ -127,10 +127,13 @@ class Application(BaseApp):
127
127
  # import only specific submodules (in specified order)
128
128
  app.import_submodules('submodule1', 'submodule2')
129
129
 
130
+ # ignore import errors
131
+ app.import_submodules(silent=True)
132
+
130
133
  """
131
134
  parent_frame = stack()[1][0]
132
135
  package_name = parent_frame.f_locals["__name__"]
133
- return import_submodules(package_name, *submodules)
136
+ return import_submodules(package_name, *submodules, silent=silent)
134
137
 
135
138
  def run_after_response(self, *tasks: Awaitable):
136
139
  """Await the given awaitable after the response is completed.
muffin/utils.py CHANGED
@@ -13,6 +13,7 @@ from contextlib import suppress
13
13
  from typing import TYPE_CHECKING, Callable, Coroutine, Dict, TypeVar
14
14
 
15
15
  from asgi_tools.utils import is_awaitable, to_awaitable
16
+ from curio.task import logging
16
17
  from sniffio import current_async_library
17
18
 
18
19
  from muffin.errors import InvalidAppError
@@ -49,6 +50,8 @@ AIOLIBS["asyncio"] = asyncio
49
50
 
50
51
  TV = TypeVar("TV")
51
52
 
53
+ logger = logging.getLogger("muffin")
54
+
52
55
 
53
56
  def aio_lib() -> str:
54
57
  """Return first available async library."""
@@ -72,15 +75,24 @@ def aio_run(corofn: Callable[..., Coroutine[None, None, TV]], *args, **kwargs) -
72
75
  return AIOLIBS[aiolib].run(lambda: corofn(*args, **kwargs))
73
76
 
74
77
 
75
- def import_submodules(package_name: str, *module_names: str) -> Dict[str, ModuleType]:
76
- """Import all submodules by package name."""
78
+ def import_submodules(
79
+ package_name: str, *module_names: str, silent: bool = False
80
+ ) -> Dict[str, ModuleType]:
81
+ """Import all submodules by the given package name."""
77
82
  package = sys.modules[package_name]
78
- return {
79
- module_name: importlib.import_module(f"{package_name}.{module_name}")
80
- for module_name in (
81
- module_names or (name for _, name, _ in pkgutil.walk_packages(package.__path__))
82
- )
83
- }
83
+ res = {}
84
+ for module_name in module_names or (
85
+ name for _, name, _ in pkgutil.walk_packages(package.__path__)
86
+ ):
87
+ try:
88
+ res[module_name] = importlib.import_module(f"{package_name}.{module_name}")
89
+ except ImportError:
90
+ if not silent:
91
+ raise
92
+
93
+ logger.debug("Failed to import module: %s", f"{package_name}.{module_name}")
94
+
95
+ return res
84
96
 
85
97
 
86
98
  def import_app(app_uri: str, *, reload: bool = False) -> Application:
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: muffin
3
- Version: 0.97.2
3
+ Version: 0.98.1
4
4
  Summary: Muffin is a fast, simple and asyncronous web-framework for Python 3 (asyncio, trio, curio)
5
5
  Home-page: https://github.com/klen/muffin
6
6
  License: MIT
@@ -19,18 +19,13 @@ Classifier: Programming Language :: Python :: 3.8
19
19
  Classifier: Programming Language :: Python :: 3.9
20
20
  Classifier: Programming Language :: Python :: 3.10
21
21
  Classifier: Programming Language :: Python :: 3.11
22
- Classifier: Programming Language :: Python :: 3
23
- Classifier: Programming Language :: Python :: 3.10
24
- Classifier: Programming Language :: Python :: 3.11
25
- Classifier: Programming Language :: Python :: 3.8
26
- Classifier: Programming Language :: Python :: 3.9
27
22
  Classifier: Programming Language :: Python :: Implementation :: PyPy
28
23
  Classifier: Topic :: Internet :: WWW/HTTP
29
24
  Provides-Extra: standard
30
- Requires-Dist: asgi-tools (>=0.73.2,<0.74.0)
25
+ Requires-Dist: asgi-tools (>=0,<1)
31
26
  Requires-Dist: gunicorn (>=20.1.0,<21.0.0) ; extra == "standard"
32
- Requires-Dist: modconfig (>=1.2.1,<2.0.0)
33
- Requires-Dist: ujson (>=5.7.0,<6.0.0)
27
+ Requires-Dist: modconfig (>=1,<2)
28
+ Requires-Dist: ujson
34
29
  Requires-Dist: uvicorn[standard] (>=0.21.1,<0.22.0) ; extra == "standard"
35
30
  Project-URL: Documentation, https://klen.github.io/muffin
36
31
  Project-URL: Repository, https://github.com/klen/muffin
@@ -1,5 +1,5 @@
1
1
  muffin/__init__.py,sha256=F8Qp4ETX5FqI1832dj2moRAQ5hEb0TO9u4aRjSKXNjI,982
2
- muffin/app.py,sha256=HxTuFjokxw5_cDeWeOzLXYvw0HZB6ifIcOXAd1GMfTA,5130
2
+ muffin/app.py,sha256=E0lYNlye-9vHvPaW7YOE01bUzQG7ficRy3wISxC5ZFg,5237
3
3
  muffin/constants.py,sha256=Ga1UJiEdXUk6dIEH_IEVYkFSZxQFPhxie7fCJwQY8V0,71
4
4
  muffin/errors.py,sha256=I-vKbMMBiMU07zPdKvoJKqA7s4xYAUA-4oZXrRMRzcM,701
5
5
  muffin/handler.py,sha256=YGodKswFv-dNf8ABODp_JQx0M36nCGmcKewAolrsq9k,3754
@@ -8,8 +8,8 @@ muffin/plugins.py,sha256=rIBO7Y3i3UUGyjPzjkS8XrEcOeoDTRg6sZiMfKtBuhY,2857
8
8
  muffin/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
9
9
  muffin/pytest.py,sha256=Fzersdp2WoO9xCKx5Cezp3yU-We2AU6etiQcT360p3E,2705
10
10
  muffin/types.py,sha256=wsUj5oAfqSZMoEf-wyFJLBlWa8Mc-eJGqKLr02HxuXE,153
11
- muffin/utils.py,sha256=xWhd79f1qEw7CH4BjB6OqVHEOukWckIEc9ap7EHh_hs,2449
12
- muffin-0.97.2.dist-info/METADATA,sha256=X8ZuoRTAypV9_BB_p7F1QWs0CA1QxZlT-zbGEW4kuh8,11614
13
- muffin-0.97.2.dist-info/WHEEL,sha256=7Z8_27uaHI_UZAc4Uox4PpBhQ9Y5_modZXWMxtUi4NU,88
14
- muffin-0.97.2.dist-info/entry_points.txt,sha256=GvPS3M-tNVPzhUS5jnUpOmWw2NAqedY34VRCYgPYzlM,84
15
- muffin-0.97.2.dist-info/RECORD,,
11
+ muffin/utils.py,sha256=SgTKGgpYq73VFabZIU0yf_rM5szJ4QD-gF9HQbspiJc,2743
12
+ muffin-0.98.1.dist-info/METADATA,sha256=GhHbT0vbbljkPKsOubTtLNQLf1hsIcdoqicyvwKD8Zo,11329
13
+ muffin-0.98.1.dist-info/WHEEL,sha256=WGfLGfLX43Ei_YORXSnT54hxFygu34kMpcQdmgmEwCQ,88
14
+ muffin-0.98.1.dist-info/entry_points.txt,sha256=GvPS3M-tNVPzhUS5jnUpOmWw2NAqedY34VRCYgPYzlM,84
15
+ muffin-0.98.1.dist-info/RECORD,,
@@ -1,4 +1,4 @@
1
1
  Wheel-Version: 1.0
2
- Generator: poetry-core 1.5.2
2
+ Generator: poetry-core 1.6.0
3
3
  Root-Is-Purelib: true
4
4
  Tag: py3-none-any