From 05e92d85fda1060e361d2d85f81551d1dc0df0d2 Mon Sep 17 00:00:00 2001 From: Frederick Mannings Date: Sat, 3 Jan 2026 16:03:24 +0000 Subject: [PATCH] removed need for registry --- orca_python/main.py | 6 -- orca_python/registry/__init__.py | 0 orca_python/registry/algorithms.py | 77 ----------------- orca_python/registry/metadata_fields.py | 79 ----------------- orca_python/registry/window_types.py | 109 ------------------------ 5 files changed, 271 deletions(-) delete mode 100644 orca_python/registry/__init__.py delete mode 100644 orca_python/registry/algorithms.py delete mode 100644 orca_python/registry/metadata_fields.py delete mode 100644 orca_python/registry/window_types.py diff --git a/orca_python/main.py b/orca_python/main.py index 61f265d..c429af2 100644 --- a/orca_python/main.py +++ b/orca_python/main.py @@ -35,7 +35,6 @@ Optional, Protocol, Generator, - TypedDict, AsyncGenerator, ) from inspect import signature @@ -69,11 +68,6 @@ LOGGER = logging.getLogger(__name__) -class StubInfo(TypedDict): - annotations: Dict[str, Any] - metadata: Dict[str, Any] - - @dataclass(frozen=True) class MetadataField: name: str diff --git a/orca_python/registry/__init__.py b/orca_python/registry/__init__.py deleted file mode 100644 index e69de29..0000000 diff --git a/orca_python/registry/algorithms.py b/orca_python/registry/algorithms.py deleted file mode 100644 index e2f2744..0000000 --- a/orca_python/registry/algorithms.py +++ /dev/null @@ -1,77 +0,0 @@ -import re -import ast -import json -from pathlib import Path - -from orca_python.main import StubInfo - - -class StubAlgorithm: - __orca_is_remote__ = True - - def __init__(self, func_name: str, stub_info: StubInfo): - self.__name__ = func_name - self.__annotations__ = stub_info["annotations"] - self.__orca_metadata__ = stub_info["metadata"] - - def __call__(self, *args, **kwargs) -> None: - _, _ = args, kwargs - raise NotImplementedError( - f"{self.__name__} is only available as a remote algorithm. " - f"Metadata: {self.__orca_metadata__}" - ) - - -def _load_stub_metadata(func_name: str) -> StubInfo: - """Load annotations and metadata from the .pyi stub file.""" - stub_file = Path.cwd() / ".orca" / "orca_python" / "registry" / "algorithms.pyi" - - if not stub_file.exists(): - return StubInfo(annotations={}, metadata={}) - - try: - content = stub_file.read_text() - tree = ast.parse(content) - - result: StubInfo = {"annotations": {}, "metadata": {}} - - # get the function node - for node in ast.walk(tree): - if isinstance(node, ast.FunctionDef) and node.name == func_name: - # get annotations - annotations = {} - for arg in node.args.args: - if arg.annotation: - annotations[arg.arg] = ast.unparse(arg.annotation) - if node.returns: - annotations["return"] = ast.unparse(node.returns) - result["annotations"] = annotations - - # get metadata from comment above function - # find the line number and look for comment above it - lines = content.split("\n") - func_line = node.lineno - 1 # 0-indexed - - # look at previous lines for metadata comment - for i in range(func_line - 1, max(0, func_line - 5), -1): - line = lines[i].strip() - if match := re.search(r"#\s*METADATA:\s*(\{.*\})", line): - result["metadata"] = json.loads(match.group(1)) - break - - break - - return result - except Exception as e: - print(f"Error parsing stub: {e}") - - return StubInfo(annotations={}, metadata={}) - - -def __getattr__(name: str) -> StubAlgorithm: - if name.startswith("_"): - raise AttributeError(f"module '{__name__}' has no attribute '{name}'") - - stub_info = _load_stub_metadata(name) - - return StubAlgorithm(name, stub_info) diff --git a/orca_python/registry/metadata_fields.py b/orca_python/registry/metadata_fields.py deleted file mode 100644 index 8b1d1e9..0000000 --- a/orca_python/registry/metadata_fields.py +++ /dev/null @@ -1,79 +0,0 @@ -import re -import ast -import json -from pathlib import Path - -from orca_python.main import StubInfo -from orca_python.exceptions import BrokenRemoteAlgorithmStubs - - -class StubMetadataField: - __orca_is_remote__ = True - name: str - description: str - - def __init__(self, field_name: str, stub_info: StubInfo): - self.__name__ = field_name - self.__annotations__ = stub_info["annotations"] - self.__orca_metadata__ = stub_info["metadata"] - name = stub_info["metadata"].get("Name", None) - description = stub_info["metadata"].get("Description", None) - if name is None or description is None: - raise BrokenRemoteAlgorithmStubs( - "Stubs appear broken. Regenerate with `orca sync`." - ) - self.name = name - self.description = description - - -def _load_stub_metadata(obj_name: str) -> StubInfo: - """Load annotations and metadata from the .pyi stub file.""" - stub_file = ( - Path.cwd() / ".orca" / "orca_python" / "registry" / "metadata_fields.pyi" - ) - - if not stub_file.exists(): - return {"annotations": {}, "metadata": {}} - - try: - content = stub_file.read_text() - tree = ast.parse(content) - - result: StubInfo = {"annotations": {}, "metadata": {}} - - # get the annotated assignment node (e.g., asset_id: MetadataField) - for node in ast.walk(tree): - if isinstance(node, ast.AnnAssign): - # check if this is the target we're looking for - if isinstance(node.target, ast.Name) and node.target.id == obj_name: - # get annotation - if node.annotation: - result["annotations"]["type"] = ast.unparse(node.annotation) - - # get metadata from comment above assignment - lines = content.split("\n") - assign_line = node.lineno - 1 # 0-indexed - - # look at previous lines for metadata comment - for i in range(assign_line - 1, max(0, assign_line - 5), -1): - line = lines[i].strip() - if match := re.search(r"#\s*METADATA:\s*(\{.*\})", line): - result["metadata"] = json.loads(match.group(1)) - break - - break - - return result - except Exception as e: - print(f"Error parsing stub: {e}") - - return StubInfo(annotations={}, metadata={}) - - -def __getattr__(name: str) -> StubMetadataField: - if name.startswith("_"): - raise AttributeError(f"module '{__name__}' has no attribute '{name}'") - - stub_info = _load_stub_metadata(name) - - return StubMetadataField(name, stub_info) diff --git a/orca_python/registry/window_types.py b/orca_python/registry/window_types.py deleted file mode 100644 index 246cd6d..0000000 --- a/orca_python/registry/window_types.py +++ /dev/null @@ -1,109 +0,0 @@ -import re -import ast -import json -from typing import List -from pathlib import Path -from dataclasses import dataclass - -from orca_python.main import StubInfo, BrokenRemoteAlgorithmStubs - - -def _load_stub_metadata(obj_name: str) -> StubInfo: - """Load annotations and metadata from the .pyi stub file.""" - stub_file = Path.cwd() / ".orca" / "orca_python" / "registry" / "window_types.pyi" - - if not stub_file.exists(): - return StubInfo(annotations={}, metadata={}) - - try: - content = stub_file.read_text() - tree = ast.parse(content) - - result: StubInfo = {"annotations": {}, "metadata": {}} - - # get the annotated assignment node - for node in ast.walk(tree): - if isinstance(node, ast.AnnAssign): - # check if this is the target we're looking for - if isinstance(node.target, ast.Name) and node.target.id == obj_name: - # get annotation - if node.annotation: - result["annotations"]["type"] = ast.unparse(node.annotation) - - # get metadata from comment above assignment - lines = content.split("\n") - assign_line = node.lineno - 1 # 0-indexed - - # look at previous lines for metadata comment - for i in range(assign_line - 1, max(0, assign_line - 5), -1): - line = lines[i].strip() - if match := re.search(r"#\s*METADATA:\s*(\{.*\})", line): - result["metadata"] = json.loads(match.group(1)) - break - - break - - return result - except Exception as e: - print(f"Error parsing stub: {e}") - - return StubInfo(annotations={}, metadata={}) - - -def __getattr__(name): - if name.startswith("_"): - raise AttributeError(f"module '{__name__}' has no attribute '{name}'") - - stub_info = _load_stub_metadata(name) - - @dataclass - class StubMetadataField: - __orca_is_remote__ = True - name: str - description: str - - class StubWindowType: - __orca_is_remote__ = True - name: str - version: str - description: str - metadataFields: List[StubMetadataField] - - def __init__(self, window_name: str): - self.__annotations__ = stub_info["annotations"] - self.__orca_metadata__ = stub_info["metadata"] - - # assign the values that the main package expects from a window - name = stub_info["metadata"].get("Name", None) - version = stub_info["metadata"].get("Version", None) - description = stub_info["metadata"].get("Description", None) - metadataFields = stub_info["metadata"].get("MetadataFields", None) - - if ( - name is None - or version is None - or description is None - or metadataFields is None - ): - raise BrokenRemoteAlgorithmStubs( - "Stubs appear broken. Regenerate them with `orca sync`." - ) - - self.name = name - self.version = version - self.description = description - try: - self.metadataFields = [ - StubMetadataField( - name=v.get("Name"), description=v.get("Description") - ) - for v in metadataFields - ] - except Exception as e: - raise BrokenRemoteAlgorithmStubs( - f"Stubs appear broken: {e}. Regenerate with `orca sync`" - ) - - self.__name__ = window_name - - return StubWindowType(name)