You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
[Codegen](https://docs.codegen.com) is a python library for manipulating codebases.
6
8
7
-
Write code that transforms code. Codegen combines the parsing power of [Tree-sitter](https://tree-sitter.github.io/tree-sitter/) with the graph algorithms of [rustworkx](https://github.com/Qiskit/rustworkx) to enable scriptable, multi-language code manipulation at scale.
8
9
9
10
```python
10
11
from codegen import Codebase
@@ -21,16 +22,43 @@ for function in codebase.functions:
21
22
function.move_to_file('deprecated.py')
22
23
```
23
24
24
-
## Installation
25
+
Write code that transforms code. Codegen combines the parsing power of [Tree-sitter](https://tree-sitter.github.io/tree-sitter/) with the graph algorithms of [rustworkx](https://github.com/Qiskit/rustworkx) to enable scriptable, multi-language code manipulation at scale.
26
+
27
+
## Installation and Usage
25
28
**This library requires Python 3.12 – 3.13.**
26
29
```
30
+
# Install inside existing project
27
31
uv pip install codegen
32
+
33
+
# Install global CLI
34
+
uv tool install codegen
35
+
36
+
# Create a codemod for a given repo
37
+
cd path/to/repo
38
+
codegen init
39
+
codegen create test-function
40
+
41
+
# Run said codemod
42
+
codegen run test-function
43
+
44
+
# Create an isolated venv with codegen => open jupyter
45
+
codegen notebook
46
+
```
47
+
48
+
## Usage
49
+
50
+
See [https://docs.codegen.com/introduction/getting-started] for a full tutorial.
<Attributetype={ <><spanclassName="text-gray-200">list[</span> <ahref="/api-reference/core/FunctionCall"style={ {fontWeight: "inherit", fontSize: "inherit"} }>FunctionCall</a> <spanclassName="text-gray-200">]</span></> }description="Returns a list of function calls present in the value of this argument." />
48
+
<Attributetype={ <><span>list[</span> <ahref="/api-reference/core/FunctionCall"style={ {fontWeight: "inherit", fontSize: "inherit"} }>FunctionCall</a> <span>]</span></> }description="Returns a list of function calls present in the value of this argument." />
49
49
50
50
### <spanclassName="text-primary">index</span>
51
51
<HorizontalDividerlight={true} />
@@ -71,19 +71,19 @@ import {Attribute} from '/snippets/Attribute.mdx';
<Attributetype={ <><ahref="/api-reference/core/Class"style={ {fontWeight: "inherit", fontSize: "inherit"} }>Class</a> <spanclassName="text-gray-200">| None</span></> }description="Find the class this node is contained in" />
74
+
<Attributetype={ <><ahref="/api-reference/core/Class"style={ {fontWeight: "inherit", fontSize: "inherit"} }>Class</a> <span>| None</span></> }description="Find the class this node is contained in" />
<Attributetype={ <><ahref="/api-reference/core/Function"style={ {fontWeight: "inherit", fontSize: "inherit"} }>Function</a> <spanclassName="text-gray-200">| None</span></> }description="Find the function this node is contained in" />
78
+
<Attributetype={ <><ahref="/api-reference/core/Function"style={ {fontWeight: "inherit", fontSize: "inherit"} }>Function</a> <span>| None</span></> }description="Find the function this node is contained in" />
<Attributetype={ <><ahref="/api-reference/core/Expression"style={ {fontWeight: "inherit", fontSize: "inherit"} }>Expression</a> <spanclassName="text-gray-200">| list[</span> <ahref="/api-reference/core/Expression"style={ {fontWeight: "inherit", fontSize: "inherit"} }>Expression</a> <spanclassName="text-gray-200">]</span></> }description="Returns the resolved type of an Expression." />
86
+
<Attributetype={ <><ahref="/api-reference/core/Expression"style={ {fontWeight: "inherit", fontSize: "inherit"} }>Expression</a> <span>| list[</span> <ahref="/api-reference/core/Expression"style={ {fontWeight: "inherit", fontSize: "inherit"} }>Expression</a> <span>]</span></> }description="Returns the resolved type of an Expression." />
87
87
88
88
### <spanclassName="text-primary">source</span>
89
89
<HorizontalDividerlight={true} />
@@ -100,11 +100,11 @@ import {Attribute} from '/snippets/Attribute.mdx';
100
100
101
101
### <spanclassName="text-primary">value</span>
102
102
<HorizontalDividerlight={true} />
103
-
<Attributetype={ <><ahref="/api-reference/core/Expression"style={ {fontWeight: "inherit", fontSize: "inherit"} }>Expression</a> <spanclassName="text-gray-200">| None</span></> }description="Gets the value node of the object." />
103
+
<Attributetype={ <><ahref="/api-reference/core/Expression"style={ {fontWeight: "inherit", fontSize: "inherit"} }>Expression</a> <span>| None</span></> }description="Gets the value node of the object." />
<Attributetype={ <><spanclassName="text-gray-200">list[</span> <ahref="/api-reference/core/Editable"style={ {fontWeight: "inherit", fontSize: "inherit"} }>Editable</a> <spanclassName="text-gray-200">]</span></> }description="Returns Editables for all TreeSitter node instances of variable usages within this node's" />
107
+
<Attributetype={ <><span>list[</span> <ahref="/api-reference/core/Editable"style={ {fontWeight: "inherit", fontSize: "inherit"} }>Editable</a> <span>]</span></> }description="Returns Editables for all TreeSitter node instances of variable usages within this node's" />
108
108
109
109
110
110
## Methods
@@ -131,7 +131,7 @@ Find all ancestors of the node of the given type. Does not return itself
@@ -189,7 +189,7 @@ Find and return matching nodes or substrings within an Editable instance.
189
189
</ParameterWrapper>
190
190
191
191
192
-
<Returnreturn_type={ <><spanclassName="text-gray-200">list[</span> <ahref="/api-reference/core/Editable"style={ {fontWeight: "inherit", fontSize: "inherit"} }>Editable</a> <spanclassName="text-gray-200">]</span></> }description="A list of Editable instances that match the search criteria."/>
192
+
<Returnreturn_type={ <><span>list[</span> <ahref="/api-reference/core/Editable"style={ {fontWeight: "inherit", fontSize: "inherit"} }>Editable</a> <span>]</span></> }description="A list of Editable instances that match the search criteria."/>
<Returnreturn_type={ <><ahref="/api-reference/core/Name"style={ {fontWeight: "inherit", fontSize: "inherit"} }>Name</a> <spanclassName="text-gray-200">|</span> <ahref="/api-reference/core/ChainedAttribute"style={ {fontWeight: "inherit", fontSize: "inherit"} }>ChainedAttribute</a> <spanclassName="text-gray-200">| None</span></> }description="The name node of the object. Can be a Name node for simple names, a ChainedAttribute for names with namespaces (e.g., a.b), or None if the object has no name."/>
231
+
<Returnreturn_type={ <><ahref="/api-reference/core/Name"style={ {fontWeight: "inherit", fontSize: "inherit"} }>Name</a> <span>|</span> <ahref="/api-reference/core/ChainedAttribute"style={ {fontWeight: "inherit", fontSize: "inherit"} }>ChainedAttribute</a> <span>| None</span></> }description="The name node of the object. Can be a Name node for simple names, a ChainedAttribute for names with namespaces (e.g., a.b), or None if the object has no name."/>
@@ -473,7 +473,7 @@ Returns a list of all regex match of `regex_pattern`, similar to python's re.sea
473
473
</ParameterWrapper>
474
474
475
475
476
-
<Returnreturn_type={ <><spanclassName="text-gray-200">list[</span> <ahref="/api-reference/core/Editable"style={ {fontWeight: "inherit", fontSize: "inherit"} }>Editable</a> <spanclassName="text-gray-200">]</span></> }description="A list of Editable objects corresponding to the matches found."/>
476
+
<Returnreturn_type={ <><span>list[</span> <ahref="/api-reference/core/Editable"style={ {fontWeight: "inherit", fontSize: "inherit"} }>Editable</a> <span>]</span></> }description="A list of Editable objects corresponding to the matches found."/>
0 commit comments