Skip to content

Commit 398e494

Browse files
author
codegen-bot
committed
linting
1 parent 52f85d2 commit 398e494

File tree

6 files changed

+23
-47
lines changed

6 files changed

+23
-47
lines changed

src/codegen/sdk/core/codebase.py

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -39,11 +39,11 @@
3939
from codegen.sdk.core.detached_symbols.code_block import CodeBlock
4040
from codegen.sdk.core.detached_symbols.parameter import Parameter
4141
from codegen.sdk.core.directory import Directory
42+
from codegen.sdk.core.export import Export
4243
from codegen.sdk.core.external_module import ExternalModule
4344
from codegen.sdk.core.file import File, SourceFile
4445
from codegen.sdk.core.function import Function
4546
from codegen.sdk.core.import_resolution import Import
46-
from codegen.sdk.core.export import Export
4747
from codegen.sdk.core.interface import Interface
4848
from codegen.sdk.core.interfaces.editable import Editable
4949
from codegen.sdk.core.interfaces.has_name import HasName
@@ -66,12 +66,12 @@
6666
from codegen.sdk.typescript.class_definition import TSClass
6767
from codegen.sdk.typescript.detached_symbols.code_block import TSCodeBlock
6868
from codegen.sdk.typescript.detached_symbols.parameter import TSParameter
69+
from codegen.sdk.typescript.export import TSExport
6970
from codegen.sdk.typescript.file import TSFile
7071
from codegen.sdk.typescript.function import TSFunction
7172
from codegen.sdk.typescript.import_resolution import TSImport
72-
from codegen.sdk.typescript.statements.import_statement import TSImportStatement
73-
from codegen.sdk.typescript.export import TSExport
7473
from codegen.sdk.typescript.interface import TSInterface
74+
from codegen.sdk.typescript.statements.import_statement import TSImportStatement
7575
from codegen.sdk.typescript.symbol import TSSymbol
7676
from codegen.sdk.typescript.type_alias import TSTypeAlias
7777
from codegen.sdk.utils import determine_project_language
@@ -102,10 +102,6 @@
102102
PyDirectory = Directory[PyFile, PySymbol, PyImportStatement, PyGlobalVar, PyClass, PyFunction, PyImport]
103103

104104

105-
106-
107-
108-
109105
@apidoc
110106
class Codebase(Generic[TSourceFile, TDirectory, TSymbol, TClass, TFunction, TImport, TGlobalVar, TInterface, TTypeAlias, TParameter, TCodeBlock]):
111107
"""This class provides the main entrypoint for most programs to analyzing and manipulating codebases.
@@ -275,11 +271,10 @@ def imports(self) -> list[TImport]:
275271
TImport can be PyImport for Python codebases or TSImport for TypeScript codebases.
276272
"""
277273
return self.G.get_nodes(NodeType.IMPORT)
278-
279274

