-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
3982ba5
commit ad3c3d3
Showing
52 changed files
with
961 additions
and
32 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
[pydocstyle] | ||
ignore = D100, D101, D102, D103, D104, D105, D107, D200, D203, D212 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
import asyncio | ||
import logging | ||
import os | ||
import shutil | ||
from contextlib import suppress, AsyncExitStack | ||
from pathlib import Path | ||
from subprocess import CalledProcessError | ||
from tempfile import TemporaryDirectory | ||
|
||
from betty import subprocess, serve | ||
from betty.locale import Str, Localizer | ||
from betty.serve import Server, NoPublicUrlBecauseServerNotStartedError | ||
|
||
|
||
async def _build_cache(cache_directory_path: Path) -> Path: | ||
cache_directory_path /= 'docs' | ||
if not cache_directory_path.exists(): | ||
await _build(cache_directory_path) | ||
return cache_directory_path | ||
|
||
|
||
async def _build(output_directory_path: Path) -> None: | ||
with suppress(FileExistsError): | ||
await asyncio.to_thread(os.makedirs, output_directory_path) | ||
with TemporaryDirectory() as working_directory_path: | ||
source_directory_path = Path(working_directory_path) / 'source' | ||
await asyncio.to_thread(shutil.copytree, Path(__file__).parent.parent / 'documentation', source_directory_path) | ||
try: | ||
await subprocess.run_exec(['sphinx-apidoc', '--force', '--separate', '-d', '999', '-o', str(source_directory_path), 'betty', 'betty/tests']) | ||
await subprocess.run_exec(['sphinx-build', str(source_directory_path), str(output_directory_path)]) | ||
except CalledProcessError as e: | ||
if e.stderr is not None: | ||
logging.getLogger().error(e.stderr) | ||
raise | ||
|
||
|
||
class _DocumentationServer(Server): | ||
def __init__( | ||
self, | ||
cache_directory_path: Path, | ||
*, | ||
localizer: Localizer, | ||
): | ||
super().__init__(localizer) | ||
self._cache_directory_path = cache_directory_path | ||
self._server: Server | None = None | ||
self._exit_stack = AsyncExitStack() | ||
|
||
@classmethod | ||
def label(cls) -> Str: | ||
return Str._('Betty documentation') | ||
|
||
@property | ||
def public_url(self) -> str: | ||
if self._server is not None: | ||
return self._server.public_url | ||
raise NoPublicUrlBecauseServerNotStartedError() | ||
|
||
async def start(self) -> None: | ||
await super().start() | ||
try: | ||
www_directory_path = await _build_cache(self._cache_directory_path) | ||
self._server = serve.BuiltinServer(www_directory_path, localizer=self._localizer) | ||
await self._exit_stack.enter_async_context(self._server) | ||
except BaseException: | ||
await self.stop() | ||
raise | ||
|
||
async def stop(self) -> None: | ||
await self._exit_stack.aclose() | ||
await super().stop() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.