Skip to content

Commit a95970a

Browse files
authored
Merge commit b34f8b5 from parent
2 parents f0c54ca + 73fa86d commit a95970a

File tree

25 files changed

+528
-3247
lines changed

25 files changed

+528
-3247
lines changed

.github/actions/setup-environment/action.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ runs:
99
using: "composite"
1010
steps:
1111
- name: Install UV
12-
uses: astral-sh/setup-uv@v5.3
12+
uses: astral-sh/setup-uv@v5.4
1313
id: setup-uv
1414
with:
1515
enable-cache: true

.github/workflows/mypy.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ jobs:
2525

2626
- name: Get changed files
2727
id: changed-files
28-
uses: tj-actions/[email protected].1
28+
uses: tj-actions/[email protected].3
2929

3030
- name: Filter Python files
3131
id: filter-python

.github/workflows/release.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ jobs:
5555
repository: ${{ github.event.pull_request.head.repo.full_name || github.event.repository.full_name }}
5656

5757
- name: Install UV
58-
uses: astral-sh/setup-uv@v5.3
58+
uses: astral-sh/setup-uv@v5.4
5959
id: setup-uv
6060
with:
6161
enable-cache: false

codegen-examples/uv.lock

Lines changed: 171 additions & 156 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docs/changelog/changelog.mdx

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,31 @@ icon: "clock"
44
iconType: "solid"
55
---
66

7+
<Update label="v0.52.19" description="March 21, 2025">
8+
### [Dependency update for OpenAI.](https://github.com/codegen-sh/codegen-sdk/releases/tag/v0.52.19)
9+
- Update OpenAI dependency to version 1.68.2
10+
</Update>
11+
12+
<Update label="v0.52.18" description="March 21, 2025">
13+
### [Updates sentry-sdk dependency and changelog.](https://github.com/codegen-sh/codegen-sdk/releases/tag/v0.52.18)
14+
- Update sentry-sdk dependency to v2.24.0
15+
- Update changelog
16+
</Update>
17+
18+
<Update label="v0.52.17" description="March 21, 2025">
19+
### [Reverts API change, fixes duplication, updates docs.](https://github.com/codegen-sh/codegen-sdk/releases/tag/v0.52.17)
20+
- Revert changes to API for removing unused symbols
21+
- Fix issue with duplicate additional tools
22+
- Update API reference documentation
23+
</Update>
24+
25+
26+
<Update label="v0.52.16" description="March 20, 2025">
27+
### [Updates OpenAI dependency and PR branch handling.](https://github.com/codegen-sh/codegen-sdk/releases/tag/v0.52.16)
28+
- Update dependency to OpenAI v1.68.0
29+
- Return branch name with PR changes
30+
</Update>
31+
732
<Update label="v0.52.15" description="March 20, 2025">
833
### [fixes token limit inversion bug.](https://github.com/codegen-sh/codegen-sdk/releases/tag/v0.52.15)
934
- Fix token limit inversion bug

