Skip to content

Commit 38d411b

Browse files
author
codegen-bot
committed
Merge branch 'develop' into tawsif-add-support-for-codebase-exports
2 parents 6015877 + f1a00f9 commit 38d411b

File tree

361 files changed

+7096
-4628
lines changed

Some content is hidden

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

361 files changed

+7096
-4628
lines changed

.circleci/config.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ commands:
6161
if [ "<<parameters.extra_repos>>" = "true" ]; then
6262
EXTRA_REPOS_ARG="--extra-repos"
6363
fi
64-
uv run --frozen gs codemod clone-repos ${EXTRA_REPOS_ARG} --token ${CODEGEN_BOT_GHE_TOKEN} --clean-cache
64+
uv run --frozen python -m tests.shared.codemod.commands clone-repos ${EXTRA_REPOS_ARG} --token ${CODEGEN_BOT_GHE_TOKEN} --clean-cache
6565
- save_cache:
6666
paths:
6767
- $GITHUB_WORKSPACE
@@ -70,15 +70,15 @@ commands:
7070
steps:
7171
- run:
7272
command: |
73-
uv run --frozen gs codemod fetch-verified-codemods --cli-api-key ${PROD_CLI_API_KEY}
73+
uv run --frozen python -m tests.shared.codemod.commands fetch-verified-codemods --cli-api-key ${PROD_CLI_API_KEY}
7474
cache-verified-codemod-repos:
7575
steps:
7676
- restore_cache:
7777
keys:
7878
- v1-verified-codemod-repos-{{ checksum "tests/integration/verified_codemods/codemod_data/repo_commits.json" }}-{{.Environment.CIRCLE_NODE_INDEX}}-{{.Environment.CIRCLE_NODE_TOTAL}}
7979
- run:
8080
command: |
81-
uv run --frozen gs codemod clone-repos --verified-codemod-repos --token ${CODEGEN_BOT_GHE_TOKEN}
81+
uv run --frozen python -m tests.shared.codemod.commands clone-repos --verified-codemod-repos --token ${CODEGEN_BOT_GHE_TOKEN}
8282
- save_cache:
8383
paths:
8484
- $GITHUB_WORKSPACE

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,4 +64,4 @@ graph-sitter-types/out/**
6464
graph-sitter-types/typings/**
6565
coverage.json
6666
tests/integration/verified_codemods/codemod_data/repo_commits.json
67-
67+
.codegen/*

.pre-commit-config.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ repos:
1919
hooks:
2020
- id: biome-check
2121
additional_dependencies: ["@biomejs/[email protected]"]
22-
exclude: (src/codemods/eval)|(tests/unit/codegen/sdk/skills)|(tests/unit/codegen/sdk/output)|(tests/integration/verified_codemods)|(docs/samples)
22+
exclude: (src/codemods/eval)|(tests/unit/skills/snapshots)|(tests/unit/codegen/sdk/output)|(tests/integration/verified_codemods)|(docs/samples)
2323

2424
- repo: https://github.com/MarcoGorelli/cython-lint
2525
rev: v0.16.6
@@ -64,7 +64,7 @@ repos:
6464
files: "docs/.*/.*.mdx"
6565

6666
- repo: https://github.com/fpgmaas/deptry.git
67-
rev: "0.22.0"
67+
rev: "0.23.0"
6868
hooks:
6969
- id: deptry
7070
pass_filenames: false

CONTRIBUTING.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
# Contributing to Graph Sitter
1+
# Contributing to Codegen
22

3-
Thank you for your interest in contributing to Graph Sitter! This document outlines the process and guidelines for contributing.
3+
Thank you for your interest in contributing to Codegen! This document outlines the process and guidelines for contributing.
44

55
## Contributor License Agreement
66

7-
By contributing to Graph Sitter, you agree that:
7+
By contributing to Codegen, you agree that:
88

99
1. Your contributions will be licensed under the project's license.
1010
2. You have the right to license your contribution under the project's license.

