Skip to content

Commit

Permalink
Merge 5b12568 into 17ff4c2
Browse files Browse the repository at this point in the history
  • Loading branch information
bartfeenstra authored Dec 20, 2023
2 parents 17ff4c2 + 5b12568 commit 9c09fe8
Show file tree
Hide file tree
Showing 32 changed files with 1,131 additions and 70 deletions.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,8 @@ extensions:
- file: ./gramps.gpkg
betty.extension.HttpApiDoc: {}
betty.extension.Maps: {}
# @todo
betty.extension.Nginx: {}
betty.extension.Privatizer: {}
betty.extension.Trees: {}
betty.extension.Wikipedia: {}
Expand Down Expand Up @@ -183,6 +185,7 @@ extensions:
- `betty.extension.HttpApiDoc` (optional): Renders interactive and user-friendly HTTP API documentation
using [ReDoc](https://github.com/Redocly/redoc).
- `betty.extension.Maps` (optional): Renders interactive maps using [Leaflet](https://leafletjs.com/).
- `betty.extension.Nginx` (optional): @todo
- `betty.extension.Privatizer` (optional): Marks living people private. Configuration: `{}`.
- `betty.extension.Trees` (optional): Renders interactive ancestry trees using [Cytoscape.js](http://js.cytoscape.org/).
- `betty.extension.Wikipedia` (optional): Lets templates and other extensions retrieve complementary Wikipedia
Expand Down
9 changes: 3 additions & 6 deletions betty/app/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,6 @@ def __init__(
):
super().__init__()
self._started = False
self._stopped = False
self._configuration = configuration or AppConfiguration()
self._assets: FileSystem | None = None
self._extensions = _AppExtensions()
Expand Down Expand Up @@ -166,12 +165,10 @@ async def start(self) -> None:
if self._started:
raise RuntimeError('This app has started already.')
self._started = True
self._stopped = False

async def stop(self) -> None:
self._stopped = True
del self.http_client
self._started = False
del self.http_client

def __del__(self) -> None:
if self._started:
Expand Down Expand Up @@ -413,8 +410,8 @@ def servers(self) -> Mapping[str, Server]:
if isinstance(extension, serve.ServerProvider)
for server in extension.servers
),
serve.BuiltinServer(self.localizer, self.project),
DemoServer(self.localizer),
serve.BuiltinServer(self),
DemoServer(),
]
}

Expand Down
8 changes: 7 additions & 1 deletion betty/assets/betty.pot
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ msgid ""
msgstr ""
"Project-Id-Version: Betty VERSION\n"
"Report-Msgid-Bugs-To: EMAIL@ADDRESS\n"
"POT-Creation-Date: 2023-12-18 22:34+0000\n"
"POT-Creation-Date: 2023-12-19 18:46+0000\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <[email protected]>\n"
Expand Down Expand Up @@ -398,6 +398,9 @@ msgstr ""
msgid "General"
msgstr ""

msgid "Generate <a href=\"\">nginx</a> configuration for your site, as well as a <code>Dockerfile</code> to build a <a href=\"https://www.docker.com/\">Docker</a> container around it."
msgstr ""

msgid "Generate entity listing pages"
msgstr ""

Expand Down Expand Up @@ -760,6 +763,9 @@ msgstr ""
msgid "This must be a whole number."
msgstr ""

msgid "This must be none/null."
msgstr ""

msgid "This person's details are unavailable to protect their privacy."
msgstr ""

Expand Down
11 changes: 10 additions & 1 deletion betty/assets/locale/fr-FR/betty.po
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ msgid ""
msgstr ""
"Project-Id-Version: PROJECT VERSION\n"
"Report-Msgid-Bugs-To: EMAIL@ADDRESS\n"
"POT-Creation-Date: 2023-12-18 22:34+0000\n"
"POT-Creation-Date: 2023-12-19 18:46+0000\n"
"PO-Revision-Date: 2020-11-27 19:49+0100\n"
"Last-Translator: \n"
"Language: fr\n"
Expand Down Expand Up @@ -473,6 +473,12 @@ msgstr "Funérailles"
msgid "General"
msgstr ""

msgid ""
"Generate <a href=\"\">nginx</a> configuration for your site, as well as a"
" <code>Dockerfile</code> to build a <a "
"href=\"https://www.docker.com/\">Docker</a> container around it."
msgstr ""

msgid "Generate entity listing pages"
msgstr ""

Expand Down Expand Up @@ -852,6 +858,9 @@ msgstr ""
msgid "This must be a whole number."
msgstr ""

