From adfefdf4700d2477f97c2184ebf618898c3ca788 Mon Sep 17 00:00:00 2001 From: RomanZhukov Date: Fri, 24 Jan 2025 11:37:00 +0500 Subject: [PATCH] amendment --- aiohttp_devtools/runserver/config.py | 16 ++++++---------- aiohttp_devtools/runserver/main.py | 2 -- 2 files changed, 6 insertions(+), 12 deletions(-) diff --git a/aiohttp_devtools/runserver/config.py b/aiohttp_devtools/runserver/config.py index 63a46121..5d433209 100644 --- a/aiohttp_devtools/runserver/config.py +++ b/aiohttp_devtools/runserver/config.py @@ -3,7 +3,7 @@ import sys from importlib import import_module from pathlib import Path -from typing import Awaitable, Callable, Optional, Union +from typing import Awaitable, Callable, Optional, Union, Literal from aiohttp import web import ssl @@ -87,12 +87,15 @@ def __init__(self, *, self.bind_address = bind_address if main_port is None: main_port = 8000 if ssl_context_factory_name == None else 8443 - self.protocol = 'http' self.main_port = main_port self.aux_port = aux_port or (main_port + 1) self.browser_cache = browser_cache self.ssl_context_factory_name = ssl_context_factory_name logger.debug('config loaded:\n%s', self) + + @property + def protocol(self) -> Literal["http", "https"]: + return "http" if self.ssl_context_factory_name is None else "https" @property def static_path_str(self) -> Optional[str]: @@ -156,19 +159,13 @@ def import_module(self): if module.__package__: __main__.__package__ = module.__package__ - sys.path.insert(0, str(self.python_path)) - module = import_module(module_path) - # Rewrite the package name, so it will appear the same as running the app. - if module.__package__: - __main__.__package__ = module.__package__ - logger.debug('successfully loaded "%s" from "%s"', module_path, self.python_path) self.watch_path = self.watch_path or Path(module.__file__ or ".").parent return module def get_app_factory(self, module) -> AppFactory: - """Import and return attribute/class from a python module. + """Return attribute/class from a python module. Raises: AdevConfigError - If the import failed. @@ -213,7 +210,6 @@ def get_ssl_context(self, module) -> ssl.SSLContext: self.py_file.name, self.ssl_context_factory_name)) ssl_context = attr() if isinstance(ssl_context, ssl.SSLContext): - self.protocol = 'https' return ssl_context else: raise AdevConfigError("ssl-context-factory '{}' in module '{}' didn't return valid SSLContext".format( diff --git a/aiohttp_devtools/runserver/main.py b/aiohttp_devtools/runserver/main.py index 282086f1..a919e7ef 100644 --- a/aiohttp_devtools/runserver/main.py +++ b/aiohttp_devtools/runserver/main.py @@ -32,8 +32,6 @@ def runserver(**config_kwargs: Any) -> RunServer: config = Config(**config_kwargs) module = config.import_module() ssl_context = config.get_ssl_context(module) - # config.get_app_factory(module) - # config.get_ssl_context_factory(module) asyncio.run(check_port_open(config.main_port, host=config.bind_address))