Skip to content

Commit

Permalink
amendment
Browse files Browse the repository at this point in the history
  • Loading branch information
zrvku2000 committed Jan 24, 2025
1 parent 9f26d69 commit adfefdf
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 12 deletions.
16 changes: 6 additions & 10 deletions aiohttp_devtools/runserver/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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]:
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -213,7 +210,6 @@ def get_ssl_context(self, module) -> ssl.SSLContext:
self.py_file.name, self.ssl_context_factory_name))
ssl_context = attr()

Check warning on line 211 in aiohttp_devtools/runserver/config.py

View check run for this annotation

Codecov / codecov/patch

aiohttp_devtools/runserver/config.py#L211

Added line #L211 was not covered by tests
if isinstance(ssl_context, ssl.SSLContext):
self.protocol = 'https'
return ssl_context

Check warning on line 213 in aiohttp_devtools/runserver/config.py

View check run for this annotation

Codecov / codecov/patch

aiohttp_devtools/runserver/config.py#L213

Added line #L213 was not covered by tests
else:
raise AdevConfigError("ssl-context-factory '{}' in module '{}' didn't return valid SSLContext".format(

Check warning on line 215 in aiohttp_devtools/runserver/config.py

View check run for this annotation

Codecov / codecov/patch

aiohttp_devtools/runserver/config.py#L215

Added line #L215 was not covered by tests
Expand Down
2 changes: 0 additions & 2 deletions aiohttp_devtools/runserver/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -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))

Expand Down

0 comments on commit adfefdf

Please sign in to comment.