demopkg
Type part of a name or a dotted path
Demo package used by the starlight-pydocs test suite.
demopkg exists to exercise every feature of the documentation renderer:
google-style docstring sections, inheritance, overloads, positional-only and
keyword-only parameters, re-exports through __all__, pydantic models,
deprecations and private members that must stay hidden.
The public surface is declared explicitly in __all__, so anything not listed
there is invisible to the default member filter.
Examples
Build a report and write it to disk:
>>> from demopkg import Report>>> report = Report("weekly")>>> report.generate("summary", title="Weekly")PosixPath('weekly.txt')Attributes
| Name | Description |
|---|---|
DEFAULT_TIMEOUT | Seconds to wait for report generation before giving up. |
Classes
| Name | Description |
|---|---|
Report | A named collection of scored sections. |
Functions
| Name | Description |
|---|---|
generate_report | Build a report from a source object. |
Modules
DEFAULT_TIMEOUTattributemodule attribute#
DEFAULT_TIMEOUT: float = 30.0Seconds to wait for report generation before giving up.
Used as the default for Report.generate.
Reportclass#
demopkg.reportclass Report(name: str, scores: dict[str, float] | None = None)Bases: BaseReport
A named collection of scored sections.
Parameters
Attributes
nameattributeinstance attribute#
name = nameThe report name.
scoresattributeinstance attribute#
scores: dict[str, float] = scores or {}Mapping of metric name to score.
from_mappingmethodclassmethod#
def from_mapping(data: Mapping[str, float], *, name: str = 'report') -> ReportBuild a report from an existing mapping of scores.
Parameters
Returns
Report- A new report holding a copy of
data.
generatemethod#
def generate(*sections: str, title: str | None = None, timeout: float = DEFAULT_TIMEOUT, **options: Any) -> pathlib.PathRender the report and return the path it was written to.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
*sections | str | () | Section names to include, in order. When empty every known section is rendered. |
title | str | None | None | Overrides the report title. Defaults to the report name. |
timeout | float | DEFAULT_TIMEOUT | Seconds to wait before giving up. |
**options | Any | {} | Extra renderer options, passed through untouched. |
Returns
pathlib.Path- The path of the file that was written.
Raises
ReportError- If a requested section does not exist.
TimeoutError- If rendering takes longer than
timeout.
Examples
>>> Report("weekly").generate("summary", title="Weekly")PosixPath('weekly.txt')rendermethod#
def render(value: str | list[str]) -> str | list[str]Render one section or a list of sections.
supported_formatsmethodstaticmethod#
def supported_formats() -> tuple[str, ...]List the formats a report can be saved as.
Inherited from demopkg.report.BaseReport
formatattributeclass attributeinstance attribute#
demopkg.report.BaseReportformat: str = 'txt'Default output format, as a bare file extension.
is_validproperty#
demopkg.report.BaseReportis_valid: boolWhether validate passes.
savemethod#
demopkg.report.BaseReportdef save(path: pathlib.Path) -> NoneWrite the rendered report to path.
Parameters
| Name | Type | Description |
|---|---|---|
path | pathlib.Path | Destination file. Parent directories must exist. |
Raises
OSError- If the file cannot be written.
validatemethod#
demopkg.report.BaseReportdef validate() -> boolCheck the report for structural problems.
Returns
bool- True when the report is well formed.
generate_reportfunction#
demopkg.reportdef generate_report(source, /, name: str, *, fmt: str = 'md') -> ReportBuild a report from a source object.
Exercises a positional-only parameter (source, before the /) and a
keyword-only one (fmt, after the *).
Returns a Report whose generate method writes a pathlib.Path. A reference nothing resolves, such as [nosuchpkg.Thing][], is left exactly as it was written.
Parameters
Returns
Report- A populated report.
Raises
ReportError- If
sourcecannot be read.