280275
@property
281276
@py_noapidoc
282-
def exports(self: 'TSCodebaseType') -> list[TSExport]:
277+
def exports(self: "TSCodebaseType") -> list[TSExport]:
283278
"""Returns a list of all Export nodes in the codebase.
284279
285280
Retrieves all Export nodes from the codebase graph. These exports represent all export statements across all files in the codebase,
@@ -291,9 +286,8 @@ def exports(self: 'TSCodebaseType') -> list[TSExport]:
291286
Returns:
292287
list[TSExport]: A list of Export nodes representing all exports in the codebase.
293288
TExport can only be a TSExport for TypeScript codebases.
294-
295-
"""
296289
290+
"""
297291
if self.language == ProgrammingLanguage.PYTHON:
298292
raise NotImplementedError("Exports are not supported for Python codebases since Python does not have an export mechanism.")
299293

@@ -1177,6 +1171,7 @@ def from_repo(cls, repo_name: str, *, tmp_dir: str | None = None, commit: str |
11771171
logger.error(f"Failed to initialize codebase: {e}")
11781172
raise
11791173

1174+
11801175
# The last 2 lines of code are added to the runner. See codegen-backend/cli/generate/utils.py
11811176
# Type Aliases
11821177
CodebaseType = Codebase[SourceFile, Directory, Symbol, Class, Function, Import, Assignment, Interface, TypeAlias, Parameter, CodeBlock]

src/codegen/sdk/core/directory.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,16 +10,15 @@
1010
from codegen.sdk.core.class_definition import Class
1111
from codegen.sdk.core.file import File
1212
from codegen.sdk.core.function import Function
13-
from codegen.sdk.core.import_resolution import ImportStatement
13+
from codegen.sdk.core.import_resolution import Import, ImportStatement
1414
from codegen.sdk.core.symbol import Symbol
15+
from codegen.sdk.typescript.class_definition import TSClass
1516
from codegen.sdk.typescript.export import TSExport
16-
from codegen.sdk.core.import_resolution import Import
1717
from codegen.sdk.typescript.file import TSFile
1818
from codegen.sdk.typescript.function import TSFunction
1919
from codegen.sdk.typescript.import_resolution import TSImport
2020
from codegen.sdk.typescript.statements.import_statement import TSImportStatement
2121
from codegen.sdk.typescript.symbol import TSSymbol
22-
from codegen.sdk.typescript.class_definition import TSClass
2322

2423
import logging
2524

@@ -36,6 +35,7 @@
3635

3736
TSGlobalVar = TypeVar("TSGlobalVar", bound="Assignment")
3837

38+
3939
@apidoc
4040
class Directory(Generic[TFile, TSymbol, TImportStatement, TGlobalVar, TClass, TFunction, TImport]):
4141
"""Directory representation for codebase.

tests/unit/codegen/sdk/python/codebase/test_codebase_raise_error.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import pytest
2+
23
from codegen.sdk.codebase.factory.get_session import get_codebase_session
34
from codegen.sdk.enums import ProgrammingLanguage
45

@@ -14,4 +15,4 @@ def hello():
1415
with get_codebase_session(tmpdir=tmpdir, files={"test.py": content}, programming_language=ProgrammingLanguage.PYTHON) as codebase:
1516
# Verify that accessing exports raises NotImplementedError
1617
with pytest.raises(NotImplementedError):
17-
_ = codebase.exports
18+
_ = codebase.exports

tests/unit/codegen/sdk/typescript/codebase/test_codebase_exports.py

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,7 @@ def test_codebase_reexports(tmpdir) -> None:
3030
export { x } from './file1';
3131
export { y as z } from './file1';
3232
"""
33-
with get_codebase_session(
34-
tmpdir=tmpdir,
35-
files={"file1.ts": content1, "file2.ts": content2},
36-
programming_language=ProgrammingLanguage.TYPESCRIPT
37-
) as codebase:
33+
with get_codebase_session(tmpdir=tmpdir, files={"file1.ts": content1, "file2.ts": content2}, programming_language=ProgrammingLanguage.TYPESCRIPT) as codebase:
3834
assert len(codebase.exports) == 4
3935
export_names = {exp.name for exp in codebase.exports}
4036
assert export_names == {"x", "y", "z"}
@@ -49,4 +45,4 @@ def test_codebase_default_exports(tmpdir) -> None:
4945
with get_codebase_session(tmpdir=tmpdir, files={"file.ts": content}, programming_language=ProgrammingLanguage.TYPESCRIPT) as codebase:
5046
assert len(codebase.exports) == 1
5147
export = codebase.exports[0]
52-
assert export.name == "value"
48+
assert export.name == "value"

tests/unit/codegen/sdk/typescript/export/test_directory_exports.py

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,7 @@ def test_codebase_reexports(tmpdir) -> None:
3030
export { x } from './file1';
3131
export { y as z } from './file1';
3232
"""
33-
with get_codebase_session(
34-
tmpdir=tmpdir,
35-
files={"file1.ts": content1, "file2.ts": content2},
36-
programming_language=ProgrammingLanguage.TYPESCRIPT
37-
) as codebase:
33+
with get_codebase_session(tmpdir=tmpdir, files={"file1.ts": content1, "file2.ts": content2}, programming_language=ProgrammingLanguage.TYPESCRIPT) as codebase:
3834
assert len(codebase.exports) == 4
3935
export_names = {exp.name for exp in codebase.exports}
4036
assert export_names == {"x", "y", "z"}
@@ -49,4 +45,4 @@ def test_codebase_default_exports(tmpdir) -> None:
4945
with get_codebase_session(tmpdir=tmpdir, files={"file.ts": content}, programming_language=ProgrammingLanguage.TYPESCRIPT) as codebase:
5046
assert len(codebase.exports) == 1
5147
export = codebase.exports[0]
52-
assert export.name == "value"
48+
assert export.name == "value"
Lines changed: 8 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
from codegen.sdk.codebase.factory.get_session import get_codebase_session
2-
from codegen.sdk.enums import ImportType, ProgrammingLanguage
2+
from codegen.sdk.enums import ProgrammingLanguage
33

