Skip to content

Commit 8e6badc

Browse files
committed
Merge branch 'develop' into rpatel/temp-run-logger
2 parents 2256aff + 84aa4e9 commit 8e6badc

File tree

370 files changed

+20038
-3104
lines changed

Some content is hidden

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

370 files changed

+20038
-3104
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,5 +26,5 @@ runs:
2626
- name: Install codecov
2727
shell: bash
2828
run: |
29-
uv tool install [email protected] --python 3.10
29+
uv tool install [email protected]
3030
uv tool update-shell

.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].7
28+
uses: tj-actions/[email protected].8
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
@@ -72,7 +72,7 @@ jobs:
7272
7373
# TODO: add cbuildwheel cache
7474
- name: Build wheel
75-
uses: pypa/cibuildwheel@v2.22.0
75+
uses: pypa/cibuildwheel@v2.23.0
7676
env:
7777
CIBW_BUILD: "*cp3${{ matrix.python }}*"
7878

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ supabase/config.toml
3030
**/scripts/*.md
3131
**/scripts/Personal/*
3232
**/infrastructure/aws_infra/.terraform/*
33+
pyrightconfig.json
3334
Edwards Scratchpad.ipynb
3435

3536
# Allowing .env files to exist in repository, but not allowing updates

.pre-commit-config.yaml

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -80,27 +80,13 @@ repos:
8080
rev: 39.169.3
8181
hooks:
8282
- id: renovate-config-validator
83+
8384
- repo: https://github.com/astral-sh/uv-pre-commit
8485
rev: "0.5.31"
8586
hooks:
8687
- id: uv-sync
8788
args: ["--frozen", "--all-packages", "--all-extras"]
8889

89-
- repo: "local"
90-
hooks:
91-
# Disabled as part of LFS removal.
92-
# - id: disallowed-words-check
93-
# name: Check for disallowed words
94-
# entry: scripts/disallowed-words-check.sh
95-
# language: script
96-
# files: '' # Check all files
97-
- id: generate-runner-imports
98-
name: Generate Runner Imports
99-
entry: bash -c "uv run --frozen python -m codegen.gscli.cli generate runner-imports src/codegen/shared/compilation/function_imports.py"
100-
language: system
101-
pass_filenames: false
102-
always_run: true
103-
10490
- repo: https://github.com/hukkin/mdformat
10591
rev: 0.7.22 # Use the ref you want to point at
10692
hooks:

CONTRIBUTING.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ uv sync --dev
3939
> [!TIP]
4040
>
4141
> - If sync fails with `missing field 'version'`, you may need to delete lockfile and rerun `rm uv.lock && uv sync --dev`.
42-
> - If sync fails with failed compilation, you may need to install clang and rerun `uv sync --dev`.
42+
> - If sync fails with failed compilation, you may need to install dependencies (see [install-deps.sh](scripts/install-deps.sh)) and rerun `uv sync --dev`.
4343
4444
### Running Tests
4545

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ We support
4949
- macOS and Linux
5050
- macOS is supported
5151
- Linux is supported on x86_64 and aarch64 with glibc 2.34+
52-
- Windows is not supported
52+
- Windows is supported via WSL. See [here](https://docs.codegen.com/building-with-codegen/codegen-with-wsl) for more details.
5353
- Python, Typescript, Javascript and React codebases
5454

5555
```

architecture/2. parsing/B. AST Construction.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,4 +74,4 @@ Statements have another layer of complexity. They are essentially pattern based
7474

7575
## Next Step
7676

77-
After the AST is constructed, the system moves on to [Import Resolution](../3.%20imports-exports/A.%20Imports.md) to analyze module dependencies and resolve symbols across files.
77+
After the AST is constructed, the system moves on to [Directory Parsing](./C.%20Directory%20Parsing.md) to build a hierarchical representation of the codebase's directory structure.
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
# Directory Parsing
2+
3+
The Directory Parsing system is responsible for creating and maintaining a hierarchical representation of the codebase's directory structure in memory. Directories do not hold references to the file itself, but instead holds the names to the files and does a dynamic lookup when needed.
4+
5+
In addition to providing a more cohesive API for listing directory files, the Directory API is also used for [TSConfig](../3.%20imports-exports/C.%20TSConfig.md)-based (Import Resolution)[../3.%20imports-exports/A.%20Imports.md].
6+
7+
## Core Components
8+
9+
The Directory Tree is constructed during the initial build_graph step in codebase_context.py, and is recreated from scratch on every re-sync. More details are below:
10+
11+
## Directory Tree Construction
12+
13+
The directory tree is built through the following process:
14+
15+
1. The `build_directory_tree` method in `CodebaseContext` is called during graph initialization or when the codebase structure changes.
16+
1. The method iterates through all files in the repository, creating directory objects for each directory path encountered.
17+
1. For each file, it adds the file to its parent directory using the `_add_file` method.
18+
1. Directories are created recursively as needed using the `get_directory` method with create_on_missing=True\`.
19+
20+
## Directory Representation
21+
22+
The `Directory` class provides a rich interface for working with directories:
23+
24+
- **Hierarchy Navigation**: Access parent directories and subdirectories
25+
- **File Access**: Retrieve files by name or extension
26+
- **Symbol Access**: Find symbols (classes, functions, etc.) within files in the directory
27+
- **Directory Operations**: Rename, remove, or update directories
28+
29+
Each `Directory` instance maintains:
30+
31+
- A reference to its parent directory
32+
- Lists of files and subdirectories
33+
- Methods to recursively traverse the directory tree
34+
35+
## File Representation
36+
37+
Files are represented by the `File` class and its subclasses:
38+
39+
- `File`: Base class for all files, supporting basic operations like reading and writing content
40+
- `SourceFile`: Specialized class for source code files that can be parsed into an AST
41+
42+
Files maintain references to:
43+
44+
- Their parent directory
45+
- Their content (loaded dynamically to preserve the source of truth)
46+
- For source files, the parsed AST and symbols
47+
48+
## Next Step
49+
50+
After the directory structure is parsed, the system can perform [Import Resolution](../3.%20imports-exports/A.%20Imports.md) to analyze module dependencies and resolve symbols across files.
Lines changed: 55 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,60 @@
11
# Import Resolution
22

3-
TODO
3+
Import resolution follows AST construction in the code analysis pipeline. It identifies dependencies between modules and builds a graph of relationships across the codebase.
4+
5+
> NOTE: This is an actively evolving part of Codegen SDK, so some details here may be imcomplete, outdated, or incorrect.
6+
7+
## Purpose
8+
9+
The import resolution system serves these purposes:
10+
11+
1. **Dependency Tracking**: Maps relationships between files by resolving import statements.
12+
1. **Symbol Resolution**: Connects imported symbols to their definitions.
13+
1. **Module Graph Construction**: Builds a directed graph of module dependencies.
14+
1. **(WIP) Cross-Language Support**: Provides implementations for different programming languages.
15+
16+
## Core Components
17+
18+
### ImportResolution Class
19+
20+
The `ImportResolution` class represents the outcome of resolving an import statement. It contains:
21+
22+
- The source file containing the imported symbol
23+
- The specific symbol being imported (if applicable)
24+
- Whether the import references an entire file/module
25+
26+
### Import Base Class
27+
28+
The `Import` class is the foundation for language-specific import implementations. It:
29+
30+
- Stores metadata about the import (module path, symbol name, alias)
31+
- Provides the abstract `resolve_import()` method
32+
- Adds symbol resolution edges to the codebase graph
33+
34+
### Language-Specific Implementations
35+
36+
#### Python Import Resolution
37+
38+
The `PyImport` class extends the base `Import` class with Python-specific logic:
39+
40+
- Handles relative imports
41+
- Supports module imports, named imports, and wildcard imports
42+
- Resolves imports using configurable resolution paths and `sys.path`
43+
- Handles special cases like `__init__.py` files
44+
45+
#### TypeScript Import Resolution
46+
47+
The `TSImport` class implements TypeScript-specific resolution:
48+
49+
- Supports named imports, default imports, and namespace imports
50+
- Handles type imports and dynamic imports
51+
- Resolves imports using TSConfig path mappings
52+
- Supports file extension resolution
53+
54+
## Implementation
55+
56+
After file and directory parse, we loop through all import nodes and perform `add_symbol_resolution_edge`. This then invokes the language-specific `resolve_import` method that converts the import statement into a resolvable `ImportResolution` object (or None if the import cannot be resolved). This import symbol and the `ImportResolution` object are then used to add a symbol resolution edge to the graph, where it can then be used in future steps to resolve symbols.
457

558
## Next Step
659

7-
After import resolution, the system analyzes [Export Analysis](./B.%20Exports.md) and handles [TSConfig Support](./C.%20TSConfig.md) for TypeScript projects. This is followed by comprehensive [Type Analysis](../4.%20type-analysis/A.%20Type%20Analysis.md).
60+
After import resolution, the system analyzes [Export Analysis](./B.%20Exports.md) and handles [TSConfig Support](./C.%20TSConfig.md) for TypeScript projects. This is followed by [Type Analysis](../4.%20type-analysis/A.%20Type%20Analysis.md).

0 commit comments

Comments
 (0)