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
¶
JsonSpecSource
dataclass
¶
SpecSourceResolver
¶
Resolve explicit or conventional project specification sources.
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 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
|
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.
expose
¶
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. |