Skip to content

Commit

Permalink
linter and test failures correction
Browse files Browse the repository at this point in the history
  • Loading branch information
zrvku2000 committed Jan 24, 2025
1 parent adfefdf commit d3cbee4
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 11 deletions.
11 changes: 6 additions & 5 deletions aiohttp_devtools/runserver/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,10 @@
from importlib import import_module
from pathlib import Path
from typing import Awaitable, Callable, Optional, Union, Literal
from types import ModuleType

from aiohttp import web
import ssl
from ssl import SSLContext

import __main__
from ..exceptions import AiohttpDevConfigError as AdevConfigError
Expand Down Expand Up @@ -145,7 +146,7 @@ def _resolve_path(self, _path: str, check: str, arg_name: str) -> Path:
raise AdevConfigError('{} is not a directory'.format(path))
return path

def import_module(self):
def import_module(self) -> ModuleType:
"""Import and return python module.
Raises:
Expand All @@ -164,7 +165,7 @@ def import_module(self):
self.watch_path = self.watch_path or Path(module.__file__ or ".").parent
return module

def get_app_factory(self, module) -> AppFactory:
def get_app_factory(self, module: ModuleType) -> AppFactory:
"""Return attribute/class from a python module.
Raises:
Expand Down Expand Up @@ -199,7 +200,7 @@ def get_app_factory(self, module) -> AppFactory:

return attr # type: ignore[no-any-return]

def get_ssl_context(self, module) -> ssl.SSLContext:
def get_ssl_context(self, module: ModuleType) -> Union[SSLContext, None]:
if self.ssl_context_factory_name is None:
return None
else:
Expand All @@ -209,7 +210,7 @@ def get_ssl_context(self, module) -> ssl.SSLContext:
raise AdevConfigError("Module '{}' does not define a '{}' attribute/class".format(

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

View check run for this annotation

Codecov / codecov/patch

aiohttp_devtools/runserver/config.py#L207-L210

Added lines #L207 - L210 were not covered by tests
self.py_file.name, self.ssl_context_factory_name))
ssl_context = attr()

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

View check run for this annotation

Codecov / codecov/patch

aiohttp_devtools/runserver/config.py#L212

Added line #L212 was not covered by tests
if isinstance(ssl_context, ssl.SSLContext):
if isinstance(ssl_context, SSLContext):
return ssl_context

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

View check run for this annotation

Codecov / codecov/patch

aiohttp_devtools/runserver/config.py#L214

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

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

View check run for this annotation

Codecov / codecov/patch

aiohttp_devtools/runserver/config.py#L216

Added line #L216 was not covered by tests
Expand Down
7 changes: 5 additions & 2 deletions aiohttp_devtools/runserver/main.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import asyncio
import os
from multiprocessing import set_start_method
from typing import Any, Type, TypedDict
from typing import Any, Type, TypedDict, Union

from aiohttp.abc import AbstractAccessLogger
from aiohttp.web import Application
Expand All @@ -11,6 +11,7 @@
from .log_handlers import AuxAccessLogger
from .serve import check_port_open, create_auxiliary_app
from .watch import AppTask, LiveReloadTask
from ssl import SSLContext


class RunServer(TypedDict):
Expand All @@ -19,6 +20,8 @@ class RunServer(TypedDict):
port: int
shutdown_timeout: float
access_log_class: Type[AbstractAccessLogger]
ssl_context: Union[SSLContext, None]



def runserver(**config_kwargs: Any) -> RunServer:
Expand Down Expand Up @@ -75,4 +78,4 @@ def serve_static(*, static_path: str, livereload: bool = True, bind_address: str
livereload_status = 'ON' if livereload else 'OFF'
logger.info('Serving "%s" at http://%s:%d, livereload %s', static_path, bind_address, port, livereload_status)
return {"app": app, "host": bind_address, "port": port,
"shutdown_timeout": 0.01, "access_log_class": AuxAccessLogger}
"shutdown_timeout": 0.01, "access_log_class": AuxAccessLogger, "ssl_context": None}
8 changes: 4 additions & 4 deletions aiohttp_devtools/runserver/serve.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import warnings
from errno import EADDRINUSE
from pathlib import Path
from typing import Any, Iterator, List, NoReturn, Optional, Set, Tuple
from typing import Any, Iterator, List, NoReturn, Optional, Set, Tuple, Union

from aiohttp import WSMsgType, web
from aiohttp.hdrs import LAST_MODIFIED, CONTENT_LENGTH
Expand All @@ -25,7 +25,7 @@
from .log_handlers import AccessLogger
from .utils import MutableValue

import ssl
from ssl import SSLContext

try:
from aiohttp_jinja2 import static_root_key
Expand Down Expand Up @@ -173,7 +173,7 @@ def serve_main_app(config: Config, tty_path: Optional[str]) -> None:
with asyncio.Runner() as runner:
app_runner = runner.run(create_main_app(config, app_factory))
try:
runner.run(start_main_app(app_runner, config.bind_address, config.main_port))
runner.run(start_main_app(app_runner, config.bind_address, config.main_port, ssl_context))
runner.get_loop().run_forever()
except KeyboardInterrupt:
pass
Expand Down Expand Up @@ -201,7 +201,7 @@ async def create_main_app(config: Config, app_factory: AppFactory) -> web.AppRun
return web.AppRunner(app, access_log_class=AccessLogger, shutdown_timeout=0.1)


async def start_main_app(runner: web.AppRunner, host: str, port: int, ssl_context: ssl.SSLContext) -> None:
async def start_main_app(runner: web.AppRunner, host: str, port: int, ssl_context: Union[SSLContext, None]) -> None:
await runner.setup()
site = web.TCPSite(runner, host=host, port=port, ssl_context=ssl_context)
await site.start()
Expand Down

0 comments on commit d3cbee4

Please sign in to comment.