44

55
def test_directory_imports(tmpdir) -> None:
@@ -13,26 +13,20 @@ def test_directory_imports(tmpdir) -> None:
1313
import defaultExport from './module';
1414
"""
1515
with get_codebase_session(
16-
tmpdir=tmpdir,
17-
files={
18-
"dir1/file1.ts": content1,
19-
"dir1/file2.ts": content2,
20-
"dir2/file3.ts": "import { d } from '../shared';"
21-
},
22-
programming_language=ProgrammingLanguage.TYPESCRIPT
16+
tmpdir=tmpdir, files={"dir1/file1.ts": content1, "dir1/file2.ts": content2, "dir2/file3.ts": "import { d } from '../shared';"}, programming_language=ProgrammingLanguage.TYPESCRIPT
2317
) as codebase:
2418
dir1 = codebase.get_directory("dir1")
2519
dir2 = codebase.get_directory("dir2")
26-
20+
2721
# Test dir1 imports
2822
assert len(dir1.imports) == 5
2923
dir1_import_names = {imp.name for imp in dir1.imports}
3024
assert dir1_import_names == {"a", "b", "IFoo", "c", "defaultExport"}
31-
25+
3226
# Test dir2 imports
3327
assert len(dir2.imports) == 1
3428
assert dir2.imports[0].name == "d"
35-
29+
3630
# Test get_import method
3731
assert dir1.get_import("a") is not None
3832
assert dir1.get_import("d") is None
@@ -51,19 +45,13 @@ def test_directory_nested_imports(tmpdir) -> None:
5145
import { c } from '../../module3';
5246
"""
5347
with get_codebase_session(
54-
tmpdir=tmpdir,
55-
files={
56-
"dir1/file1.ts": content1,
57-
"dir1/subdir/file2.ts": content2,
58-
"dir1/subdir/deepdir/file3.ts": content3
59-
},
60-
programming_language=ProgrammingLanguage.TYPESCRIPT
48+
tmpdir=tmpdir, files={"dir1/file1.ts": content1, "dir1/subdir/file2.ts": content2, "dir1/subdir/deepdir/file3.ts": content3}, programming_language=ProgrammingLanguage.TYPESCRIPT
6149
) as codebase:
6250
dir1 = codebase.get_directory("dir1")
6351
subdir = codebase.get_directory("dir1/subdir")
6452
deepdir = codebase.get_directory("dir1/subdir/deepdir")
65-
53+
6654
# Test imports at each directory level
6755
assert len(dir1.imports) == 3 # Should include all nested imports
6856
assert len(subdir.imports) == 2 # Should include its own and deeper imports
69-
assert len(deepdir.imports) == 1 # Should only include its own imports
57+
assert len(deepdir.imports) == 1 # Should only include its own imports

0 commit comments

Comments
 (0)