Skip to content

Commit 02fcd95

Browse files
committed
Merge branch 'develop' into rpatel/codebase-snapshot
2 parents 993f2b9 + de7f33a commit 02fcd95

File tree

365 files changed

+9423
-2867
lines changed

Some content is hidden

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

365 files changed

+9423
-2867
lines changed

.codegen/.gitignore

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,8 @@ jupyter/
88
codegen-system-prompt.txt
99

1010
# Python cache files
11-
__pycache__/
11+
**/__pycache__/
1212
*.py[cod]
1313
*$py.class
1414
*.txt
1515
*.pyc
16-
17-
# Keep codemods
18-
!codemods/
19-
!codemods/**

.codegen/codemods/no_link_backticks/no_link_backticks.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
from codegen import Codebase
33

44

5-
@codegen.function("no-link-backticks")
5+
@codegen.function(name="no-link-backticks", subdirectories=["test/unit"])
66
def run(codebase: Codebase):
77
import re
88

@@ -12,6 +12,7 @@ def run(codebase: Codebase):
1212
# Iterate over all .mdx files in the codebase
1313
for file in codebase.files(extensions=["mdx"]):
1414
if file.extension == ".mdx":
15+
print(f"Processing {file.path}")
1516
new_content = file.content
1617

1718
# Find all markdown links with backticks in link text
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import codegen
2+
from codegen.sdk.core.codebase import Codebase
3+
from codegen.shared.enums.programming_language import ProgrammingLanguage
4+
5+
6+
@codegen.function("test-language", subdirectories=["src/codegen/cli"], language=ProgrammingLanguage.PYTHON)
7+
def run(codebase: Codebase):
8+
file = codebase.get_file("src/codegen/cli/errors.py")
9+
print(f"File: {file.path}")
10+
for s in file.symbols:
11+
print(s.name)
12+
13+
14+
if __name__ == "__main__":
15+
print("Parsing codebase...")
16+
codebase = Codebase("./")
17+
18+
print("Running...")
19+
run(codebase)
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import codegen
2+
from codegen.sdk.core.codebase import PyCodebaseType
3+
4+
5+
@codegen.function("update-loggers")
6+
def run(codebase: PyCodebaseType) -> None:
7+
"""Updates all loggers in src/codegen to use the new get_logger function."""
8+
for file in codebase.files:
9+
if not str(file.filepath).startswith("src/codegen/"):
10+
continue
11+
12+
if file.get_import("logging") is None:
13+
continue
14+
15+
if (logger := file.get_global_var("logger")) and logger.value.source == "logging.getLogger(__name__)":
16+
print(f"Updating logger in {file.filepath}")
17+
logger.set_value("get_logger(__name__)")
18+
file.add_import_from_import_string("\nfrom codegen.shared.logging.get_logger import get_logger")

.github/actions/report/action.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ runs:
1919
- name: Upload coverage reports to Codecov
2020
if: (success() || failure()) # always upload coverage reports even if the tests fail
2121
continue-on-error: true
22-
uses: codecov/codecov-action@v5.3.1
22+
uses: codecov/codecov-action@v5.4.0
2323
with:
2424
token: ${{ inputs.codecov_token }}
2525
files: coverage.xml

.github/actions/run-ats/ats.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ if [ ! -s codecov_ats/tests_to_run.txt ]; then
5050
echo "No tests to run, collecting from default tests"
5151
PYTEST_ARGS="${COLLECT_ARGS} ${DEFAULT_TESTS}"
5252
echo "Using args: ${PYTEST_ARGS}"
53-
TESTS_TO_RUN=$(PYTEST_ARGS=${PYTEST_ARGS} ./.circleci/collect.sh)
53+
TESTS_TO_RUN=$(PYTEST_ARGS=${PYTEST_ARGS} ./.github/actions/run-ats/collect.sh)
5454
echo "${TESTS_TO_RUN}" > codecov_ats/tests_to_run.txt
5555
run_count=1
5656
echo "Added ${TESTS_TO_RUN} as fallback. New run count: $run_count"

.github/actions/run-ats/collect.sh

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
#!/usr/bin/env bash
2+
TESTS_TO_RUN=$(uv run --frozen pytest --collect-only ${PYTEST_ARGS} -q --disable-warnings --no-summary --no-header)
3+
TESTS_TO_RUN=$(echo "${TESTS_TO_RUN}" | head -n -2)
4+
echo $TESTS_TO_RUN

.github/workflows/auto-release.yml

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,40 @@ jobs:
3535
env:
3636
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
3737

38+
generate-changelog:
39+
if: ${{ needs.semantic-version.outputs.release-tag }}
40+
needs: semantic-version
41+
name: Generate Changelog
42+
runs-on: ubuntu-latest
43+
environment: auto-release
44+
permissions:
45+
contents: write
46+
steps:
47+
- uses: actions/checkout@v4
48+
with:
49+
fetch-depth: 0
50+
token: ${{ secrets.GHA_TOKEN }}
51+
52+
- name: Setup backend
53+
uses: ./.github/actions/setup-environment
54+
55+
- name: Generate changelog
56+
env:
57+
OPEN_AI_TOKEN: ${{ secrets.OPEN_AI_TOKEN }}
58+
run: uv run python src/codegen/gscli/cli.py generate changelog --openai-key ${{ secrets.OPEN_AI_TOKEN }}
59+
60+
- name: Commit changes
61+
run: |
62+
git config --local user.email "github-actions[bot]@users.noreply.github.com"
63+
git config --local user.name "github-actions[bot]"
64+
git add docs/changelog/changelog.mdx
65+
git diff --staged --quiet || git commit -m "update changelog"
66+
67+
- name: Push changes
68+
uses: ad-m/github-push-action@master
69+
with:
70+
branch: ${{ github.ref }}
71+
3872
release:
3973
if: ${{ needs.semantic-version.outputs.release-tag }}
4074
needs: semantic-version

.github/workflows/generate-docs.yml

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
name: Generate Documentation
2+
3+
on:
4+
push:
5+
branches:
6+
- develop
7+
8+
permissions:
9+
contents: write # Need write permission to commit changes
10+
11+
jobs:
12+
generate-docs:
13+
environment: auto-release
14+
runs-on: ubuntu-latest
15+
steps:
16+
- uses: actions/checkout@v4
17+
with:
18+
fetch-depth: 0
19+
token: ${{ secrets.GHA_TOKEN }}
20+
21+
- name: Setup backend
22+
uses: ./.github/actions/setup-environment
23+
24+
- name: Generate API reference
25+
run: uv run python src/codegen/gscli/cli.py generate docs
26+
27+
- name: Generate System Prompt
28+
run: uv run python src/codegen/gscli/cli.py generate system-prompt
29+
30+
- name: Commit changes
31+
run: |
32+
git config --local user.email ${{ secrets.DOCS_USER_EMAIL }}
33+
git config --local user.name ${{ secrets.DOCS_USER_NAME }}
34+
git add docs/ src/codegen/sdk/system-prompt.txt
35+
git diff --staged --quiet || git commit -m "docs: updated API reference"
36+
37+
- name: Push changes
38+
uses: ad-m/github-push-action@master
39+
with:
40+
branch: ${{ github.ref }}

.github/workflows/pre-commit.yml

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,15 @@ jobs:
1212
pre-commit:
1313
runs-on: ubuntu-latest
1414
timeout-minutes: 10
15+
env:
16+
REPO_SCOPED_TOKEN: ${{ secrets.REPO_SCOPED_TOKEN }}
1517

1618
steps:
1719
- name: Check out the repo
1820
uses: actions/checkout@v4
1921
with:
2022
fetch-depth: 0
21-
repository: ${{ github.event.pull_request.head.repo.full_name }}
22-
ref: ${{ github.event.pull_request.head.ref }}
23-
token: ${{ secrets.REPO_SCOPED_TOKEN }}
23+
token: ${{ env.REPO_SCOPED_TOKEN || github.token }}
2424

2525
- name: Setup environment
2626
uses: ./.github/actions/setup-environment
@@ -36,12 +36,9 @@ jobs:
3636

3737
- run: uv run --frozen pre-commit run --show-diff-on-failure --color=always --all-files --source ${{ github.event.pull_request.base.sha || github.event.before }} --origin ${{ github.event.pull_request.head.sha || github.event.after }}
3838
shell: bash
39-
env:
40-
SKIP: circleci_validate
4139

4240
- uses: stefanzweifel/git-auto-commit-action@v5
43-
# Always commit changes even if pre-commit failed
44-
if: always() && github.event_name == 'pull_request'
41+
if: ${{ always() && env.REPO_SCOPED_TOKEN && github.event_name == 'pull_request' }}
4542
with:
4643
commit_message: "Automated pre-commit update"
4744
push_options: "--no-verify"

.github/workflows/release.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ jobs:
5252
with:
5353
fetch-depth: 0
5454
ref: ${{ inputs.release-tag || github.event.pull_request.head.ref || github.ref }}
55+
repository: ${{ github.event.pull_request.head.repo.full_name || github.event.repository.full_name }}
5556

5657
- name: Install UV
5758
uses: astral-sh/[email protected]
@@ -64,6 +65,7 @@ jobs:
6465
cache-suffix: 3.${{ matrix.python }}
6566

6667
- name: Fetch tags
68+
if: ${{ inputs.release-tag || startsWith(github.ref, 'refs/tags/') }}
6769
run: |
6870
git branch
6971
git fetch --depth=1 origin +refs/tags/*:refs/tags/*

.github/workflows/unit-tests.yml renamed to .github/workflows/test.yml

Lines changed: 34 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,37 @@
1-
name: Unit Tests
1+
name: Tests
22

33
on:
44
push:
55
branches:
66
- "develop"
7-
pull_request:
7+
pull_request_target:
88
types: [ opened, synchronize, reopened, labeled ]
99
branches:
1010
- "develop"
1111
workflow_dispatch:
1212

1313
jobs:
14+
access-check:
15+
runs-on: ubuntu-latest
16+
steps:
17+
- uses: actions-cool/check-user-permission@v2
18+
with:
19+
require: write
20+
username: ${{ github.triggering_actor }}
21+
error-if-missing: true
22+
1423
unit-tests:
24+
needs: access-check
1525
runs-on: ubuntu-latest-8
1626
steps:
1727
- uses: actions/checkout@v4
1828
with:
1929
fetch-depth: 0
30+
ref: ${{ github.event.pull_request.head.sha }}
31+
2032
- name: Setup environment
2133
uses: ./.github/actions/setup-environment
34+
2235
- name: Run ATS and Tests
2336
uses: ./.github/actions/run-ats
2437
timeout-minutes: 15
@@ -30,6 +43,7 @@ jobs:
3043
codecov_flags: unit-tests
3144

3245
codemod-tests:
46+
needs: access-check
3347
# TODO: re-enable when this check is a develop required check
3448
if: false
3549
runs-on: ubuntu-latest-32
@@ -48,10 +62,15 @@ jobs:
4862
name: "Codemod tests ${{matrix.size}}: Sync Graph=${{matrix.sync_graph}}"
4963
steps:
5064
- uses: actions/checkout@v4
65+
with:
66+
ref: ${{ github.event.pull_request.head.sha }}
67+
5168
- name: Setup environment
5269
uses: ./.github/actions/setup-environment
70+
5371
- name: Cache oss-repos
5472
uses: ./.github/actions/setup-oss-repos
73+
5574
- name: Run ATS and Tests
5675
uses: ./.github/actions/run-ats
5776
timeout-minutes: 15
@@ -66,11 +85,14 @@ jobs:
6685
GITHUB_WORKSPACE: $GITHUB_WORKSPACE
6786

6887
parse-tests:
69-
runs-on: ubuntu-latest-32
88+
needs: access-check
7089
if: contains(github.event.pull_request.labels.*.name, 'parse-tests') || github.event_name == 'push' || github.event_name == 'workflow_dispatch'
71-
environment: parse-tests
90+
runs-on: ubuntu-latest-32
7291
steps:
7392
- uses: actions/checkout@v4
93+
with:
94+
ref: ${{ github.event.pull_request.head.sha }}
95+
7496
- name: Setup environment
7597
uses: ./.github/actions/setup-environment
7698

@@ -91,10 +113,12 @@ jobs:
91113
-n auto \
92114
-o junit_suite_name="${{github.job}}" \
93115
tests/integration/codemod/test_parse.py
116+
94117
- uses: ./.github/actions/report
95118
with:
96119
flag: no-flag
97120
codecov_token: ${{ secrets.CODECOV_TOKEN }}
121+
98122
- name: Notify parse tests failure
99123
uses: slackapi/[email protected]
100124
if: failure() && github.event_name == 'push' && false
@@ -132,11 +156,16 @@ jobs:
132156
}
133157
134158
integration-tests:
159+
needs: access-check
135160
runs-on: ubuntu-latest-16
136161
steps:
137162
- uses: actions/checkout@v4
163+
with:
164+
ref: ${{ github.event.pull_request.head.sha }}
165+
138166
- name: Setup environment
139167
uses: ./.github/actions/setup-environment
168+
140169
- name: Test with pytest
141170
timeout-minutes: 5
142171
env:
@@ -147,6 +176,7 @@ jobs:
147176
-n auto \
148177
-o junit_suite_name="${{github.job}}" \
149178
tests/integration/codegen
179+
150180
- uses: ./.github/actions/report
151181
with:
152182
flag: integration-tests

CONTRIBUTING.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,10 @@ uv run pytest tests/unit -n auto
5151
uv run pytest tests/integration/codemod/test_codemods.py -n auto
5252
```
5353

54+
> [!TIP]
55+
>
56+
> - If on Linux the error `OSError: [Errno 24] Too many open files` appears then you might want to increase your _ulimit_
57+
5458
## Pull Request Process
5559

5660
1. Fork the repository and create your branch from `develop`.

Dockerfile

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ ARG CODEGEN_BOT_GHE_TOKEN=""
33
FROM ghcr.io/astral-sh/uv:python${PYTHON_VERSION}-bookworm-slim AS base_uv
44
ENV UV_COMPILE_BYTECODE=1 UV_LINK_MODE=copy
55
ENV GITHUB_WORKSPACE=/workspace
6-
LABEL com.circleci.preserve-entrypoint=true
76
## Change the working directory to the `codegen-sdk` directory
87
FROM base_uv AS install-tools
98
RUN apt-get update && apt-get install -y build-essential curl git

README.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,16 @@ See [Getting Started](https://docs.codegen.com/introduction/getting-started) for
7979
from codegen import Codebase
8080
```
8181

82+
## Troubleshooting
83+
84+
Having issues? Here are some common problems and their solutions:
85+
86+
- **I'm hitting an UV error related to `[[ packages ]]`**: This means you're likely using an outdated version of UV. Try updating to the latest version with: `uv self update`.
87+
- **I'm hitting an error about `No module named 'codegen.sdk.extensions.utils'`**: The compiled cython extensions are out of sync. Update them with `uv sync --reinstall-package codegen`.
88+
- **I'm hitting a `RecursionError: maximum recursion depth exceeded` error while parsing my codebase**: If you are using python 3.12, try upgrading to 3.13. If you are already on 3.13, try upping the recursion limit with `sys.setrecursionlimit(10000)`.
89+
90+
If you run into additional issues not listed here, please [join our slack community](https://community.codegen.com) and we'll help you out!
91+
8292
## Resources
8393

8494
- [Docs](https://docs.codegen.com)

0 commit comments

Comments
 (0)