diff --git a/src/codegen/configs/models/codebase.py b/src/codegen/configs/models/codebase.py index 88643cfcd..b8484e63b 100644 --- a/src/codegen/configs/models/codebase.py +++ b/src/codegen/configs/models/codebase.py @@ -16,6 +16,7 @@ def __init__(self, prefix: str = "CODEBASE", *args, **kwargs) -> None: ignore_process_errors: bool = True disable_graph: bool = False disable_file_parse: bool = False + exp_lazy_graph: bool = False generics: bool = True import_resolution_paths: list[str] = Field(default_factory=lambda: []) import_resolution_overrides: dict[str, str] = Field(default_factory=lambda: {}) diff --git a/src/codegen/sdk/codebase/codebase_context.py b/src/codegen/sdk/codebase/codebase_context.py index 3894a87fa..1d4eb2fda 100644 --- a/src/codegen/sdk/codebase/codebase_context.py +++ b/src/codegen/sdk/codebase/codebase_context.py @@ -144,7 +144,8 @@ def __init__( from codegen.sdk.core.parser import Parser self.progress = progress or StubProgress() - self._graph = PyDiGraph() + self.__graph = PyDiGraph() + self.__graph_ready = False self.filepath_idx = {} self._ext_module_idx = {} self.generation = 0 @@ -189,7 +190,8 @@ def __init__( logger.warning("Some features may not work as expected. Advanced static analysis will be disabled but simple file IO will still work.") # Build the graph - self.build_graph(context.repo_operator) + if not self.config.exp_lazy_graph: + self.build_graph(context.repo_operator) try: self.synced_commit = context.repo_operator.head_commit except ValueError as e: @@ -203,10 +205,22 @@ def __init__( def __repr__(self): return self.__class__.__name__ + @property + def _graph(self) -> PyDiGraph[Importable, Edge]: + if not self.__graph_ready: + logger.info("Lazily Computing Graph") + self.build_graph(self.projects[0].repo_operator) + return self.__graph + + @_graph.setter + def _graph(self, value: PyDiGraph[Importable, Edge]) -> None: + self.__graph = value + @stopwatch_with_sentry(name="build_graph") @commiter def build_graph(self, repo_operator: RepoOperator) -> None: """Builds a codebase graph based on the current file state of the given repo operator""" + self.__graph_ready = True self._graph.clear() # =====[ Add all files to the graph in parallel ]=====