Dockerfile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ RUN --mount=type=cache,target=/root/.cache/uv \
3434
uv run pre-commit install-hooks
3535
FROM base-image AS extra-repos
3636
ARG CODEGEN_BOT_GHE_TOKEN=""
37-
RUN uv run gs codemod clone-repos --clean-cache --extra-repos --token ${CODEGEN_BOT_GHE_TOKEN}
37+
RUN uv run python -m tests.shared.codemod.commands clone-repos --clean-cache --extra-repos --token ${CODEGEN_BOT_GHE_TOKEN}
3838
FROM base-image AS oss-repos
3939
ARG CODEGEN_BOT_GHE_TOKEN=""
40-
RUN uv run gs codemod clone-repos --clean-cache --token ${CODEGEN_BOT_GHE_TOKEN}
40+
RUN uv run python -m tests.shared.codemod.commands clone-repos --clean-cache --token ${CODEGEN_BOT_GHE_TOKEN}

README.md

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
# Codegen
22

33
[![Documentation](https://img.shields.io/badge/docs-docs.codegen.com-blue)](https://docs.codegen.com)
4+
[![Slack Community](https://img.shields.io/badge/slack-community-4A154B?logo=slack)](https://community.codegen.com)
5+
[![Twitter Follow](https://img.shields.io/twitter/follow/codegen)](https://twitter.com/codegen)
46

57
[Codegen](https://docs.codegen.com) is a python library for manipulating codebases.
68

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.
89

910
```python
1011
from codegen import Codebase
@@ -21,16 +22,43 @@ for function in codebase.functions:
2122
function.move_to_file('deprecated.py')
2223
```
2324

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
2528
**This library requires Python 3.12 – 3.13.**
2629
```
30+
# Install inside existing project
2731
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.
51+
52+
```
53+
from codegen import Codebase
54+
2855
```
2956

3057
## Resources
3158

3259
- [Docs](https://docs.codegen.com)
3360
- [Get Started](https://docs.codegen.com/introduction/getting-started)
61+
- [Contributing](CONTRIBUTING.md)
3462

3563

3664
## Why Codegen?

docs/api-reference/core/Argument.mdx

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ import {Attribute} from '/snippets/Attribute.mdx';
4545

4646
### <span className="text-primary">function_calls</span>
4747
<HorizontalDivider light={true} />
48-
<Attribute type={ <><span className="text-gray-200">list[</span> <a href="/api-reference/core/FunctionCall" style={ {fontWeight: "inherit", fontSize: "inherit"} }>FunctionCall</a> <span className="text-gray-200">]</span></> } description="Returns a list of function calls present in the value of this argument." />
48+
<Attribute type={ <><span>list[</span> <a href="/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." />
4949

5050
### <span className="text-primary">index</span>
5151
<HorizontalDivider light={true} />
@@ -71,19 +71,19 @@ import {Attribute} from '/snippets/Attribute.mdx';
7171

7272
### <span className="text-primary">parent_class</span>
7373
<HorizontalDivider light={true} />
74-
<Attribute type={ <><a href="/api-reference/core/Class" style={ {fontWeight: "inherit", fontSize: "inherit"} }>Class</a> <span className="text-gray-200">| None</span></> } description="Find the class this node is contained in" />
74+
<Attribute type={ <><a href="/api-reference/core/Class" style={ {fontWeight: "inherit", fontSize: "inherit"} }>Class</a> <span>| None</span></> } description="Find the class this node is contained in" />
7575

7676
### <span className="text-primary">parent_function</span>
7777
<HorizontalDivider light={true} />
78-
<Attribute type={ <><a href="/api-reference/core/Function" style={ {fontWeight: "inherit", fontSize: "inherit"} }>Function</a> <span className="text-gray-200">| None</span></> } description="Find the function this node is contained in" />
78+
<Attribute type={ <><a href="/api-reference/core/Function" style={ {fontWeight: "inherit", fontSize: "inherit"} }>Function</a> <span>| None</span></> } description="Find the function this node is contained in" />
7979

8080
### <span className="text-primary">parent_statement</span>
8181
<HorizontalDivider light={true} />
82-
<Attribute type={ <><a href="/api-reference/core/Statement" style={ {fontWeight: "inherit", fontSize: "inherit"} }>Statement</a> <span className="text-gray-200">| None</span></> } description="Find the statement this node is contained in" />
82+
<Attribute type={ <><a href="/api-reference/core/Statement" style={ {fontWeight: "inherit", fontSize: "inherit"} }>Statement</a> <span>| None</span></> } description="Find the statement this node is contained in" />
8383

8484
### <span className="text-primary">resolved_value</span>
8585
<HorizontalDivider light={true} />
86-
<Attribute type={ <><a href="/api-reference/core/Expression" style={ {fontWeight: "inherit", fontSize: "inherit"} }>Expression</a> <span className="text-gray-200">| list[</span> <a href="/api-reference/core/Expression" style={ {fontWeight: "inherit", fontSize: "inherit"} }>Expression</a> <span className="text-gray-200">]</span></> } description="Returns the resolved type of an Expression." />
86+
<Attribute type={ <><a href="/api-reference/core/Expression" style={ {fontWeight: "inherit", fontSize: "inherit"} }>Expression</a> <span>| list[</span> <a href="/api-reference/core/Expression" style={ {fontWeight: "inherit", fontSize: "inherit"} }>Expression</a> <span>]</span></> } description="Returns the resolved type of an Expression." />
8787

8888
### <span className="text-primary">source</span>
8989
<HorizontalDivider light={true} />
@@ -100,11 +100,11 @@ import {Attribute} from '/snippets/Attribute.mdx';
100100

101101
### <span className="text-primary">value</span>
102102
<HorizontalDivider light={true} />
103-
<Attribute type={ <><a href="/api-reference/core/Expression" style={ {fontWeight: "inherit", fontSize: "inherit"} }>Expression</a> <span className="text-gray-200">| None</span></> } description="Gets the value node of the object." />
103+
<Attribute type={ <><a href="/api-reference/core/Expression" style={ {fontWeight: "inherit", fontSize: "inherit"} }>Expression</a> <span>| None</span></> } description="Gets the value node of the object." />
104104

105105
### <span className="text-primary">variable_usages</span>
106106
<HorizontalDivider light={true} />
107-
<Attribute type={ <><span className="text-gray-200">list[</span> <a href="/api-reference/core/Editable" style={ {fontWeight: "inherit", fontSize: "inherit"} }>Editable</a> <span className="text-gray-200">]</span></> } description="Returns Editables for all TreeSitter node instances of variable usages within this node's" />
107+
<Attribute type={ <><span>list[</span> <a href="/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" />
108108

109109

110110
## Methods
@@ -131,7 +131,7 @@ Find all ancestors of the node of the given type. Does not return itself
131131
<GithubLinkNote link="https://github.com/codegen-sh/codegen-sdk/blob/develop/src/codegen/sdk/core/interfaces/editable.py#L1082-L1090" />
132132

133133

134-
<Return return_type={ <><span className="text-gray-200">list[</span> <a href="/api-reference/core/Editable" style={ {fontWeight: "inherit", fontSize: "inherit"} }>Editable</a> <span className="text-gray-200">]</span></> } description=""/>
134+
<Return return_type={ <><span>list[</span> <a href="/api-reference/core/Editable" style={ {fontWeight: "inherit", fontSize: "inherit"} }>Editable</a> <span>]</span></> } description=""/>
135135

136136

137137
### <span className="text-primary">edit</span>
@@ -189,7 +189,7 @@ Find and return matching nodes or substrings within an Editable instance.
189189
</ParameterWrapper>
190190

191191

192-
<Return return_type={ <><span className="text-gray-200">list[</span> <a href="/api-reference/core/Editable" style={ {fontWeight: "inherit", fontSize: "inherit"} }>Editable</a> <span className="text-gray-200">]</span></> } description="A list of Editable instances that match the search criteria."/>
192+
<Return return_type={ <><span>list[</span> <a href="/api-reference/core/Editable" style={ {fontWeight: "inherit", fontSize: "inherit"} }>Editable</a> <span>]</span></> } description="A list of Editable instances that match the search criteria."/>
193193

194194

195195
### <span className="text-primary">find_string_literals</span>
@@ -212,23 +212,23 @@ Returns a list of string literals within this node's source that match any of th
212212
</ParameterWrapper>
213213

214214

215-
<Return return_type={ <><span className="text-gray-200">list[</span> <a href="/api-reference/core/Editable" style={ {fontWeight: "inherit", fontSize: "inherit"} }>Editable</a> <span className="text-gray-200">]</span></> } description="A list of Editable objects representing the matching string literals."/>
215+
<Return return_type={ <><span>list[</span> <a href="/api-reference/core/Editable" style={ {fontWeight: "inherit", fontSize: "inherit"} }>Editable</a> <span>]</span></> } description="A list of Editable objects representing the matching string literals."/>
216216

217217

218218
### <span className="text-primary">flag</span>
219219
Adds a visual flag comment to the end of this Editable's source text.
220220
<GithubLinkNote link="https://github.com/codegen-sh/codegen-sdk/blob/develop/src/codegen/sdk/core/interfaces/editable.py#L920-L931" />
221221

222222

223-
<Return return_type={ <><span className="text-gray-200">CodeFlag[</span> <a href="/api-reference/core/Argument" style={ {fontWeight: "inherit", fontSize: "inherit"} }>Argument</a> <span className="text-gray-200">]</span></> } description=""/>
223+
<Return return_type={ <><span>CodeFlag[</span> <a href="/api-reference/core/Argument" style={ {fontWeight: "inherit", fontSize: "inherit"} }>Argument</a> <span>]</span></> } description=""/>
224224

225225

226226
### <span className="text-primary">get_name</span>
227227
Returns the name node of the object.
228228
<GithubLinkNote link="https://github.com/codegen-sh/codegen-sdk/blob/develop/src/codegen/sdk/core/interfaces/has_name.py#L52-L62" />
229229

230230

231-
<Return return_type={ <><a href="/api-reference/core/Name" style={ {fontWeight: "inherit", fontSize: "inherit"} }>Name</a> <span className="text-gray-200">|</span> <a href="/api-reference/core/ChainedAttribute" style={ {fontWeight: "inherit", fontSize: "inherit"} }>ChainedAttribute</a> <span className="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+
<Return return_type={ <><a href="/api-reference/core/Name" style={ {fontWeight: "inherit", fontSize: "inherit"} }>Name</a> <span>|</span> <a href="/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."/>
232232

233233

234234
### <span className="text-primary">get_variable_usages</span>
@@ -251,7 +251,7 @@ Returns Editables for all TreeSitter nodes corresponding to instances of variabl
251251
</ParameterWrapper>
252252

253253

254-
<Return return_type={ <><span className="text-gray-200">list[</span> <a href="/api-reference/core/Editable" style={ {fontWeight: "inherit", fontSize: "inherit"} }>Editable</a> <span className="text-gray-200">]</span></> } description="List of Editable objects representing variable usage nodes matching the given name."/>
254+
<Return return_type={ <><span>list[</span> <a href="/api-reference/core/Editable" style={ {fontWeight: "inherit", fontSize: "inherit"} }>Editable</a> <span>]</span></> } description="List of Editable objects representing variable usage nodes matching the given name."/>
255255

256256

257257
### <span className="text-primary">insert_after</span>
@@ -349,7 +349,7 @@ Find the first ancestor of the node of the given type. Does not return itself
349349
<GithubLinkNote link="https://github.com/codegen-sh/codegen-sdk/blob/develop/src/codegen/sdk/core/interfaces/editable.py#L1073-L1079" />
350350

351351

352-
<Return return_type={ <><a href="/api-reference/core/Editable" style={ {fontWeight: "inherit", fontSize: "inherit"} }>Editable</a> <span className="text-gray-200">| None</span></> } description=""/>
352+
<Return return_type={ <><a href="/api-reference/core/Editable" style={ {fontWeight: "inherit", fontSize: "inherit"} }>Editable</a> <span>| None</span></> } description=""/>
353353

354354

355355
### <span className="text-primary">reduce_condition</span>
@@ -473,7 +473,7 @@ Returns a list of all regex match of `regex_pattern`, similar to python's re.sea
473473
</ParameterWrapper>
474474

475475

476-
<Return return_type={ <><span className="text-gray-200">list[</span> <a href="/api-reference/core/Editable" style={ {fontWeight: "inherit", fontSize: "inherit"} }>Editable</a> <span className="text-gray-200">]</span></> } description="A list of Editable objects corresponding to the matches found."/>
476+
<Return return_type={ <><span>list[</span> <a href="/api-reference/core/Editable" style={ {fontWeight: "inherit", fontSize: "inherit"} }>Editable</a> <span>]</span></> } description="A list of Editable objects corresponding to the matches found."/>
477477

478478

479479
### <span className="text-primary">set_name</span>

0 commit comments

Comments
 (0)