pyproject.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ readme = "README.md"
66
# renovate: datasource=python-version depName=python
77
requires-python = ">=3.12, <3.14"
88
dependencies = [
9-
"openai==1.68.0",
9+
"openai==1.68.2",
1010
"tiktoken<1.0.0,>=0.5.1",
1111
"tabulate>=0.9.0,<1.0.0",
1212
"codeowners<1.0.0,>=0.6.0",
@@ -36,7 +36,7 @@ dependencies = [
3636
"rustworkx>=0.15.1",
3737
"typing-extensions>=4.12.2",
3838
"termcolor>=2.4.0",
39-
"sentry-sdk==2.23.1",
39+
"sentry-sdk==2.24.0",
4040
"click>=8.1.7",
4141
"requests>=2.32.3",
4242
"lazy-object-proxy>=0.0.0",

src/codegen/extensions/langchain/agent.py

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ def create_codebase_agent(
6363
"""
6464
llm = LLM(model_provider=model_provider, model_name=model_name, **kwargs)
6565

66-
# Get all codebase tools
66+
# Initialize default tools
6767
tools = [
6868
ViewFileTool(codebase),
6969
ListDirectoryTool(codebase),
@@ -80,17 +80,13 @@ def create_codebase_agent(
8080
ReflectionTool(codebase),
8181
SearchFilesByNameTool(codebase),
8282
GlobalReplacementEditTool(codebase),
83-
# SemanticSearchTool(codebase),
84-
# =====[ Github Integration ]=====
85-
# Enable Github integration
86-
# GithubCreatePRTool(codebase),
87-
# GithubViewPRTool(codebase),
88-
# GithubCreatePRCommentTool(codebase),
89-
# GithubCreatePRReviewCommentTool(codebase),
9083
]
9184

92-
# Add additional tools if provided
9385
if additional_tools:
86+
# Get names of additional tools
87+
additional_names = {t.get_name() for t in additional_tools}
88+
# Keep only tools that don't have matching names in additional_tools
89+
tools = [t for t in tools if t.get_name() not in additional_names]
9490
tools.extend(additional_tools)
9591

9692
memory = MemorySaver() if memory else None

src/codegen/sdk/codebase/transaction_manager.py

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import math
21
import time
32
from collections.abc import Callable
43
from pathlib import Path
@@ -290,22 +289,6 @@ def get_transactions_at_range(self, file_path: Path, start_byte: int, end_byte:
290289

291290
return matching_transactions
292291

293-
def get_transaction_containing_range(self, file_path: Path, start_byte: int, end_byte: int, transaction_order: TransactionPriority | None = None) -> Transaction | None:
294-
"""Returns the nearest transaction that includes the range specified given the filtering criteria."""
295-
if file_path not in self.queued_transactions:
296-
return None
297-
298-
smallest_difference = math.inf
299-
best_fit_transaction = None
300-
for t in self.queued_transactions[file_path]:
301-
if t.start_byte <= start_byte and t.end_byte >= end_byte:
302-
if transaction_order is None or t.transaction_order == transaction_order:
303-
smallest_difference = min(smallest_difference, abs(t.start_byte - start_byte) + abs(t.end_byte - end_byte))
304-
if smallest_difference == 0:
305-
return t
306-
best_fit_transaction = t
307-
return best_fit_transaction
308-
309292
def _get_conflicts(self, transaction: Transaction) -> list[Transaction]:
310293
"""Returns all transactions that overlap with the given transaction"""
311294
overlapping_transactions = []

src/codegen/sdk/core/file.py

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -943,13 +943,6 @@ def remove_unused_exports(self) -> None:
943943
None
944944
"""
945945

946-
def remove_unused_imports(self) -> None:
947-
# Process each import statement
948-
for import_stmt in self.imports:
949-
# Don't remove imports we can't be sure about
950-
if import_stmt.usage_is_ascertainable():
951-
import_stmt.remove_if_unused()
952-
953946
####################################################################################################################
954947
# MANIPULATIONS
955948
####################################################################################################################

src/codegen/sdk/core/import_resolution.py

Lines changed: 6 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
from typing import TYPE_CHECKING, ClassVar, Generic, Literal, Self, TypeVar, override
66

77
from codegen.sdk.codebase.resolution_stack import ResolutionStack
8+
from codegen.sdk.codebase.transactions import TransactionPriority
89
from codegen.sdk.core.autocommit import commiter, reader, remover, writer
910
from codegen.sdk.core.dataclasses.usage import UsageKind
1011
from codegen.sdk.core.expressions.name import Name
@@ -220,17 +221,6 @@ def is_symbol_import(self) -> bool:
220221
"""
221222
return not self.is_module_import()
222223

223-
@reader
224-
def usage_is_ascertainable(self) -> bool:
225-
"""Returns True if we can determine for sure whether the import is unused or not.
226-
227-
Returns:
228-
bool: True if the usage can be ascertained for the import, False otherwise.
229-
"""
230-
if self.is_wildcard_import() or self.is_sideffect_import():
231-
return False
232-
return True
233-
234224
@reader
235225
def is_wildcard_import(self) -> bool:
236226
"""Returns True if the import symbol is a wildcard import.
@@ -244,16 +234,6 @@ def is_wildcard_import(self) -> bool:
244234
"""
245235
return self.import_type == ImportType.WILDCARD
246236

247-
@reader
248-
def is_sideffect_import(self) -> bool:
249-
# Maybe better name for this
250-
"""Determines if this is a sideffect.
251-
252-
Returns:
253-
bool: True if this is a sideffect import, False otherwise
254-
"""
255-
return self.import_type == ImportType.SIDE_EFFECT
256-
257237
@property
258238
@abstractmethod
259239
def namespace(self) -> str | None:
@@ -681,21 +661,12 @@ def __eq__(self, other: object):
681661

682662
@noapidoc
683663
@reader
684-
def remove_if_unused(self, force: bool = False) -> bool:
685-
"""Removes import if it is not being used. Considers current transaction removals.
686-
687-
Args:
688-
force (bool, optional): If true removes the import even if we cannot ascertain the usage for sure. Defaults to False.
689-
690-
Returns:
691-
bool: True if removed, False if not
692-
"""
693-
if all(usage.match.get_transaction_if_pending_removal() for usage in self.usages):
694-
if not force and not self.usage_is_ascertainable():
695-
return False
664+
def remove_if_unused(self) -> None:
665+
if all(
666+
self.transaction_manager.get_transactions_at_range(self.filepath, start_byte=usage.match.start_byte, end_byte=usage.match.end_byte, transaction_order=TransactionPriority.Remove)
667+
for usage in self.usages
668+
):
696669
self.remove()
697-
return True
698-
return False
699670

700671
@noapidoc
701672
@reader

src/codegen/sdk/core/interfaces/editable.py

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
from rich.pretty import Pretty
1111

1212
from codegen.sdk.codebase.span import Span
13-
from codegen.sdk.codebase.transactions import EditTransaction, InsertTransaction, RemoveTransaction, Transaction, TransactionPriority
13+
from codegen.sdk.codebase.transactions import EditTransaction, InsertTransaction, RemoveTransaction, TransactionPriority
1414
from codegen.sdk.core.autocommit import commiter, reader, remover, repr_func, writer
1515
from codegen.sdk.core.placeholder.placeholder import Placeholder
1616
from codegen.sdk.extensions.utils import get_all_identifiers
@@ -1156,15 +1156,6 @@ def parent_class(self) -> Class | None:
11561156

11571157
return self.parent_of_type(Class)
11581158

1159-
@noapidoc
1160-
def get_transaction_if_pending_removal(self) -> Transaction | None:
1161-
"""Checks if this editable is being removed by some transaction and if so returns it.
1162-
1163-
Returns:
1164-
Transaction|None: The transaction removing the editable
1165-
"""
1166-
return self.transaction_manager.get_transaction_containing_range(self.file.path, self.start_byte, self.end_byte, TransactionPriority.Remove)
1167-
11681159
def _get_ast_children(self) -> list[tuple[str | None, AST]]:
11691160
children = []
11701161
names = {}

src/codegen/sdk/core/symbol.py

Lines changed: 1 addition & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55

66
from rich.markup import escape
77

8-
from codegen.sdk.codebase.transactions import TransactionPriority
98
from codegen.sdk.core.autocommit import commiter, reader, writer
109
from codegen.sdk.core.dataclasses.usage import UsageKind, UsageType
1110
from codegen.sdk.core.detached_symbols.argument import Argument
@@ -267,38 +266,11 @@ def insert_before(self, new_src: str, fix_indentation: bool = False, newline: bo
267266
return first_node.insert_before(new_src, fix_indentation, newline, priority, dedupe)
268267
return super().insert_before(new_src, fix_indentation, newline, priority, dedupe)
269268

270-
def _post_move_import_cleanup(self, encountered_symbols, strategy):
271-
# =====[ Remove any imports that are no longer used ]=====
272-
from codegen.sdk.core.import_resolution import Import
273-
274-
for dep in self.dependencies:
275-
if strategy != "duplicate_dependencies":
276-
other_usages = [usage.usage_symbol for usage in dep.usages if usage.usage_symbol not in encountered_symbols]
277-
else:
278-
other_usages = [usage.usage_symbol for usage in dep.usages]
279-
if isinstance(dep, Import):
280-
dep.remove_if_unused()
281-
282-
elif isinstance(dep, Symbol):
283-
usages_in_file = [symb for symb in other_usages if symb.file == self.file and not symb.get_transaction_if_pending_removal()]
284-
if dep.get_transaction_if_pending_removal():
285-
if not usages_in_file and strategy != "add_back_edge":
286-
# We are going to assume there is only one such import
287-
if imp_list := [import_str for import_str in self.file._pending_imports if dep.name and dep.name in import_str]:
288-
if insert_import_list := [
289-
transaction
290-
for transaction in self.transaction_manager.queued_transactions[self.file.path]
291-
if imp_list[0] and transaction.new_content and imp_list[0] in transaction.new_content and transaction.transaction_order == TransactionPriority.Insert
292-
]:
293-
self.transaction_manager.queued_transactions[self.file.path].remove(insert_import_list[0])
294-
self.file._pending_imports.remove(imp_list[0])
295-
296269
def move_to_file(
297270
self,
298271
file: SourceFile,
299272
include_dependencies: bool = True,
300273
strategy: Literal["add_back_edge", "update_all_imports", "duplicate_dependencies"] = "update_all_imports",
301-
cleanup_unused_imports: bool = True,
302274
) -> None:
303275
"""Moves the given symbol to a new file and updates its imports and references.
304276
@@ -318,7 +290,7 @@ def move_to_file(
318290
AssertionError: If an invalid strategy is provided.
319291
"""
320292
encountered_symbols = {self}
321-
self._move_to_file(file, encountered_symbols, include_dependencies, strategy, cleanup_unused_imports)
293+
self._move_to_file(file, encountered_symbols, include_dependencies, strategy)
322294

323295
@noapidoc
324296
def _move_to_file(
@@ -327,7 +299,6 @@ def _move_to_file(
327299
encountered_symbols: set[Symbol | Import],
328300
include_dependencies: bool = True,
329301
strategy: Literal["add_back_edge", "update_all_imports", "duplicate_dependencies"] = "update_all_imports",
330-
cleanup_unused_imports: bool = True,
331302
) -> tuple[NodeId, NodeId]:
332303
"""Helper recursive function for `move_to_file`"""
333304
from codegen.sdk.core.import_resolution import Import
@@ -420,9 +391,6 @@ def _move_to_file(
420391
# Delete the original symbol
421392
self.remove()
422393

423-
if cleanup_unused_imports:
424-
self._post_move_import_cleanup(encountered_symbols, strategy)
425-
426394
@property
427395
@reader
428396
@noapidoc

0 commit comments

Comments
 (0)