Skip to content

Commit 1a085d2

Browse files
authored
Rename CodebaseGraph to CodebaseContext (#405)
`CodebaseGraph` is misleading and has been a deprecated term since the Codebase Initialization Refactor.
1 parent 1a5d9ed commit 1a085d2

File tree

228 files changed

+1422
-1314
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

228 files changed

+1422
-1314
lines changed

src/codegen/runner/diff/get_raw_diff.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ def patch_to_limited_diff_string(patch, codebase: Codebase, max_lines=10000):
2727

2828
# Add flags that are not in the diff
2929
filenames = [patched_file.path for patched_file in patch]
30-
flags_not_in_diff = list(filter(lambda flag: flag.symbol.filepath not in filenames, codebase.G.flags._flags))
30+
flags_not_in_diff = list(filter(lambda flag: flag.symbol.filepath not in filenames, codebase.ctx.flags._flags))
3131

3232
for flag in flags_not_in_diff:
3333
filename = flag.symbol.filepath
@@ -39,7 +39,7 @@ def patch_to_limited_diff_string(patch, codebase: Codebase, max_lines=10000):
3939
patch.append(patched_file)
4040

4141
for patched_file in patch:
42-
filtered_flags = filter(lambda flag: flag.symbol.filepath == patched_file.path, codebase.G.flags._flags)
42+
filtered_flags = filter(lambda flag: flag.symbol.filepath == patched_file.path, codebase.ctx.flags._flags)
4343
sorted_flags = list(map(lambda flag: flag.symbol.start_point.row + 1, filtered_flags))
4444
sorted_flags.sort()
4545

src/codegen/runner/sandbox/executor.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,8 @@ async def find_flags(self, execute_func: Callable) -> list[CodeFlag]:
3636
"""Runs the execute_func in find_mode to find flags"""
3737
self.codebase.set_find_mode(True)
3838
await self._execute_with_try_catch(execute_func, commit=False)
39-
code_flags = self.codebase.G.flags._flags
40-
logger.info(f"> Found {len(self.codebase.G.flags._flags)} CodeFlags")
39+
code_flags = self.codebase.ctx.flags._flags
40+
logger.info(f"> Found {len(self.codebase.ctx.flags._flags)} CodeFlags")
4141
return code_flags
4242

4343
async def find_flag_groups(self, code_flags: list[CodeFlag], grouping_config: GroupingConfig) -> list[Group]:
@@ -77,7 +77,7 @@ async def execute_flag_groups(self, commit_msg: str, execute_func: Callable, fla
7777
run_results.append(run_result)
7878
head_branches.append(created_branch)
7979

80-
self.codebase.G.flags._flags.clear()
80+
self.codebase.ctx.flags._flags.clear()
8181
return run_results, head_branches
8282

8383
async def execute(self, execute_func: Callable, group: Group | None = None, session_options: SessionOptions = SessionOptions()) -> CodemodRunResult:
@@ -155,7 +155,7 @@ async def _get_structured_run_output(self, result: CodemodRunResult) -> CodemodR
155155
"messageType": str(flag.message_type),
156156
"messageRecipient": flag.message_recipient,
157157
}
158-
for flag in self.codebase.G.flags._flags
158+
for flag in self.codebase.ctx.flags._flags
159159
]
160160
result.flags = flags
161161
if result.observation_meta is None:

src/codegen/runner/sandbox/middlewares.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,6 @@ async def cleanup_after_codemod(self, is_exception: bool = False):
6969
if is_exception:
7070
# TODO: instead of committing transactions, we should just rollback
7171
logger.info("Committing pending transactions due to exception")
72-
self.runner.codebase.G.commit_transactions(sync_graph=False)
72+
self.runner.codebase.ctx.commit_transactions(sync_graph=False)
7373
self.runner.reset_runner()
7474
self.server_info.is_running_codemod = False

src/codegen/runner/sandbox/runner.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,5 +112,5 @@ async def create_branch(self, request: CreateBranchRequest) -> CreateBranchRespo
112112
response.results = run_results
113113
response.branches = branches
114114

115-
self.codebase.G.flags._flags.clear()
115+
self.codebase.ctx.flags._flags.clear()
116116
return response

src/codegen/sdk/code_generation/doc_utils/generate_docs_json.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
from codegen.sdk.core.placeholder.placeholder_type import TypePlaceholder
99

1010
ATTRIBUTES_TO_IGNORE = [
11-
"G",
11+
"ctx",
1212
"node_id",
1313
"angular",
1414
"model_config",
@@ -19,7 +19,6 @@
1919
"node_type",
2020
"ts_node",
2121
"file_node_id",
22-
"G",
2322
"statement_type",
2423
"assignment_types",
2524
]

src/codegen/sdk/codebase/codebase_analysis.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010

