Skip to content

Commit

Permalink
lazy load yaml library
Browse files Browse the repository at this point in the history
  • Loading branch information
Mickaël Guérin committed Jan 14, 2023
1 parent 23b9f05 commit e35b34f
Showing 1 changed file with 4 additions and 8 deletions.
12 changes: 4 additions & 8 deletions uvicorn/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,6 @@

import click

try:
import yaml
except ImportError: # pragma: no cover
# If the code below that depends on yaml is exercised, it will raise a NameError.
# Install the PyYAML package or the uvicorn[standard] optional dependencies to
# enable this functionality.
pass

from uvicorn.importer import ImportFromStringError, import_from_string
from uvicorn.middleware.asgi2 import ASGI2Middleware
from uvicorn.middleware.message_logger import MessageLoggerMiddleware
Expand Down Expand Up @@ -410,6 +402,10 @@ def configure_logging(self) -> None:
loaded_config = json.load(file)
logging.config.dictConfig(loaded_config)
elif self.log_config.endswith((".yaml", ".yml")):
# Install the PyYAML package or the uvicorn[standard] optional
# dependencies to enable this functionality.
import yaml

with open(self.log_config) as file:
loaded_config = yaml.safe_load(file)
logging.config.dictConfig(loaded_config)
Expand Down

0 comments on commit e35b34f

Please sign in to comment.