msgid "This must be none/null."
msgstr ""

msgid "This person's details are unavailable to protect their privacy."
msgstr ""
"Les détails concernant cette personne ne sont pas disponibles afin de "
Expand Down
11 changes: 10 additions & 1 deletion betty/assets/locale/nl-NL/betty.po
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ msgid ""
msgstr ""
"Project-Id-Version: PROJECT VERSION\n"
"Report-Msgid-Bugs-To: EMAIL@ADDRESS\n"
"POT-Creation-Date: 2023-12-18 22:34+0000\n"
"POT-Creation-Date: 2023-12-19 18:46+0000\n"
"PO-Revision-Date: 2022-04-08 01:58+0100\n"
"Last-Translator: \n"
"Language: nl\n"
Expand Down Expand Up @@ -504,6 +504,12 @@ msgstr "Uitvaart"
msgid "General"
msgstr "Algemeen"

msgid ""
"Generate <a href=\"\">nginx</a> configuration for your site, as well as a"
" <code>Dockerfile</code> to build a <a "
"href=\"https://www.docker.com/\">Docker</a> container around it."
msgstr "Genereer <a href=\"\">nginx</a>-configuratie voor je site, evenals een <code>Dockerfile</code> om er een <a href=\"https://www.docker.com/\">Docker</a>-container omheen te bouwen."

msgid "Generate entity listing pages"
msgstr "Genereer pagina's met entiteitsoverzichten"

Expand Down Expand Up @@ -890,6 +896,9 @@ msgstr "Dit moet een tekenreeks zijn."
msgid "This must be a whole number."
msgstr "Dit moet een geheel getal zijn."

msgid "This must be none/null."
msgstr "Dit moet none/null zijn."

msgid "This person's details are unavailable to protect their privacy."
msgstr "De gegevens van deze persoon zijn niet beschikbaar vanwege privacyredenen."

Expand Down
11 changes: 10 additions & 1 deletion betty/assets/locale/uk/betty.po
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ msgid ""
msgstr ""
"Project-Id-Version: Betty VERSION\n"
"Report-Msgid-Bugs-To: EMAIL@ADDRESS\n"
"POT-Creation-Date: 2023-12-18 22:34+0000\n"
"POT-Creation-Date: 2023-12-19 18:46+0000\n"
"PO-Revision-Date: 2020-05-02 22:29+0100\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language: uk\n"
Expand Down Expand Up @@ -474,6 +474,12 @@ msgstr "Похорон"
msgid "General"
msgstr ""

msgid ""
"Generate <a href=\"\">nginx</a> configuration for your site, as well as a"
" <code>Dockerfile</code> to build a <a "
"href=\"https://www.docker.com/\">Docker</a> container around it."
msgstr ""

msgid "Generate entity listing pages"
msgstr ""

Expand Down Expand Up @@ -855,6 +861,9 @@ msgstr ""
msgid "This must be a whole number."
msgstr ""

msgid "This must be none/null."
msgstr ""

msgid "This person's details are unavailable to protect their privacy."
msgstr "Дані цієї особи недоступні для захисту їх конфіденційності."

Expand Down
14 changes: 6 additions & 8 deletions betty/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import asyncio
import logging
import sys
import time
from contextlib import suppress, contextmanager
from functools import wraps
from pathlib import Path
Expand All @@ -24,7 +23,7 @@
from betty.locale import update_translations, init_translation, Str
from betty.logging import CliHandler
from betty.serde.load import AssertionFailed
from betty.serve import ProjectServer
from betty.serve import AppServer

T = TypeVar('T')
P = ParamSpec('P')
Expand Down Expand Up @@ -181,11 +180,10 @@ async def _clear_caches() -> None:
@click.command(help='Explore a demonstration site.')
@global_command
async def _demo() -> None:
async with App() as app:
async with demo.DemoServer(app.localizer) as server:
await server.show()
while True:
time.sleep(999)
async with demo.DemoServer() as server:
await server.show()
while True:
await asyncio.sleep(999)


@click.command(help="Open Betty's graphical user interface (GUI).")
Expand Down Expand Up @@ -221,7 +219,7 @@ async def _generate(app: App) -> None:
@click.command(help='Serve a generated site.')
@app_command
async def _serve(app: App) -> None:
async with ProjectServer.get(app) as server:
async with AppServer.get(app) as server:
await server.show()
while True:
await asyncio.sleep(999)
Expand Down
3 changes: 1 addition & 2 deletions betty/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -476,8 +476,7 @@ def dump(self) -> VoidableDump:
item_dump, configuration_key = self._dump_key(item_dump)
if self._minimize_item_dump():
item_dump = minimize(item_dump)
if item_dump is not Void:
dump[configuration_key] = item_dump
dump[configuration_key] = item_dump
return minimize(dump)

