From ab5a3011a0adb39d0e99e8309b3a6ea4aec7c893 Mon Sep 17 00:00:00 2001 From: Bart Feenstra Date: Fri, 21 Jun 2024 18:11:07 +0100 Subject: [PATCH] Remove server negotiation --- betty/app/__init__.py | 25 +------------------------ betty/cli.py | 4 ++-- betty/extension/nginx/__init__.py | 12 ------------ betty/gui/serve.py | 6 +++--- betty/serve.py | 27 +-------------------------- 5 files changed, 7 insertions(+), 67 deletions(-) diff --git a/betty/app/__init__.py b/betty/app/__init__.py index b10ec0d97..11ec1461d 100644 --- a/betty/app/__init__.py +++ b/betty/app/__init__.py @@ -11,7 +11,7 @@ from multiprocessing import get_context from os import environ from pathlib import Path -from typing import TYPE_CHECKING, Mapping, Self, Any, final +from typing import TYPE_CHECKING, Self, Any, final import aiohttp from aiofiles.tempfile import TemporaryDirectory @@ -76,7 +76,6 @@ from types import TracebackType from collections.abc import AsyncIterator from betty.jinja2 import Environment - from betty.serve import Server from betty.url import StaticUrlGenerator, LocalizedUrlGenerator CONFIGURATION_DIRECTORY_PATH = fs.HOME_DIRECTORY_PATH / "configuration" @@ -660,28 +659,6 @@ def event_types(self) -> set[type[EventType]]: def event_types(self) -> None: self._event_types = None - @property - def servers(self) -> Mapping[str, Server]: - """ - The available web servers. - """ - from betty import serve - from betty.extension.demo import DemoServer - - return { - server.name(): server - for server in [ - *( - server - for extension in self.extensions.flatten() - if isinstance(extension, serve.ServerProvider) - for server in extension.servers - ), - serve.BuiltinAppServer(self), - DemoServer(app=self), - ] - } - @property def cache(self) -> Cache[Any] & FileCache: """ diff --git a/betty/cli.py b/betty/cli.py index 8419d5160..1d6d638d2 100644 --- a/betty/cli.py +++ b/betty/cli.py @@ -33,7 +33,7 @@ from betty.locale import Str, DEFAULT_LOCALIZER from betty.logging import CliHandler from betty.serde.load import AssertionFailed -from betty.serve import AppServer +from betty.serve import BuiltinAppServer if TYPE_CHECKING: from PyQt6.QtWidgets import QMainWindow @@ -330,7 +330,7 @@ async def _generate(app: App) -> None: @click.command(help="Serve a generated site.") @app_command async def _serve(app: App) -> None: - async with AppServer.get(app) as server: + async with BuiltinAppServer(app) as server: await server.show() while True: await asyncio.sleep(999) diff --git a/betty/extension/nginx/__init__.py b/betty/extension/nginx/__init__.py index 4e970d528..d5e94b4e2 100644 --- a/betty/extension/nginx/__init__.py +++ b/betty/extension/nginx/__init__.py @@ -1,6 +1,5 @@ """Integrate Betty with `nginx `_.""" -from collections.abc import Sequence from pathlib import Path from click import Command @@ -18,14 +17,12 @@ from betty.generate import Generator, GenerationContext from betty.gui import GuiBuilder from betty.locale import Str, Localizable -from betty.serve import ServerProvider, Server class Nginx( ConfigurableExtension[NginxConfiguration], UserFacingExtension, Generator, - ServerProvider, GuiBuilder, CommandProvider, ): @@ -50,15 +47,6 @@ def description(cls) -> Localizable: def default_configuration(cls) -> NginxConfiguration: return NginxConfiguration() - @override - @property - def servers(self) -> Sequence[Server]: - from betty.extension.nginx.serve import DockerizedNginxServer - - if DockerizedNginxServer.is_available(): - return [DockerizedNginxServer(self._app)] - return [] - @override async def generate(self, job_context: GenerationContext) -> None: await generate_configuration_file(self._app) diff --git a/betty/gui/serve.py b/betty/gui/serve.py index b83b6264d..d9c194e2f 100644 --- a/betty/gui/serve.py +++ b/betty/gui/serve.py @@ -11,16 +11,16 @@ from PyQt6.QtWidgets import QVBoxLayout, QWidget, QPushButton from typing_extensions import override -from betty import documentation +from betty import documentation, serve from betty.asyncio import wait_to_thread from betty.extension import demo from betty.gui.error import ExceptionCatcher from betty.gui.text import Text from betty.gui.window import BettyMainWindow from betty.locale import Str, Localizable -from betty.serve import Server, AppServer if TYPE_CHECKING: + from betty.serve import Server from betty.app import App @@ -128,7 +128,7 @@ class ServeProjectWindow(_ServeWindow): @override def _new_server(self) -> Server: - return AppServer.get(self._app) + return serve.BuiltinAppServer(self._app) @override @property diff --git a/betty/serve.py b/betty/serve.py index 979474937..9296b202d 100644 --- a/betty/serve.py +++ b/betty/serve.py @@ -11,7 +11,7 @@ from http.server import SimpleHTTPRequestHandler, HTTPServer from io import StringIO from pathlib import Path -from typing import Sequence, Any, TYPE_CHECKING +from typing import Any, TYPE_CHECKING from aiofiles.os import makedirs, symlink from aiofiles.tempfile import TemporaryDirectory, AiofilesContextManagerTempDir @@ -153,18 +153,6 @@ def __init__(self, app: App) -> None: super().__init__(localizer=app.localizer) self._app = app - @staticmethod - def get(app: App) -> AppServer: - """ - Get a web server for the given Betty application. - """ - for server in app.servers.values(): - if isinstance(server, AppServer): - return server - raise RuntimeError( - f"Cannot find a project server. This must never happen, because {BuiltinAppServer} should be the fallback." - ) - @override async def start(self) -> None: await makedirs( @@ -173,19 +161,6 @@ async def start(self) -> None: await super().start() -class ServerProvider: - """ - Provide one or more web servers. - """ - - @property - def servers(self) -> Sequence[Server]: - """ - Provide one or more web servers. - """ - raise NotImplementedError(repr(self)) - - class _BuiltinServerRequestHandler(SimpleHTTPRequestHandler): @override def end_headers(self) -> None: