-
Notifications
You must be signed in to change notification settings - Fork 52
Tawsif add support for codebase exports #117
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
tawsifkamal
merged 11 commits into
develop
from
tawsif-add-support-for-codebase-exports
Jan 27, 2025
Merged
Changes from 5 commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
7c340e1
added exports
0683135
Merge branch 'develop' into tawsif-add-support-for-codebase-exports
33fc194
Merge branch 'develop' into tawsif-add-support-for-codebase-exports
6015877
added py_noapidocs for the TS specific methods?
38d411b
Merge branch 'develop' into tawsif-add-support-for-codebase-exports
fc6578e
adding PyDirectroty and TSDirectoryt
034b82d
fixed TSCodebaseType
52f85d2
Merge branch 'develop' into tawsif-add-support-for-codebase-exports
398e494
linting
a815be4
more linting
96a98d6
Merge branch 'develop' into tawsif-add-support-for-codebase-exports
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
17 changes: 17 additions & 0 deletions
17
tests/unit/codegen/sdk/python/codebase/test_codebase_raise_error.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import pytest | ||
from codegen.sdk.codebase.factory.get_session import get_codebase_session | ||
from codegen.sdk.enums import ProgrammingLanguage | ||
|
||
|
||
def test_python_exports_not_supported(tmpdir): | ||
"""Test that exports are not supported in Python codebases.""" | ||
# language=python | ||
content = """ | ||
def hello(): | ||
pass | ||
""" | ||
# Create a Python codebase with a simple Python file | ||
with get_codebase_session(tmpdir=tmpdir, files={"test.py": content}, programming_language=ProgrammingLanguage.PYTHON) as codebase: | ||
# Verify that accessing exports raises NotImplementedError | ||
with pytest.raises(NotImplementedError): | ||
_ = codebase.exports |
52 changes: 52 additions & 0 deletions
52
tests/unit/codegen/sdk/typescript/codebase/test_codebase_exports.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
from codegen.sdk.codebase.factory.get_session import get_codebase_session | ||
from codegen.sdk.enums import ProgrammingLanguage | ||
|
||
|
||
def test_codebase_exports(tmpdir) -> None: | ||
# language=typescript | ||
content = """ | ||
export const a = 1; | ||
export let b = 2; | ||
export var c = 3; | ||
export function foo() {} | ||
export class Bar {} | ||
export interface IFoo {} | ||
export type MyType = string; | ||
export { foo as default }; | ||
""" | ||
with get_codebase_session(tmpdir=tmpdir, files={"file.ts": content}, programming_language=ProgrammingLanguage.TYPESCRIPT) as codebase: | ||
assert len(codebase.exports) == 8 | ||
export_names = {exp.name for exp in codebase.exports} | ||
assert export_names == {"a", "b", "c", "foo", "Bar", "IFoo", "MyType", "default"} | ||
|
||
|
||
def test_codebase_reexports(tmpdir) -> None: | ||
# language=typescript | ||
content1 = """ | ||
export const x = 1; | ||
export const y = 2; | ||
""" | ||
content2 = """ | ||
export { x } from './file1'; | ||
export { y as z } from './file1'; | ||
""" | ||
with get_codebase_session( | ||
tmpdir=tmpdir, | ||
files={"file1.ts": content1, "file2.ts": content2}, | ||
programming_language=ProgrammingLanguage.TYPESCRIPT | ||
) as codebase: | ||
assert len(codebase.exports) == 4 | ||
export_names = {exp.name for exp in codebase.exports} | ||
assert export_names == {"x", "y", "z"} | ||
|
||
|
||
def test_codebase_default_exports(tmpdir) -> None: | ||
# language=typescript | ||
content = """ | ||
const value = 42; | ||
export default value; | ||
""" | ||
with get_codebase_session(tmpdir=tmpdir, files={"file.ts": content}, programming_language=ProgrammingLanguage.TYPESCRIPT) as codebase: | ||
assert len(codebase.exports) == 1 | ||
export = codebase.exports[0] | ||
assert export.name == "value" |
52 changes: 52 additions & 0 deletions
52
tests/unit/codegen/sdk/typescript/export/test_directory_exports.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
from codegen.sdk.codebase.factory.get_session import get_codebase_session | ||
from codegen.sdk.enums import ProgrammingLanguage | ||
|
||
|
||
def test_codebase_exports(tmpdir) -> None: | ||
# language=typescript | ||
content = """ | ||
export const a = 1; | ||
export let b = 2; | ||
export var c = 3; | ||
export function foo() {} | ||
export class Bar {} | ||
export interface IFoo {} | ||
export type MyType = string; | ||
export { foo as default }; | ||
""" | ||
with get_codebase_session(tmpdir=tmpdir, files={"file.ts": content}, programming_language=ProgrammingLanguage.TYPESCRIPT) as codebase: | ||
assert len(codebase.exports) == 8 | ||
export_names = {exp.name for exp in codebase.exports} | ||
assert export_names == {"a", "b", "c", "foo", "Bar", "IFoo", "MyType", "default"} | ||
|
||
|
||
def test_codebase_reexports(tmpdir) -> None: | ||
# language=typescript | ||
content1 = """ | ||
export const x = 1; | ||
export const y = 2; | ||
""" | ||
content2 = """ | ||
export { x } from './file1'; | ||
export { y as z } from './file1'; | ||
""" | ||
with get_codebase_session( | ||
tmpdir=tmpdir, | ||
files={"file1.ts": content1, "file2.ts": content2}, | ||
programming_language=ProgrammingLanguage.TYPESCRIPT | ||
) as codebase: | ||
assert len(codebase.exports) == 4 | ||
export_names = {exp.name for exp in codebase.exports} | ||
assert export_names == {"x", "y", "z"} | ||
|
||
|
||
def test_codebase_default_exports(tmpdir) -> None: | ||
# language=typescript | ||
content = """ | ||
const value = 42; | ||
export default value; | ||
""" | ||
with get_codebase_session(tmpdir=tmpdir, files={"file.ts": content}, programming_language=ProgrammingLanguage.TYPESCRIPT) as codebase: | ||
assert len(codebase.exports) == 1 | ||
export = codebase.exports[0] | ||
assert export.name == "value" |
69 changes: 69 additions & 0 deletions
69
tests/unit/codegen/sdk/typescript/import_resolution/test_directory_import.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
from codegen.sdk.codebase.factory.get_session import get_codebase_session | ||
from codegen.sdk.enums import ImportType, ProgrammingLanguage | ||
|
||
|
||
def test_directory_imports(tmpdir) -> None: | ||
# language=typescript | ||
content1 = """ | ||
import { a, b } from '../shared'; | ||
import type { IFoo } from './types'; | ||
""" | ||
content2 = """ | ||
import { c } from '../shared'; | ||
import defaultExport from './module'; | ||
""" | ||
with get_codebase_session( | ||
tmpdir=tmpdir, | ||
files={ | ||
"dir1/file1.ts": content1, | ||
"dir1/file2.ts": content2, | ||
"dir2/file3.ts": "import { d } from '../shared';" | ||
}, | ||
programming_language=ProgrammingLanguage.TYPESCRIPT | ||
) as codebase: | ||
dir1 = codebase.get_directory("dir1") | ||
dir2 = codebase.get_directory("dir2") | ||
|
||
# Test dir1 imports | ||
assert len(dir1.imports) == 5 | ||
dir1_import_names = {imp.name for imp in dir1.imports} | ||
assert dir1_import_names == {"a", "b", "IFoo", "c", "defaultExport"} | ||
|
||
# Test dir2 imports | ||
assert len(dir2.imports) == 1 | ||
assert dir2.imports[0].name == "d" | ||
|
||
# Test get_import method | ||
assert dir1.get_import("a") is not None | ||
assert dir1.get_import("d") is None | ||
assert dir2.get_import("d") is not None | ||
|
||
|
||
def test_directory_nested_imports(tmpdir) -> None: | ||
# language=typescript | ||
content1 = """ | ||
import { a } from './module1'; | ||
""" | ||
content2 = """ | ||
import { b } from '../module2'; | ||
""" | ||
content3 = """ | ||
import { c } from '../../module3'; | ||
""" | ||
with get_codebase_session( | ||
tmpdir=tmpdir, | ||
files={ | ||
"dir1/file1.ts": content1, | ||
"dir1/subdir/file2.ts": content2, | ||
"dir1/subdir/deepdir/file3.ts": content3 | ||
}, | ||
programming_language=ProgrammingLanguage.TYPESCRIPT | ||
) as codebase: | ||
dir1 = codebase.get_directory("dir1") | ||
subdir = codebase.get_directory("dir1/subdir") | ||
deepdir = codebase.get_directory("dir1/subdir/deepdir") | ||
|
||
# Test imports at each directory level | ||
assert len(dir1.imports) == 3 # Should include all nested imports | ||
assert len(subdir.imports) == 2 # Should include its own and deeper imports | ||
assert len(deepdir.imports) == 1 # Should only include its own imports |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.