1111
def get_codebase_summary(codebase: Codebase) -> str:
12-
node_summary = f"""Contains {len(codebase.G.get_nodes())} nodes
12+
node_summary = f"""Contains {len(codebase.ctx.get_nodes())} nodes
1313
- {len(list(codebase.files))} files
1414
- {len(list(codebase.imports))} imports
1515
- {len(list(codebase.external_modules))} external_modules
@@ -19,10 +19,10 @@ def get_codebase_summary(codebase: Codebase) -> str:
1919
\t- {len(list(codebase.global_vars))} global_vars
2020
\t- {len(list(codebase.interfaces))} interfaces
2121
"""
22-
edge_summary = f"""Contains {len(codebase.G.edges)} edges
23-
- {len([x for x in codebase.G.edges if x[2].type == EdgeType.SYMBOL_USAGE])} symbol -> used symbol
24-
- {len([x for x in codebase.G.edges if x[2].type == EdgeType.IMPORT_SYMBOL_RESOLUTION])} import -> used symbol
25-
- {len([x for x in codebase.G.edges if x[2].type == EdgeType.EXPORT])} export -> exported symbol
22+
edge_summary = f"""Contains {len(codebase.ctx.edges)} edges
23+
- {len([x for x in codebase.ctx.edges if x[2].type == EdgeType.SYMBOL_USAGE])} symbol -> used symbol
24+
- {len([x for x in codebase.ctx.edges if x[2].type == EdgeType.IMPORT_SYMBOL_RESOLUTION])} import -> used symbol
25+
- {len([x for x in codebase.ctx.edges if x[2].type == EdgeType.EXPORT])} export -> exported symbol
2626
"""
2727

2828
return f"{node_summary}\n{edge_summary}"

src/codegen/sdk/codebase/codebase_graph.py renamed to src/codegen/sdk/codebase/codebase_context.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ def get_node_classes(programming_language: ProgrammingLanguage) -> NodeClasses:
7676
raise ValueError(msg)
7777

7878

79-
class CodebaseGraph:
79+
class CodebaseContext:
8080
"""MultiDiGraph Wrapper with TransactionManager"""
8181

8282
# =====[ __init__ attributes ]=====

src/codegen/sdk/codebase/config_parser.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,21 +4,21 @@
44
from codegen.sdk.enums import ProgrammingLanguage
55

66
if TYPE_CHECKING:
7-
from codegen.sdk.codebase.codebase_graph import CodebaseGraph
7+
from codegen.sdk.codebase.codebase_context import CodebaseContext
88

99

1010
class ConfigParser(ABC):
1111
def __init__(self):
1212
pass
1313

1414
@abstractmethod
15-
def parse_configs(self, codebase_graph: "CodebaseGraph"): ...
15+
def parse_configs(self, codebase_context: "CodebaseContext"): ...
1616

1717

18-
def get_config_parser_for_language(language: ProgrammingLanguage, codebase_graph: "CodebaseGraph") -> ConfigParser | None:
18+
def get_config_parser_for_language(language: ProgrammingLanguage, codebase_context: "CodebaseContext") -> ConfigParser | None:
1919
from codegen.sdk.typescript.config_parser import TSConfigParser
2020

2121
if language == ProgrammingLanguage.TYPESCRIPT:
22-
return TSConfigParser(codebase_graph)
22+
return TSConfigParser(codebase_context)
2323

2424
return None

src/codegen/sdk/codebase/factory/get_session.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
from codegen.git.repo_operator.local_repo_operator import LocalRepoOperator
88
from codegen.git.schemas.repo_config import BaseRepoConfig
9-
from codegen.sdk.codebase.codebase_graph import CodebaseGraph
9+
from codegen.sdk.codebase.codebase_context import CodebaseContext
1010
from codegen.sdk.codebase.config import CodebaseConfig, GSFeatureFlags, ProjectConfig, SessionOptions, TestFlags
1111
from codegen.sdk.codebase.factory.codebase_factory import CodebaseFactory
1212
from codegen.sdk.core.codebase import Codebase, PyCodebaseType, TSCodebaseType
@@ -108,12 +108,12 @@ def get_codebase_graph_session(
108108
files: dict[str, str] = {},
109109
sync_graph: bool = True,
110110
session_options: SessionOptions = SessionOptions(),
111-
) -> Generator[CodebaseGraph, None, None]:
111+
) -> Generator[CodebaseContext, None, None]:
112112
"""Gives you a Codebase2 operating on the files you provided as a dict"""
113113
op = LocalRepoOperator.create_from_files(repo_path=tmpdir, files=files)
114114
config = CodebaseConfig(feature_flags=TestFlags)
115115
projects = [ProjectConfig(repo_operator=op, programming_language=programming_language)]
116-
graph = CodebaseGraph(projects=projects, config=config)
116+
graph = CodebaseContext(projects=projects, config=config)
117117
with graph.session(sync_graph=sync_graph, session_options=session_options):
118118
try:
119119
yield graph

src/codegen/sdk/codebase/node_classes/py_node_classes.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,10 @@
3131
from codegen.sdk.python.statements.import_statement import PyImportStatement
3232

3333

34-
def parse_subscript(node: TSNode, file_node_id, G, parent):
34+
def parse_subscript(node: TSNode, file_node_id, ctx, parent):
3535
if (node.prev_named_sibling and node.prev_named_sibling.text.decode("utf-8") == "TypeAlias") or isinstance(parent, Type):
36-
return PyGenericType(node, file_node_id, G, parent)
37-
return SubscriptExpression(node, file_node_id, G, parent)
36+
return PyGenericType(node, file_node_id, ctx, parent)
37+
return SubscriptExpression(node, file_node_id, ctx, parent)
3838

3939

4040
PyExpressionMap = {

0 commit comments

Comments
 (0)