Skip to content

Project

The project API resolves conventional project paths and Spec sources without loading build or runtime configuration.

Spec sources

Use SpecSourceResolver.resolve to select a source, then load_spec_source to load it.

Resolve and load specification sources for an Uptimely project.

PythonSpecSource dataclass

Describe a resolved Python spec source.

path instance-attribute

path: Path | None

entrypoint instance-attribute

entrypoint: Entrypoint

display_name property

display_name: str

Return a path for conventional sources or the explicit entrypoint.

JsonSpecSource dataclass

Describe a resolved JSON spec source.

path instance-attribute

path: Path

display_name property

display_name: str

Return the resolved JSON source path.

SpecSourceResolver

Resolve explicit or conventional project specification sources.

project_root instance-attribute

project_root = project_root.resolve()

resolve

resolve(python_spec: str | None = None, json_spec: JsonSourceInput = None, yaml_spec: YamlSourceInput = None) -> ResolvedSpecSource

Select one explicit or discovered source without loading it.

load_spec_source

load_spec_source(source: ResolvedSpecSource, *, validate: bool = True, dataframe_classes: DataFrameClasses | None = None) -> spec.Spec

Load and convert a resolved specification source.

Python imports

Set up temporary Python imports using an Uptimely project's layout.

expose

expose(root: Path, src_path: Path | None = None) -> typing.ContextManager[None]

Expose an Uptimely project's Python modules within a context.

The project root and spec directory can be imported. The source directory defaults to src under the project root. It can be changed to an absolute path or a path relative to the project root.

Parameters:

Name Type Description Default
root Path

Uptimely project root.

required
src_path Path | None

Explicit Python source directory, or None for src.

None

Returns:

Type Description
ContextManager[None]

A context manager that makes the project's Python modules available

ContextManager[None]

while keeping existing imports safe.

Raises:

Type Description
NotADirectoryError

An explicit source directory does not exist.

Temporarily make Python modules importable and restore the previous state.

PythonModuleImportManager

Make Python modules under a source root importable for a short time.

The scope adds the root, parent package root, and source directory to sys.path. It removes modules that could conflict with project modules. When the scope ends, it removes newly imported modules and puts the old modules and sys.path back.

root instance-attribute

root = root.resolve()

source instance-attribute

source = source.resolve()

module_roots instance-attribute

module_roots = tuple(path.resolve() for path in module_roots)

reserved_modules instance-attribute

reserved_modules = frozenset(reserved_modules)

expose

expose() -> typing.Iterator[None]

Make the configured modules importable, then restore the previous state.

Nested scopes for the same root and source directory reuse the current scope. Changes use a lock because sys.path and sys.modules are shared by the whole Python process.

Yields:

Type Description
None

Control to code that may import from the configured Python roots.