def prepend(self, *configurations: ConfigurationT) -> None:
Expand Down
5 changes: 4 additions & 1 deletion betty/error.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import traceback
from typing import TypeVar
from typing import TypeVar, Self

from betty.locale import Localizable, DEFAULT_LOCALIZER, Localizer

Expand Down Expand Up @@ -35,6 +35,9 @@ def __init__(self, message: Localizable):
)
self._localizable_message = message

def __reduce__(self) -> tuple[type[Self], tuple[Localizable]]:
return type(self), (self._localizable_message,)

def __str__(self) -> str:
return self.localize(DEFAULT_LOCALIZER)

Expand Down
5 changes: 5 additions & 0 deletions betty/extension/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
from betty.extension.gramps import _Gramps
from betty.extension.http_api_doc import _HttpApiDoc
from betty.extension.maps import _Maps
from betty.extension.nginx import _Nginx
from betty.extension.privatizer import _Privatizer
from betty.extension.trees import _Trees
from betty.extension.wikipedia import _Wikipedia
Expand Down Expand Up @@ -35,6 +36,10 @@ class Maps(_Maps):
pass


class Nginx(_Nginx):
pass


class Privatizer(_Privatizer):
pass

Expand Down
48 changes: 28 additions & 20 deletions betty/extension/demo/__init__.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,20 @@
from __future__ import annotations

from contextlib import AsyncExitStack

from geopy import Point

from betty import load, generate
from betty.app import App
from betty.app.extension import Extension
from betty.load import Loader
from betty.locale import Date, DateRange, Str, Localizer
from betty.locale import Date, DateRange, Str
from betty.model import Entity
from betty.model.ancestry import Place, PlaceName, Person, Presence, Subject, PersonName, Link, Source, Citation, Event, \
Enclosure
from betty.model.event_type import Marriage, Birth, Death
from betty.project import LocaleConfiguration, ExtensionConfiguration, EntityReference
from betty.serve import Server, ProjectServer, NoPublicUrlBecauseServerNotStartedError
from betty.serve import Server, AppServer, NoPublicUrlBecauseServerNotStartedError


class _Demo(Extension, Loader):
Expand Down Expand Up @@ -359,9 +361,19 @@ async def load(self) -> None:


class DemoServer(Server):
def __init__(self, localizer: Localizer):
super().__init__(localizer)
def __init__(self):
self._app = App()
super().__init__(self._app.localizer)
self._app.project.configuration.extensions.append(ExtensionConfiguration(_Demo))
# Include all of the translations Betty ships with.
self._app.project.configuration.locales.replace(
LocaleConfiguration('en-US', 'en'),
LocaleConfiguration('nl-NL', 'nl'),
LocaleConfiguration('fr-FR', 'fr'),
LocaleConfiguration('uk', 'uk'),
)
self._server: Server | None = None
self._exit_stack = AsyncExitStack()

@classmethod
def label(cls) -> Str:
Expand All @@ -374,21 +386,17 @@ def public_url(self) -> str:
raise NoPublicUrlBecauseServerNotStartedError()

async def start(self) -> None:
app = App()
app.project.configuration.extensions.append(ExtensionConfiguration(_Demo))
# Include all of the translations Betty ships with.
app.project.configuration.locales.replace(
LocaleConfiguration('en-US', 'en'),
LocaleConfiguration('nl-NL', 'nl'),
LocaleConfiguration('fr-FR', 'fr'),
LocaleConfiguration('uk', 'uk'),
)
await load.load(app)
self._server = ProjectServer.get(app)
await self._server.start()
app.project.configuration.base_url = self._server.public_url
await generate.generate(app)
try:
await super().start()
await self._exit_stack.enter_async_context(self._app)
await load.load(self._app)
self._server = AppServer.get(self._app)
await self._exit_stack.enter_async_context(self._server)
self._app.project.configuration.base_url = self._server.public_url
await generate.generate(self._app)
finally:
await self.stop()

async def stop(self) -> None:
if self._server:
await self._server.stop()
await self._exit_stack.aclose()
await super().stop()
Loading

0 comments on commit 9c09fe8

Please sign in to comment.