Skip to content

Commit 0d15c10

Browse files
authored
feat!: Finalize some of the programming_language -> language migration (#490)
# Motivation <!-- Why is this change necessary? --> # Content <!-- Please include a summary of the change --> # Testing <!-- How was the change tested? --> # Please check the following before marking your PR as ready for review - [ ] I have added tests for my changes - [ ] I have updated the documentation or added new documentation as needed
1 parent f88da8f commit 0d15c10

File tree

7 files changed

+19
-21
lines changed

7 files changed

+19
-21
lines changed

docs/api-reference/core/Codebase.mdx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -310,8 +310,8 @@ Fetches a codebase from GitHub and returns a Codebase instance.
310310
defaultValue=""
311311
/>
312312
<Parameter
313-
name="programming_language"
314-
type={ <code className="text-sm bg-gray-100 px-2 py-0.5 rounded">ProgrammingLanguage | None</code> }
313+
name="language"
314+
type={ <code className="text-sm bg-gray-100 px-2 py-0.5 rounded">Literal["python", "typescript"] | ProgrammingLanguage | None</code> }
315315
description="The programming language of the repo. Defaults to None."
316316
defaultValue=""
317317
/>

src/codegen/extensions/graph/main.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
from codegen import Codebase
22
from codegen.extensions.graph.create_graph import create_codebase_graph
33
from codegen.extensions.graph.neo4j_exporter import Neo4jExporter
4-
from codegen.shared.enums.programming_language import ProgrammingLanguage
54

65

76
def visualize_codebase(codebase, neo4j_uri: str, username: str, password: str):
@@ -39,5 +38,5 @@ def visualize_codebase(codebase, neo4j_uri: str, username: str, password: str):
3938

4039
if __name__ == "__main__":
4140
# Initialize codebase
42-
codebase = Codebase("../../", programming_language=ProgrammingLanguage.PYTHON)
41+
codebase = Codebase("../../", language="python")
4342
visualize_codebase(codebase, "bolt://localhost:7687", "neo4j", "password")

src/codegen/extensions/mcp/codebase_agent.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@
1111

1212
mcp = FastMCP(
1313
"codebase-agent-mcp",
14-
instructions="Use this server to access any information from your codebase. This tool can provide information ranging from AST Symbol details and information from across the codebase. Use this tool for all questions, queries regarding your codebase.",
14+
instructions="""Use this server to access any information from your codebase. This tool can provide information ranging from AST Symbol details and information from across the codebase.
15+
Use this tool for all questions, queries regarding your codebase.""",
1516
)
1617

1718

@@ -27,7 +28,7 @@ def query_codebase(
2728
if not os.path.exists(codebase_dir):
2829
return {"error": f"Codebase directory '{codebase_dir}' does not exist. Please provide a valid directory path."}
2930
# Initialize codebase
30-
codebase = Codebase(repo_path=codebase_dir, programming_language=codebase_language)
31+
codebase = Codebase(repo_path=codebase_dir, language=codebase_language)
3132

3233
# Create the agent
3334
agent = create_codebase_inspector_agent(codebase=codebase, model_name="gpt-4", verbose=True)

src/codegen/extensions/mcp/codebase_mods.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ def split_files_by_function(
2121
):
2222
if not os.path.exists(codebase_dir):
2323
return {"error": f"Codebase directory '{codebase_dir}' does not exist. Please provide a valid directory path."}
24-
codebase = Codebase(repo_path=codebase_dir, programming_language=codebase_language)
24+
codebase = Codebase(repo_path=codebase_dir, language=codebase_language)
2525
new_files = {}
2626
file = codebase.get_file(target_file)
2727
# for each test_function in the file

src/codegen/extensions/mcp/codebase_tools.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ def reveal_symbol_tool(
2525
collect_dependencies: Annotated[Optional[bool], "includes dependencies of symbol"],
2626
collect_usages: Annotated[Optional[bool], "includes usages of symbol"],
2727
):
28-
codebase = Codebase(repo_path=codebase_dir, programming_language=codebase_language)
28+
codebase = Codebase(repo_path=codebase_dir, language=codebase_language)
2929
result = reveal_symbol(
3030
codebase=codebase,
3131
symbol_name=symbol_name,
@@ -45,7 +45,7 @@ def search_codebase_tool(
4545
codebase_language: Annotated[ProgrammingLanguage, "The language the codebase is written in"],
4646
use_regex: Annotated[bool, "use regex for the search query"],
4747
):
48-
codebase = Codebase(repo_path=codebase_dir, programming_language=codebase_language)
48+
codebase = Codebase(repo_path=codebase_dir, language=codebase_language)
4949
result = search(codebase, query, target_directories, use_regex=use_regex)
5050
return json.dumps(result, indent=2)
5151

src/codegen/sdk/core/codebase.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ def __init__(
141141
self,
142142
repo_path: str,
143143
*,
144-
language: Literal["python", "typescript"] | None = None,
144+
language: Literal["python", "typescript"] | ProgrammingLanguage | None = None,
145145
projects: None = None,
146146
config: CodebaseConfig = DefaultConfig,
147147
io: IO | None = None,
@@ -1251,7 +1251,7 @@ def from_repo(
12511251
tmp_dir (Optional[str]): The directory to clone the repo into. Defaults to /tmp/codegen
12521252
commit (Optional[str]): The specific commit hash to clone. Defaults to HEAD
12531253
shallow (bool): Whether to do a shallow clone. Defaults to True
1254-
language (Literal["python", "typescript"] | None): The programming language of the repo. Defaults to None.
1254+
language (Literal["python", "typescript"] | ProgrammingLanguage | None): The programming language of the repo. Defaults to None.
12551255
config (CodebaseConfig): Configuration for the codebase. Defaults to DefaultConfig.
12561256
12571257
Returns:

src/codegen/sdk/system-prompt.txt

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1350,7 +1350,6 @@ Construct a Codebase by passing in a path to a local `git` repository or any sub
13501350

13511351
```python
13521352
from codegen import Codebase
1353-
from codegen.shared.enums.programming_language import ProgrammingLanguage
13541353

13551354
# Parse from a git repository root
13561355
codebase = Codebase("path/to/repository")
@@ -1362,12 +1361,12 @@ codebase = Codebase("path/to/repository/src/subfolder")
13621361
codebase = Codebase("./")
13631362

13641363
# Specify programming language (instead of inferring from file extensions)
1365-
codebase = Codebase("./", programming_language=ProgrammingLanguage.TYPESCRIPT)
1364+
codebase = Codebase("./", language="typescript")
13661365
```
13671366

13681367
<Note>
13691368
By default, Codegen will automatically infer the programming language of the codebase and
1370-
parse all files in the codebase. You can override this by passing the `programming_language` parameter
1369+
parse all files in the codebase. You can override this by passing the `language` parameter
13711370
with a value from the `ProgrammingLanguage` enum.
13721371
</Note>
13731372

@@ -1383,7 +1382,6 @@ To fetch and parse a repository directly from GitHub, use the `from_repo` functi
13831382

13841383
```python
13851384
import codegen
1386-
from codegen.shared.enums.programming_language import ProgrammingLanguage
13871385

13881386
# Fetch and parse a repository (defaults to /tmp/codegen/{repo_name})
13891387
codebase = codegen.from_repo('fastapi/fastapi')
@@ -1394,7 +1392,7 @@ codebase = codegen.from_repo(
13941392
tmp_dir='/custom/temp/dir', # Optional: custom temp directory
13951393
commit='786a8ada7ed0c7f9d8b04d49f24596865e4b7901', # Optional: specific commit
13961394
shallow=False, # Optional: full clone instead of shallow
1397-
programming_language=ProgrammingLanguage.PYTHON # Optional: override language detection
1395+
language="python" # Optional: override language detection
13981396
)
13991397
```
14001398

@@ -1446,7 +1444,6 @@ from codegen import Codebase
14461444
from codegen.git.repo_operator.local_repo_operator import LocalRepoOperator
14471445
from codegen.git.schemas.repo_config import BaseRepoConfig
14481446
from codegen.sdk.codebase.config import ProjectConfig
1449-
from codegen.shared.enums.programming_language import ProgrammingLanguage
14501447

14511448
codebase = Codebase(
14521449
projects = [
@@ -1456,7 +1453,7 @@ codebase = Codebase(
14561453
repo_config=BaseRepoConfig(),
14571454
bot_commit=True
14581455
),
1459-
programming_language=ProgrammingLanguage.TYPESCRIPT,
1456+
language="typescript",
14601457
base_path="src/codegen/sdk/typescript",
14611458
subdirectories=["src/codegen/sdk/typescript"]
14621459
)
@@ -6606,14 +6603,13 @@ First, we initialize the codebase and create a vector index for semantic search:
66066603
```python
66076604
from codegen import Codebase
66086605
from codegen.extensions import VectorIndex
6609-
from codegen.shared.enums.programming_language import ProgrammingLanguage
66106606

66116607
def initialize_codebase():
66126608
"""Initialize and index the codebase."""
66136609
# Initialize codebase with smart caching
66146610
codebase = Codebase.from_repo(
66156611
"codegen-sh/codegen-sdk",
6616-
programming_language=ProgrammingLanguage.PYTHON,
6612+
language="python",
66176613
tmp_dir="/root"
66186614
)
66196615

@@ -6795,6 +6791,7 @@ While this example demonstrates a simple RAG-based bot, you can extend it to bui
67956791
</Card>
67966792
</CardGroup>
67976793

6794+
67986795
---
67996796
title: "Mining Training Data for LLMs"
68006797
sidebarTitle: "Mining Data"
@@ -10651,7 +10648,7 @@ from codegen.extensions.tools.semantic_search import semantic_search
1065110648

1065210649
@mcp.tool('codebase_semantic_search', "search codebase with the provided query")
1065310650
def search(query: Annotated[str, "search query to run against codebase"]):
10654-
codebase = Codebase("provide location to codebase", programming_language="provide codebase Language")
10651+
codebase = Codebase("provide location to codebase", language="provide codebase Language")
1065510652
# use the semantic search tool from codegen.extensions.tools OR write your own
1065610653
results = semantic_search(codebase=codebase, query=query)
1065710654
return results
@@ -10672,6 +10669,7 @@ If you'd like to integrate this into an IDE checkout out this [setup guide](/int
1067210669
And that's a wrap, chime in at our [community
1067310670
Slack](https://community.codegen.com) if you have questions or ideas for additional MCP tools/capabilities
1067410671

10672+
1067510673
---
1067610674
title: "Neo4j Graph"
1067710675
sidebarTitle: "Neo4j Graph"

0 commit comments

Comments
 (0)