Skip to content

Commit e7c85cb

Browse files
caroljung-cgcodegen-bot
and
codegen-bot
authored
CG-10473: Generate function_imports on build (#143)
# Motivation Updates all codegen import lines used by codemod runs on cloud # Content <!-- Please include a summary of the change --> # Testing <!-- How was the change tested? --> # Please check the following before marking your PR as ready for review - [x] I have added tests for my changes - [x] I have updated the documentation or added new documentation as needed - [x] I have read and agree to the [Contributor License Agreement](../CLA.md) --------- Co-authored-by: codegen-bot <[email protected]>
1 parent a7dd810 commit e7c85cb

19 files changed

+29
-51
lines changed

.circleci/ats.sh

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,4 +33,3 @@ if [ ! -s codecov_ats/tests_to_run.txt ]; then
3333
run_count=1
3434
echo "Added ${TESTS_TO_RUN} as fallback. New run count: $run_count"
3535
fi
36-

.circleci/config.yml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -528,6 +528,3 @@ workflows:
528528
requires:
529529
- linux-wheels
530530
- osx-wheels
531-
532-
533-

.github/codecov.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,4 +71,3 @@ cli:
7171
- "--verbose"
7272
- "-n=auto"
7373
python_path: ".venv/bin/python"
74-

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,4 +65,4 @@ graph-sitter-types/typings/**
6565
coverage.json
6666
tests/integration/verified_codemods/codemod_data/repo_commits.json
6767
.codegen/*
68-
.benchmarks/*
68+
.benchmarks/*

.lfsconfig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
[lfs]
2-
url = [email protected]:codegen-sh/graph-sitter-private.git
2+
url = [email protected]:codegen-sh/graph-sitter-private.git

.pre-commit-config.yaml

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ repos:
4343
exclude_types: [mdx, pyi]
4444
- id: check-yaml
4545
- id: end-of-file-fixer
46-
files: .*/expected_diff.patch
46+
exclude: (src/codemods/eval)|(tests/unit/skills/snapshots)|(tests/unit/codegen/sdk/output)|(tests/integration/verified_codemods)|(docs/)
4747
- id: check-merge-conflict
4848

4949
- repo: https://github.com/python-jsonschema/check-jsonschema
@@ -80,6 +80,13 @@ repos:
8080
entry: scripts/disallowed-words-check.sh
8181
language: script
8282
files: '' # Check all files
83+
- id: generate-runner-imports
84+
name: Generate Runner Imports
85+
entry: bash -c "uv run --frozen python -m codegen.gscli.main generate runner-imports src/codegen/shared/compilation/function_imports.py"
86+
language: system
87+
pass_filenames: false
88+
always_run: true
89+
8390
- repo: https://github.com/renovatebot/pre-commit-hooks
8491
rev: 39.120.4
8592
hooks:

CONTRIBUTING.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,4 +69,3 @@ git push origin v0.YOUR_VERSION
6969
```
7070

7171
This will trigger a release job to build this new version.
72-

mypy.ini

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,4 +49,3 @@ exclude = (?x)(
4949
| tests/unit/skills/snapshots/*
5050
)
5151
plugins = pydantic.mypy
52-

pyproject.toml

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -153,14 +153,7 @@ max-line-length = 200
153153

154154
[tool.ruff]
155155
line-length = 200
156-
exclude = [
157-
"app/codemod/compilation/function_imports.py", # generated import list to compile uesr code with
158-
'codegen_tests/**/expected*/**',
159-
'codegen_tests/**/original/**',
160-
'codegen_tests/projects/**/codebase/**',
161-
'docs/**',
162-
'scripts/Debugging/**',
163-
]
156+
exclude = ["src/codegen/shared/compilation/function_imports.py", 'docs/**']
164157

165158
lint.select = ["F", "E", "W", "I", "UP", "D", "RUF", "DTZ"]
166159
lint.ignore = [
@@ -192,9 +185,8 @@ lint.exclude = [
192185
] # disable just linting for notebooks (allow for formatting)
193186
lint.pydocstyle.convention = "google"
194187
[tool.ruff.lint.isort]
195-
known-first-party = ["app"]
196-
known-third-party = ["git"]
197-
#known-local-folder=[]
188+
known-first-party = ["codegen"]
189+
198190
[tool.coverage.run]
199191
branch = true
200192
plugins = ["Cython.Coverage"]

scripts/setup-lfs.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@
22
./scripts/install-deps.sh
33

44
git lfs install
5-
git lfs pull
5+
git lfs pull

scripts/setup.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,4 @@ uv tool update-shell
66
uv venv && source .venv/bin/activate
77
uv sync
88
pre-commit install
9-
pre-commit install-hooks
9+
pre-commit install-hooks

src/codegen/gsbuild/build.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,5 +21,4 @@ class SpecialBuildHook(BuildHookInterface):
2121
def initialize(self, version: str, build_data: dict[str, Any]) -> None:
2222
file = Path(self.root) / "src" / "codegen" / "sdk" / "__init__.py"
2323
update_init_file(file)
24-
2524
build_data["artifacts"].append(f"/{file}")

src/codegen/gscli/__init__.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +0,0 @@
1-

src/codegen/gscli/generate/commands.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -186,3 +186,7 @@ def generate_codegen_sdk_docs(docs_dir: str) -> None:
186186
json.dump(mint_data, mint_file, indent=2)
187187

188188
print(colored("Updated mint.json with new page sets", "green"))
189+
190+
191+
if __name__ == "__main__":
192+
generate()

src/codegen/gscli/generate/runner_imports.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
CODEGEN_IMPORTS = """
1515
from codegen.git.models.codemod_context import CodemodContext
1616
from codegen.git.models.github_named_user_context import GithubNamedUserContext
17+
from codegen.git.models.pr_options import PROptions
1718
from codegen.git.models.pr_part_context import PRPartContext
1819
from codegen.git.models.pull_request_context import PullRequestContext
1920
"""
@@ -34,13 +35,16 @@
3435
{gs_public_imports}
3536
""".strip()
3637

37-
IMPORT_FILE_TEMPLATE = '''
38-
# This file is auto-generated, do not modify manually. Edit this in codegen-backend/cli/generate/runner_imports.py.
38+
IMPORT_FILE_TEMPLATE = (
39+
'''
40+
# This file is auto-generated, do not modify manually. Edit this in src/codegen/gscli/generate/runner_imports.py.
3941
def get_generated_imports():
4042
return """
4143
{import_str}
4244
"""
4345
'''.strip()
46+
+ "\n"
47+
)
4448

4549

4650
def get_runner_imports(include_codegen=True, include_private_imports: bool = True) -> str:

src/codegen/runner/sandbox/executor.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ async def find_flag_groups(self, code_flags: list[CodeFlag], grouping_config: Gr
5353

5454
# =====[ Group the code flags ]=====
5555
logger.info(f"> Grouping CodeFlags by config: {grouping_config}")
56-
grouper = get_grouper_by_group_by(grouping_config.group_by, repo_id=self.codebase.op.repo_config.id)
56+
grouper = get_grouper_by_group_by(grouping_config.group_by)
5757
groups = grouper.create_all_groups(flags=code_flags, repo_operator=self.codebase.op)
5858
logger.info(f"> Created {len(groups)} groups")
5959
return groups

src/codegen/sdk/core/global_context.py

Lines changed: 0 additions & 20 deletions
This file was deleted.

src/codegen/shared/compilation/README.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,3 @@ This includes:
55
- Catching and logging any compilation errors
66
- Monkey patching built-ins like print
77
- etc
8-

src/codegen/shared/compilation/function_imports.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# This file is auto-generated, do not modify manually. Edit this in codegen-backend/cli/generate/runner_imports.py.
1+
# This file is auto-generated, do not modify manually. Edit this in src/codegen/gscli/generate/runner_imports.py.
22
def get_generated_imports():
33
return """
44
# External imports
@@ -12,10 +12,11 @@ def get_generated_imports():
1212
1313
from codegen.git.models.codemod_context import CodemodContext
1414
from codegen.git.models.github_named_user_context import GithubNamedUserContext
15+
from codegen.git.models.pr_options import PROptions
1516
from codegen.git.models.pr_part_context import PRPartContext
1617
from codegen.git.models.pull_request_context import PullRequestContext
1718
18-
from codegen.sdk.codebase.control_flow import StopCodemodException
19+
from codegen.shared.exceptions.control_flow import StopCodemodException
1920
2021
# GraphSitter imports (public)
2122
from codegen.sdk.codebase.flagging.enums import FlagKwargs

0 commit comments

Comments
 (0)