diff --git a/changelog.d/ITL-1479.md b/changelog.d/ITL-1479.md new file mode 100644 index 000000000..a2ea86834 --- /dev/null +++ b/changelog.d/ITL-1479.md @@ -0,0 +1,9 @@ +### Added + +- Expanded the API reference to cover public exports, added an Errors page, and + documented the `orcapod warm-cache` command. (ITL-1479) + +### Changed + +- `from orcapod.types import *` now imports only the documented names. Import + anything else by name. (ITL-1479) diff --git a/docs/api/databases.md b/docs/api/databases.md index 4387b75c1..0c12ead5a 100644 --- a/docs/api/databases.md +++ b/docs/api/databases.md @@ -6,10 +6,24 @@ introduction. Every signature and docstring on the published page comes from the code. See site/README.md. --> -Database backends for persistent storage of pipeline computation results. +Database backends store pipeline results. The SQLite and PostgreSQL connectors support +reads and writes through `ConnectorArrowDatabase`. The SpiralDB connector is read-only. + +**Provisional.** `ExtensionAwareDatabase` is expected to be integrated more closely with +the underlying database classes (ITL-1539), so its public form may change. ::: orcapod.databases.DeltaTableDatabase ::: orcapod.databases.InMemoryArrowDatabase ::: orcapod.databases.NoOpArrowDatabase + +::: orcapod.databases.ConnectorArrowDatabase + +::: orcapod.databases.ExtensionAwareDatabase + +::: orcapod.databases.SQLiteConnector + +::: orcapod.databases.PostgreSQLConnector + +::: orcapod.databases.SpiralDBConnector diff --git a/docs/api/errors.md b/docs/api/errors.md new file mode 100644 index 000000000..36ef484ee --- /dev/null +++ b/docs/api/errors.md @@ -0,0 +1,133 @@ +# Errors + +Exceptions and warnings defined in `orcapod.errors`. + +## Input, schema, and value validation + +These exceptions and warnings report invalid inputs, schemas, or values. + +::: orcapod.errors.InputValidationError + +::: orcapod.errors.DuplicateTagError + +::: orcapod.errors.SchemaInconsistencyError + +::: orcapod.errors.TypeIdentityError + +::: orcapod.errors.RecursiveTypeError + +::: orcapod.errors.CanonicalOrderError + +::: orcapod.errors.UnsupportedValueError + +::: orcapod.errors.ValueConversionWarning + +::: orcapod.errors.UnstorableDatetimeError + +::: orcapod.errors.NaiveDatetimeError + +::: orcapod.errors.SubMicrosecondDatetimeError + +::: orcapod.errors.InstantOutOfRangeError + +::: orcapod.errors.NotADatetimeError + +::: orcapod.errors.NullInNonNullableColumnError + +## Sources + +These exceptions and warnings report problems identifying, binding, or reading sources. + +::: orcapod.errors.RowIdentifierError + +::: orcapod.errors.SourceTooLargeError + +::: orcapod.errors.UnboundSourceError + +::: orcapod.errors.SourceSpecMismatchError + +::: orcapod.errors.InconsistentSourceError + +::: orcapod.errors.CursorInvalidatedError + +::: orcapod.errors.SourceCheckFailedWarning + +::: orcapod.errors.SourceNameWarning + +::: orcapod.errors.SourceVersionWarning + +::: orcapod.errors.CachedSourceIdMismatchError + +::: orcapod.errors.SourceSlotNameCollisionError + +## Pipeline execution + +These exceptions and warnings report problems running pipelines, processing rows, or tracing results. + +::: orcapod.errors.PipelineJobRequiredError + +::: orcapod.errors.DataFunctionUnavailableError + +::: orcapod.errors.OutputTypeError + +::: orcapod.errors.NoOutputsDeclaredError + +::: orcapod.errors.RowFailuresWarning + +::: orcapod.errors.RestrictedAggregationWarning + +::: orcapod.errors.SemiJoinIgnoredColumnWarning + +::: orcapod.errors.RejoinDifferingColumnWarning + +::: orcapod.errors.UpstreamFailedError + +::: orcapod.errors.EmptyDataAccessError + +::: orcapod.errors.EmptyDataHashMissingError + +::: orcapod.errors.EphemeralResultMissingError + +::: orcapod.errors.ProvenanceInconsistencyError + +## Databases and connectors + +These exceptions and warnings report storage, schema, and connector problems. + +::: orcapod.errors.OrcapodDatabaseError + +::: orcapod.errors.OrcapodDatabaseReadError + +::: orcapod.errors.OrcapodDatabaseWriteError + +::: orcapod.errors.StoredTableSchemaError + +::: orcapod.errors.SideEffectLogDataContextError + +::: orcapod.errors.OrcapodDatabaseContentWarning + +::: orcapod.errors.UnstorableColumnError + +::: orcapod.errors.UnstorableTableNameError + +::: orcapod.errors.TableSchemaError + +::: orcapod.errors.TableListingNotSupportedError + +::: orcapod.errors.UnrecordedTableSchemaWarning + +::: orcapod.errors.NullabilityRecordMismatchError + +::: orcapod.errors.SpiralDBWriteNotSupportedError + +::: orcapod.errors.SpiralDBSignInError + +## Feature availability and stability + +These exceptions and warnings report optional dependencies and features still in development. + +::: orcapod.errors.MissingOptionalDependencyError + +::: orcapod.errors.ProvisionalHashWarning + +::: orcapod.errors.InDevelopmentWarning diff --git a/docs/api/function-pods.md b/docs/api/function-pods.md index 6931a095b..cde0c0485 100644 --- a/docs/api/function-pods.md +++ b/docs/api/function-pods.md @@ -14,14 +14,38 @@ Function pods wrap Python functions to transform individual data in a stream. ::: orcapod.side_effects.SideEffectPod +::: orcapod.SideEffectPodConfig + ::: orcapod.side_effects.side_effect_pod ::: orcapod.side_effects.sink_pod ::: orcapod.side_effects.tap_pod +::: orcapod.side_effect_function_pod + +::: orcapod.InvocationContext + +::: orcapod.InvocationHashConfig + ::: orcapod.core.data_function.PythonDataFunction ::: orcapod.core.data_function.CachedDataFunction ::: orcapod.core.data_function.DataFunctionBase + +## Post-run hooks + +::: orcapod.HookConfig + +::: orcapod.InvocationStatus + +::: orcapod.PodContext + +::: orcapod.PostRunHook + +::: orcapod.PostRunHookFn + +::: orcapod.PostRunPayload + +::: orcapod.RunStats diff --git a/docs/api/index.md b/docs/api/index.md index c76985a60..206afe787 100644 --- a/docs/api/index.md +++ b/docs/api/index.md @@ -16,7 +16,8 @@ directly: | [`PipelineJob`](pipeline.md) | A pipeline bound to sources and a database; the object you run | | [`side_effect_pod`, `sink_pod`, `tap_pod`](function-pods.md) | Decorators for functions run for their side effects | -Everything else lives in subpackages: +The table lists the public modules alongside the top-level `orcapod` namespace. +Other modules support Orcapod internally or are covered in the concept pages. | Subpackage | Description | |------------|-------------| @@ -25,4 +26,8 @@ Everything else lives in subpackages: | [`orcapod.databases`](databases.md) | Persistent storage backends for computation results | | [`orcapod.nodes`](nodes.md) | Pipeline graph elements, including the DB-backed job nodes | | [`orcapod.streams`](streams.md) | Immutable (Tag, Data) sequences backed by PyArrow tables | +| [`orcapod.pipeline`](pipeline.md) | Pipelines, jobs, orchestrators, observers, and run summaries | | [`orcapod.types`](types.md) | Core type definitions: `Schema`, `ColumnConfig`, `ContentHash`, `Condition`, `col`, `Explanation`, `Trace`, `Absence`, `Highlight` | +| [`orcapod.errors`](errors.md) | Orcapod exceptions and warnings | + +See the [command-line reference](../reference/cli.md) for `orcapod warm-cache`. diff --git a/docs/api/operators.md b/docs/api/operators.md index 8da38f324..eb3795836 100644 --- a/docs/api/operators.md +++ b/docs/api/operators.md @@ -47,3 +47,7 @@ Operators perform structural transformations on streams without inspecting or sy ::: orcapod.core.operators.Pick ::: orcapod.core.operators.Index + +::: orcapod.operators.DropNulls + +::: orcapod.operators.TagBy diff --git a/docs/api/pipeline.md b/docs/api/pipeline.md index b80da182d..4bc0d429e 100644 --- a/docs/api/pipeline.md +++ b/docs/api/pipeline.md @@ -14,3 +14,21 @@ blueprint; `PipelineJob` binds a pipeline to sources and a database and runs it. ::: orcapod.pipeline.PipelineJob ::: orcapod.pipeline.PipelineDiagram + +::: orcapod.pipeline.LoadStatus + +::: orcapod.pipeline.RunSummary + +::: orcapod.pipeline.NodeRunSummary + +::: orcapod.pipeline.SyncPipelineOrchestrator + +::: orcapod.pipeline.AsyncPipelineOrchestrator + +::: orcapod.pipeline.CompositeObserver + +::: orcapod.pipeline.LoggingObserver + +::: orcapod.pipeline.StatusObserver + +::: orcapod.pipeline.DataLogger diff --git a/docs/api/sources.md b/docs/api/sources.md index 67efeeb0a..1f03bea82 100644 --- a/docs/api/sources.md +++ b/docs/api/sources.md @@ -27,6 +27,10 @@ source id and hashes are not frozen with data context v1 (`PROVISIONAL_SOURCES`) ::: orcapod.core.sources.PostgreSQLTableSource +::: orcapod.sources.SpiralDBTableSource + +::: orcapod.sources.DBTableSource + ::: orcapod.core.sources.PollingSource ::: orcapod.core.sources.DerivedSource diff --git a/docs/api/streams.md b/docs/api/streams.md index 446229075..d7b09e652 100644 --- a/docs/api/streams.md +++ b/docs/api/streams.md @@ -11,3 +11,7 @@ Streams are immutable sequences of (Tag, Data) pairs backed by PyArrow tables. ::: orcapod.core.streams.ArrowTableStream ::: orcapod.core.streams.StreamBase + +::: orcapod.streams.StreamView + +::: orcapod.streams.ViewStatus diff --git a/docs/api/types.md b/docs/api/types.md index 2403cc7df..afab565c4 100644 --- a/docs/api/types.md +++ b/docs/api/types.md @@ -37,3 +37,69 @@ Core type definitions used throughout Orcapod. ::: orcapod.types.Absence ::: orcapod.types.Highlight + +## Data and schema types + +::: orcapod.types.DataType + +::: orcapod.types.DataValue + +::: orcapod.types.DataLike + +::: orcapod.types.SchemaLike + +::: orcapod.types.TagValue + +::: orcapod.types.SourceInfoValue + +::: orcapod.types.PathLike + +::: orcapod.types.PathSet + +::: orcapod.types.ColumnInfo + +## Polling sources + +::: orcapod.types.Cursor + +::: orcapod.types.PollingConfig + +## Pipeline execution + +::: orcapod.types.OrchestratorType + +::: orcapod.types.PipelineConfig + +::: orcapod.types.PodConfig + +::: orcapod.types.NodeConfig + +::: orcapod.types.CacheMode + +## Files and directories + +::: orcapod.File + +::: orcapod.Directory + +::: orcapod.enable_file_hash_caching + +## Custom types and extensions + +::: orcapod.dataclass + +::: orcapod.OrcapodExtension + +::: orcapod.register_extension + +## Configuration + +::: orcapod.OrcapodConfig + +::: orcapod.DisplayConfig + +::: orcapod.HashingConfig + +::: orcapod.DEFAULT_CONFIG + +::: orcapod.load_config diff --git a/docs/reference/cli.md b/docs/reference/cli.md new file mode 100644 index 000000000..8eaef676f --- /dev/null +++ b/docs/reference/cli.md @@ -0,0 +1,35 @@ +# Command-line reference + +## `orcapod warm-cache` + +Run `orcapod warm-cache PATH` to fill the SQLite file-hash cache before a pipeline run. +The command scans the directory at `PATH` recursively, skips symbolic links, and +hashes files that meet the minimum size and lack a cache entry. It reports how many files +it hashed, found in the cache, skipped by size, or could not process. + +| Option | Meaning | +| --- | --- | +| `--min-size MB` | Minimum file size, in units of 1,048,576 bytes. Defaults to `500`. | +| `--db-path PATH` | Local SQLite cache path. Defaults to `ORCAPOD_HASH_CACHE_DB` if set, or `~/.orcapod/file_hash_cache.db`. | +| `--algorithm NAME` | Content hash algorithm. Defaults to `sha256`. | +| `--buffer-size BYTES` | Read buffer size in bytes. Defaults to `65536`. | +| `--workers COUNT` | Number of hashing threads. Defaults to `4`, with a minimum of `1`. | +| `--dry-run` | Count files that would be hashed. The scan runs serially and writes no hash entries. Opening the database can initialize a new cache file. | +| `--force` | Hash eligible files again, even when they already have a cache entry. With `--dry-run`, include those files in the count. | + +!!! warning "Use one hash algorithm per cache" + The cache keys entries by path, modification time, and size. A matching entry + can return a digest from a different algorithm (ITL-1488). Use the same + algorithm in `warm-cache` and in every pipeline that uses that cache. The + default file hasher uses `sha256`. When changing algorithms, clear the + cache before using it again or use a new cache file. + +To preview and then warm the same cache, run: + +```sh +orcapod warm-cache ./recordings --min-size 100 --dry-run +orcapod warm-cache ./recordings --min-size 100 +``` + +Enable [file hash caching](../concepts/file-hash-caching.md) in your Python process +before the pipeline hashes files. Use the same SQLite cache path as the command. diff --git a/site/astro.config.mjs b/site/astro.config.mjs index 56075569e..e2a9c7215 100644 --- a/site/astro.config.mjs +++ b/site/astro.config.mjs @@ -189,6 +189,7 @@ export default defineConfig({ page('Nodes', 'api/nodes'), page('Pipeline', 'api/pipeline'), page('Types', 'api/types'), + page('Errors', 'api/errors'), ], }, { @@ -198,6 +199,7 @@ export default defineConfig({ page('Golden hashes', 'reference/golden-hashes'), page('Data function types', 'reference/data-function-types'), page('Data types per database', 'reference/database-types'), + page('Command-line reference', 'reference/cli'), ], }, page('Troubleshooting', 'troubleshooting'), diff --git a/src/orcapod/databases/extension_aware_database.py b/src/orcapod/databases/extension_aware_database.py index 546cf8595..bbb891f2e 100644 --- a/src/orcapod/databases/extension_aware_database.py +++ b/src/orcapod/databases/extension_aware_database.py @@ -39,6 +39,9 @@ class ExtensionAwareDatabase: """``ArrowDatabaseProtocol`` wrapper that auto-registers and applies extension types. + **Provisional.** This wrapper is expected to be integrated more closely with the + underlying database classes (ITL-1539), so its public form may change. + All read methods delegate to the wrapped *db*, then: 1. Walk the returned table's schema to find any extension types (from diff --git a/src/orcapod/types/__init__.py b/src/orcapod/types/__init__.py index c3061039e..82d020b24 100644 --- a/src/orcapod/types/__init__.py +++ b/src/orcapod/types/__init__.py @@ -52,6 +52,40 @@ if TYPE_CHECKING: from orcapod.protocols.core_protocols import DataFunctionExecutorProtocol +__all__ = [ + "Absence", + "CacheMode", + "ColumnConfig", + "ColumnInfo", + "ColumnRef", + "Condition", + "ContentHash", + "Cursor", + "DataLike", + "DataType", + "DataValue", + "Explanation", + "FunctionRun", + "Highlight", + "NodeConfig", + "OrchestratorType", + "PathLike", + "PathSet", + "PipelineConfig", + "PodConfig", + "PollingConfig", + "Schema", + "SchemaLike", + "SourceCell", + "SourceInfoValue", + "SourceReading", + "Step", + "TagValue", + "Trace", + "TraceStep", + "col", +] + logger = logging.getLogger(__name__) # TODO: revisit and consider a way to incorporate older Union type diff --git a/tests/test_docs/test_api_reference.py b/tests/test_docs/test_api_reference.py new file mode 100644 index 000000000..fbb340f9f --- /dev/null +++ b/tests/test_docs/test_api_reference.py @@ -0,0 +1,142 @@ +"""Keep the public export lists and generated API reference in sync.""" + +from __future__ import annotations + +import re +from collections.abc import Sequence +from importlib import import_module +from pathlib import Path +from typing import cast + +import griffe +from griffe import Alias, Module, Object + +REPO_ROOT = Path(__file__).resolve().parents[2] +PUBLIC_MODULES = ( + "orcapod", + "orcapod.databases", + "orcapod.errors", + "orcapod.nodes", + "orcapod.operators", + "orcapod.pipeline", + "orcapod.sources", + "orcapod.streams", + "orcapod.types", +) + +# These namespaces are outside the public reference. The reasons also apply +# to their nested modules. +EXCLUDED_NAMESPACES = { + "orcapod._version": "Generated build metadata.", + "orcapod.contexts": "Public API documented in concept pages. A dedicated reference page will follow separately.", + "orcapod.core": "Implementation modules behind the public re-exports.", + "orcapod.extensions": "Implementation namespace for the top-level extension API.", + "orcapod.hashing": "Hashing internals and dedicated hashing documentation.", + "orcapod.logical_types": "Logical type internals and concept documentation.", + "orcapod.pipeline.dag": "Internal graph interfaces and implementations.", + "orcapod.pipeline.diagram": "Implementation module for the public PipelineDiagram.", + "orcapod.pipeline.networkx_backend": "Internal graph backend.", + "orcapod.protocols": "Internal interfaces between Orcapod components.", + "orcapod.semantic_types": "Internal semantic type conversion and inference.", + "orcapod.structural": "Implementation namespace for the top-level dataclass decorator.", +} + +EXCLUDED_EXPORTS = { + "orcapod.__version__": "Version metadata supplied by the package build.", + "orcapod.Path": "Stable alias of pathlib.Path, documented by Python.", + "orcapod.UPath": "Stable alias of upath.UPath, documented by universal-pathlib.", + "orcapod.UUID": "Stable alias of uuid.UUID, documented by Python.", + "orcapod.databases": "Package link in the API overview.", + "orcapod.nodes": "Package link in the API overview.", + "orcapod.operators": "Package link in the API overview.", + "orcapod.sources": "Package link in the API overview.", + "orcapod.streams": "Package link in the API overview.", + "orcapod.types": "Package link in the API overview.", + "orcapod.nodes.FunctionNodeBase": "Internal base shared by function node implementations.", + "orcapod.nodes.GraphNode": "Internal base for nodes in a pipeline graph.", + "orcapod.nodes.JobNode": "Internal base for nodes bound to a job.", + "orcapod.nodes.OperatorNodeBase": "Internal base shared by operator node implementations.", + "orcapod.nodes.SourceNodeBase": "Internal base shared by source node implementations.", + "orcapod.operators.PROVISIONAL_OPERATORS": "Bookkeeping for provisional operator hashes.", + "orcapod.pipeline.ExecutionContext": "Placeholder for pipeline execution configuration.", + "orcapod.pipeline.GraphProtocol": "Internal graph backend interface.", + "orcapod.pipeline.OrcaDAG": "Internal representation of a pipeline graph.", + "orcapod.pipeline.PIPELINE_FORMAT_VERSION": "Serialization metadata for pipeline blueprints.", + "orcapod.pipeline.PIPELINE_JOB_FORMAT_VERSION": "Serialization metadata for pipeline jobs.", + "orcapod.sources.GLOBAL_SOURCE_REGISTRY": "Shared process-wide source registry instance.", + "orcapod.sources.PROVISIONAL_SOURCES": "Bookkeeping for provisional source hashes.", +} + + +def test_public_exports_have_api_reference_entries() -> None: + package = griffe.load( + "orcapod", + search_paths=[str(REPO_ROOT / "src")], + resolve_aliases=True, + resolve_external=False, + ) + modules = [package] + unclassified: list[str] = [] + for source_module in modules: + modules.extend( + child + for child in source_module.members.values() + if isinstance(child, Module) + ) + if source_module.exports and source_module.path not in PUBLIC_MODULES: + if not any( + source_module.path == namespace + or source_module.path.startswith(namespace + ".") + for namespace in EXCLUDED_NAMESPACES + ): + unclassified.append(source_module.path) + + def reference_key(path: str) -> tuple[str, str]: + # Preserve the exported spelling while counting existing entries for + # the same object through an alias (e.g. orcapod.core.operators.Join). + obj = cast("Object | Alias", package[path.removeprefix("orcapod.")]) + target = obj.final_target if isinstance(obj, Alias) else obj + return path.rsplit(".", 1)[-1], target.path + + entries = { + reference_key(directive.group(1)) + for page in (REPO_ROOT / "docs" / "api").glob("*.md") + for directive in re.finditer( + r"^::: +([\w.]+) *$", page.read_text(encoding="utf-8"), re.M + ) + } + exports: set[str] = set() + for module_name in PUBLIC_MODULES: + module = import_module(module_name) + members = cast("dict[str, object]", vars(module)) + if module_name != "orcapod.errors": + assert "__all__" in members, ( + f"{module_name} must declare its public exports" + ) + names = cast("Sequence[str]", members.get("__all__", ())) + exports.update(f"{module_name}.{name}" for name in names) + if module_name == "orcapod.errors": + # The errors module has no __all__. Its own exception and warning + # classes are the public entries for this page. + exports.update( + f"{module_name}.{name}" + for name, value in members.items() + if isinstance(value, type) + and value.__module__ == module_name + and issubclass(value, Exception) + and not name.startswith("_") + ) + + assert all(EXCLUDED_NAMESPACES.values()) and all(EXCLUDED_EXPORTS.values()) + assert not unclassified, f"Classify namespaces with __all__: {sorted(unclassified)}" + assert not (stale := EXCLUDED_EXPORTS.keys() - exports), ( + f"Remove stale API exclusions: {sorted(stale)}" + ) + missing = sorted( + path + for path in exports - EXCLUDED_EXPORTS.keys() + if reference_key(path) not in entries + ) + assert not missing, ( + "Add API reference entries or reasoned exclusions for:\n" + "\n".join(missing) + )