Skip to content

Commit e022868

Browse files
refactor: Use @graph_sitter (#49)
- **rename to CliSession** - **update to use @graph_sitter** --------- Co-authored-by: Codegen Team (Internal) <[email protected]>
1 parent e2f01c9 commit e022868

File tree

56 files changed

+283
-262
lines changed

Some content is hidden

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

56 files changed

+283
-262
lines changed

.codegen/codemods/test_language/test_language.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
import codegen
2-
from codegen.sdk.core.codebase import Codebase
3-
from codegen.shared.enums.programming_language import ProgrammingLanguage
1+
import graph_sitter
2+
from graph_sitter.core.codebase import Codebase
3+
from graph_sitter.shared.enums.programming_language import ProgrammingLanguage
44

55

6-
@codegen.function("test-language", subdirectories=["src/codegen/cli"], language=ProgrammingLanguage.PYTHON)
6+
@graph_sitter.function("test-language", subdirectories=["src/codegen/cli"], language=ProgrammingLanguage.PYTHON)
77
def run(codebase: Codebase):
88
file = codebase.get_file("src/codegen/cli/errors.py")
99
print(f"File: {file.path}")

.github/workflows/test.yml

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,10 @@ jobs:
2323
unit-tests:
2424
needs: access-check
2525
runs-on: ubuntu-latest
26+
strategy:
27+
matrix:
28+
group: [1, 2, 3, 4, 5, 6, 7, 8]
29+
2630
steps:
2731
- uses: actions/checkout@v4
2832
with:
@@ -38,9 +42,10 @@ jobs:
3842
uv run pytest \
3943
-n auto \
4044
--cov src \
41-
--cov-report=json \
45+
--splits 8 --group ${{ matrix.group }} \
46+
# --cov-report=json \
4247
--timeout 15 \
43-
-o junit_suite_name="${{github.job}}" \
48+
-o junit_suite_name="${{github.job}}-${{ matrix.group }}" \
4449
tests/unit
4550
4651
- uses: ./.github/actions/report

docs/building-with-graph-sitter/function-decorator.mdx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
---
22
title: Function Decorator
3-
sidebarTitle: "@codegen.function"
3+
sidebarTitle: "@graph_sitter.function"
44
icon: "at"
55
iconType: "solid"
66
---
@@ -11,17 +11,17 @@ The `function` decorator is used to define codegen functions within your applica
1111

1212
## Usage
1313

14-
To use the `function` decorator, simply annotate your function with `@codegen.function` and provide a name as an argument.
14+
To use the `function` decorator, simply annotate your function with `@graph_sitter.function` and provide a name as an argument.
1515

1616
### Example
1717

1818
```python
19-
@codegen.function('my-function')
19+
@graph_sitter.function('my-function')
2020
def run(codebase):
2121
pass
2222
```
2323

24-
In this example, the function `run` is decorated with `@codegen.function` and given the name `'my-function'`. This name will be used when the function is ran.
24+
In this example, the function `run` is decorated with `@graph_sitter.function` and given the name `'my-function'`. This name will be used when the function is ran.
2525

2626
## Parameters
2727

docs/building-with-graph-sitter/reusable-codemods.mdx

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ icon: "arrows-rotate"
55
iconType: "solid"
66
---
77

8-
Graph-sitter enables you to create reusable code transformations using Python functions decorated with `@codegen.function`. These codemods can be shared, versioned, and run by your team.
8+
Graph-sitter enables you to create reusable code transformations using Python functions decorated with `@graph_sitter.function`. These codemods can be shared, versioned, and run by your team.
99

1010
## Creating Codemods
1111

@@ -18,10 +18,10 @@ gs create rename-function .
1818
This creates a new codemod in your `.codegen/codemods` directory:
1919

2020
```python
21-
import codegen
21+
import graph_sitter
2222
from graph_sitter import Codebase
2323

24-
@codegen.function("rename-function")
24+
@graph_sitter.function("rename-function")
2525
def run(codebase: Codebase):
2626
"""Add a description of what this codemod does."""
2727
# Add your code here
@@ -64,15 +64,15 @@ The execution flow:
6464

6565
A codemod consists of three main parts:
6666

67-
1. The `@codegen.function` decorator that names your codemod
67+
1. The `@graph_sitter.function` decorator that names your codemod
6868
2. A `run` function that takes a `Codebase` parameter
6969
3. Your transformation logic using the Codebase API
7070

7171
```python
72-
import codegen
72+
import graph_sitter
7373
from graph_sitter import Codebase
7474

75-
@codegen.function("update-imports")
75+
@graph_sitter.function("update-imports")
7676
def run(codebase: Codebase):
7777
"""Update import statements to use new package names."""
7878
for file in codebase.files:
@@ -93,7 +93,7 @@ class RenameArgs(BaseModel):
9393
old_name: str
9494
new_name: str
9595

96-
@codegen.function("rename-function")
96+
@graph_sitter.function("rename-function")
9797
def run(codebase: Codebase, arguments: RenameArgs):
9898
"""Rename a function across the codebase."""
9999
old_func = codebase.get_function(arguments.old_name)

docs/cli/create.mdx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,10 +41,10 @@ When you run `gs create rename-function .`, it creates:
4141
The generated codemod will have this structure:
4242

4343
```python
44-
import codegen
44+
import graph_sitter
4545
from graph_sitter import Codebase
4646

47-
@codegen.function("rename-function")
47+
@graph_sitter.function("rename-function")
4848
def run(codebase: Codebase):
4949
"""Add a description of what this codemod does."""
5050
# Add your code here

docs/tutorials/training-data.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ First, we will do a "graph expansion" for each function - grab the function's so
3131
First, let's import the types we need from Codegen:
3232

3333
```python
34-
import codegen
34+
import graph_sitter
3535
from graph_sitter import Codebase
3636
from codegen.sdk.core.external_module import ExternalModule
3737
from codegen.sdk.core.import_resolution import Import

examples/STRUCTURE.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ Your `run.py` should follow this structure, demonstrated well in the `generate_t
2525
1. **Imports at the top**
2626

2727
```python
28-
import codegen
28+
import graph_sitter
2929
from graph_sitter import Codebase
3030
from codegen.sdk.core import Function
3131
# ... other imports
@@ -42,7 +42,7 @@ Your `run.py` should follow this structure, demonstrated well in the `generate_t
4242
1. **Main Graph-sitter function with decorator**
4343

4444
```python
45-
@codegen.function("your-function-name")
45+
@graph_sitter.function("your-function-name")
4646
def run(codebase: Codebase):
4747
"""Clear docstring explaining what the function does.
4848
@@ -98,7 +98,7 @@ Choose between these approaches based on:
9898

9999
1. **Function Decorator**
100100

101-
- Always use `@codegen.function()` with a descriptive name
101+
- Always use `@graph_sitter.function()` with a descriptive name
102102
- Name should match the example's purpose
103103

104104
1. **Utility Functions**
@@ -136,7 +136,7 @@ def get_function_context(function) -> dict:
136136

137137

138138
# Main transformation with decorator
139-
@codegen.function("generate-training-data")
139+
@graph_sitter.function("generate-training-data")
140140
def run(codebase: Codebase):
141141
"""Generate training data using a node2vec-like approach...
142142

examples/examples/codegen-mcp-server/server.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ def codegen_system_prompt():
167167
```python
168168
from graph_sitter import Codebase
169169
170-
@codegen.function('{name}')
170+
@graph_sitter.function('{name}')
171171
def codemod(codebase: Codebase):
172172
for function in codebase.functions:
173173
if not function.usages:
@@ -355,9 +355,9 @@ async def run_codemod(
355355
return {"error": "Invalid JSON in arguments parameter"}
356356

357357
# Create a session for the codemod
358-
from graph_sitter.cli.auth.session import CodegenSession
358+
from graph_sitter.cli.auth.session import CliSession
359359

360-
session = CodegenSession(state.parsed_codebase.repo_path)
360+
session = CliSession(state.parsed_codebase.repo_path)
361361
session.codebase = state.parsed_codebase
362362

363363
# Capture output

examples/examples/cyclomatic_complexity/run.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
import codegen
1+
import graph_sitter
22
from graph_sitter import Codebase
33
from graph_sitter.core.statements.for_loop_statement import ForLoopStatement
44
from graph_sitter.core.statements.if_block_statement import IfBlockStatement
55
from graph_sitter.core.statements.try_catch_statement import TryCatchStatement
66
from graph_sitter.core.statements.while_statement import WhileStatement
77

88

9-
@codegen.function("cyclomatic-complexity")
9+
@graph_sitter.function("cyclomatic-complexity")
1010
def run(codebase: Codebase):
1111
def calculate_cyclomatic_complexity(code_block):
1212
# Initialize cyclomatic complexity count

examples/examples/delete_dead_code/run.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
import codegen
1+
import graph_sitter
22
from graph_sitter import Codebase
33

44

5-
@codegen.function("delete-dead-code")
5+
@graph_sitter.function("delete-dead-code")
66
def run(codebase: Codebase):
77
removed_functions_count = 0
88
removed_variables_count = 0

0 commit comments

Comments
 (0)