mafw.devtools.documentation.server
Local documentation server management for MAFw.
This module provides the ServerStatusEnum, helper functions, and
orchestration logic for managing a python -m http.server subprocess used
to serve locally built versioned documentation.
Module Attributes
Default directory served by the local documentation server. |
|
Filename for server metadata stored inside the served directory. |
Functions
Format a timestamp for server metadata. |
|
|
Determine the current server status from metadata and process/HTTP checks. |
|
Probe whether the server responds at the given address:port. |
|
Check whether a process resembles the expected http.server invocation. |
|
Read local documentation server metadata if available. |
Return the default directory served by the local documentation server. |
|
|
Return the metadata path associated to a served directory. |
|
Implementation for starting a local documentation server. |
|
Stop the server based on metadata found under a served directory. |
|
Write local documentation server metadata. |
Classes
|
Possible status values for the multiversion-doc local documentation server. |
- class mafw.devtools.documentation.server.ServerStatusEnum(*values)[source]
Bases:
StrEnumPossible status values for the multiversion-doc local documentation server.
- Variables:
running – The server process exists, matches the expected signature and responds over HTTP.
stale – The server process exists and matches the expected signature, but does not respond over HTTP.
stopped – The recorded PID does not exist or does not match the expected signature.
unknown – The metadata file is missing, so no status can be determined.
- static _generate_next_value_(name, start, count, last_values)
Return the lower-cased version of the member name.
- mafw.devtools.documentation.server.format_started_at_utc(now: datetime) str[source]
Format a timestamp for server metadata.
- Parameters:
now (datetime) – A datetime instance (timezone-aware is preferred)
- Returns:
UTC ISO-8601 timestamp with
Zsuffix- Return type:
str
- mafw.devtools.documentation.server.get_server_status(directory: Path) tuple[ServerStatusEnum, dict[str, Any] | None][source]
Determine the current server status from metadata and process/HTTP checks.
- mafw.devtools.documentation.server.http_probe(address: str, port: int, timeout_s: float = 1.0) bool[source]
Probe whether the server responds at the given address:port.
- Parameters:
address (str) – Server address
port (int) – Server port
timeout_s (float) – Timeout in seconds
- Returns:
True if a GET to the server root returns HTTP 200
- Return type:
bool
- mafw.devtools.documentation.server.process_matches_http_server(proc: Any, address: str, port: int, directory: Path) bool[source]
Check whether a process resembles the expected http.server invocation.
- Parameters:
proc (Any) – psutil Process instance
address (str) – Expected bind address
port (int) – Expected port
directory (Path) – Expected served directory
- Returns:
True when the process signature matches
- Return type:
bool
- mafw.devtools.documentation.server.read_server_metadata(directory: Path) dict[str, Any] | None[source]
Read local documentation server metadata if available.
- Parameters:
directory (Path) – Served directory to locate metadata under
- Returns:
Parsed metadata, or None when the metadata file is missing
- Return type:
dict[str, Any] | None
- Raises:
DevtoolsError – If the metadata file exists but cannot be parsed
- mafw.devtools.documentation.server.server_default_directory() Path[source]
Return the default directory served by the local documentation server.
- Returns:
Default documentation build directory
- Return type:
Path
- mafw.devtools.documentation.server.server_metadata_path(directory: Path) Path[source]
Return the metadata path associated to a served directory.
- Parameters:
directory (Path) – Served directory
- Returns:
Metadata JSON file path
- Return type:
Path
- mafw.devtools.documentation.server.server_start_impl(address: str, port: int, directory: Path, log_file: Path, force_restart: bool) None[source]
Implementation for starting a local documentation server.
- mafw.devtools.documentation.server.server_stop_by_metadata(directory: Path, require_metadata: bool) None[source]
Stop the server based on metadata found under a served directory.
- mafw.devtools.documentation.server.write_server_metadata(directory: Path, metadata: dict[str, Any]) None[source]
Write local documentation server metadata.
- Parameters:
directory (Path) – Served directory where metadata is stored
metadata (dict[str, Any]) – Metadata dictionary to serialize as JSON
- Raises:
DevtoolsError – If the metadata file cannot be written
- mafw.devtools.documentation.server.SERVER_DEFAULT_DIRECTORY = PosixPath('docs/build')
Default directory served by the local documentation server.
- mafw.devtools.documentation.server.SERVER_METADATA_FILENAME = '.multiversion-doc-server.json'
Filename for server metadata stored inside the served directory.