Skip to content

Commit 17f84e7

Browse files
caroljung-cgcodegen-bot
andauthored
CG-10491: Move skills testing + utils into tests/ (#96)
# Motivation <!-- Why is this change necessary? --> # 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 50c10c6 commit 17f84e7

File tree

122 files changed

+301
-557
lines changed

Some content is hidden

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

122 files changed

+301
-557
lines changed

.circleci/config.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ commands:
6161
if [ "<<parameters.extra_repos>>" = "true" ]; then
6262
EXTRA_REPOS_ARG="--extra-repos"
6363
fi
64-
uv run --frozen gs codemod clone-repos ${EXTRA_REPOS_ARG} --token ${CODEGEN_BOT_GHE_TOKEN} --clean-cache
64+
uv run --frozen python -m tests.shared.codemod.commands clone-repos ${EXTRA_REPOS_ARG} --token ${CODEGEN_BOT_GHE_TOKEN} --clean-cache
6565
- save_cache:
6666
paths:
6767
- $GITHUB_WORKSPACE
@@ -70,15 +70,15 @@ commands:
7070
steps:
7171
- run:
7272
command: |
73-
uv run --frozen gs codemod fetch-verified-codemods --cli-api-key ${PROD_CLI_API_KEY}
73+
uv run --frozen python -m tests.shared.codemod.commands fetch-verified-codemods --cli-api-key ${PROD_CLI_API_KEY}
7474
cache-verified-codemod-repos:
7575
steps:
7676
- restore_cache:
7777
keys:
7878
- v1-verified-codemod-repos-{{ checksum "tests/integration/verified_codemods/codemod_data/repo_commits.json" }}-{{.Environment.CIRCLE_NODE_INDEX}}-{{.Environment.CIRCLE_NODE_TOTAL}}
7979
- run:
8080
command: |
81-
uv run --frozen gs codemod clone-repos --verified-codemod-repos --token ${CODEGEN_BOT_GHE_TOKEN}
81+
uv run --frozen python -m tests.shared.codemod.commands clone-repos --verified-codemod-repos --token ${CODEGEN_BOT_GHE_TOKEN}
8282
- save_cache:
8383
paths:
8484
- $GITHUB_WORKSPACE

.pre-commit-config.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ repos:
1919
hooks:
2020
- id: biome-check
2121
additional_dependencies: ["@biomejs/[email protected]"]
22-
exclude: (src/codemods/eval)|(tests/unit/codegen/sdk/skills)|(tests/unit/codegen/sdk/output)|(tests/integration/verified_codemods)|(docs/samples)
22+
exclude: (src/codemods/eval)|(tests/unit/skills/snapshots)|(tests/unit/codegen/sdk/output)|(tests/integration/verified_codemods)|(docs/samples)
2323

2424
- repo: https://github.com/MarcoGorelli/cython-lint
2525
rev: v0.16.6

Dockerfile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ RUN --mount=type=cache,target=/root/.cache/uv \
3434
uv run pre-commit install-hooks
3535
FROM base-image AS extra-repos
3636
ARG CODEGEN_BOT_GHE_TOKEN=""
37-
RUN uv run gs codemod clone-repos --clean-cache --extra-repos --token ${CODEGEN_BOT_GHE_TOKEN}
37+
RUN uv run python -m tests.shared.codemod.commands clone-repos --clean-cache --extra-repos --token ${CODEGEN_BOT_GHE_TOKEN}
3838
FROM base-image AS oss-repos
3939
ARG CODEGEN_BOT_GHE_TOKEN=""
40-
RUN uv run gs codemod clone-repos --clean-cache --token ${CODEGEN_BOT_GHE_TOKEN}
40+
RUN uv run python -m tests.shared.codemod.commands clone-repos --clean-cache --token ${CODEGEN_BOT_GHE_TOKEN}

conftest.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import logging
22
import os
33

4-
from codegen.sdk.testing.models import Size
4+
from tests.shared.codemod.models import Size
55

66

77
def find_dirs_to_ignore(start_dir, prefix):

mypy.ini

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ exclude = (?x)(
4646
| scripts/.*
4747
| .*/codemods/.*/test_.*/
4848
| ^/expected/
49-
| src/codegen/sdk/skills/*
49+
| tests/unit/skills/snapshots/*
5050
)
5151
plugins = pydantic.mypy
5252

pyproject.toml

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,19 +23,14 @@ dependencies = [
2323
"networkx>=3.4.1",
2424
"wrapt<2.0.0,>=1.16.0",
2525
"pyright<2.0.0,>=1.1.372",
26-
"jsbeautifier<2.0.0,>=1.15.1",
2726
"watchfiles<1.1.0,>=1.0.0",
2827
"loguru<1.0.0,>=0.7.2",
2928
"rich<14.0.0,>=13.7.1",
30-
"inflection<1.0.0,>=0.5.1",
3129
"pydantic<3.0.0,>=2.9.2",
3230
"docstring-parser<1.0,>=0.16",
3331
"plotly<6.0.0,>=5.24.0",
3432
"humanize<5.0.0,>=4.10.0",
35-
"autoflake>=2.3.1",
36-
"black>=24.8.0",
3733
"pytest-snapshot>=0.9.0",
38-
"isort>=5.13.2",
3934
"anthropic==0.23.1",
4035
"pyjson5==1.6.8",
4136
"mini-racer>=0.12.4",
@@ -52,7 +47,6 @@ dependencies = [
5247
"hatchling>=1.25.0",
5348
"pyinstrument>=5.0.0",
5449
"pip>=24.3.1", # This is needed for some NPM/YARN/PNPM post-install scripts to work!
55-
"emoji>=2.14.0",
5650
"rich-click>=1.8.5",
5751
"python-dotenv>=1.0.1",
5852
"giturlparse",
@@ -110,6 +104,12 @@ dev-dependencies = [
110104
"deptry>=0.22.0",
111105
"cibuildwheel[uv]>=2.22.0",
112106
"sybil[pytest]>=9.0.0",
107+
"jsbeautifier<2.0.0,>=1.15.1",
108+
"inflection<1.0.0,>=0.5.1",
109+
"autoflake>=2.3.1",
110+
"black>=24.8.0",
111+
"isort>=5.13.2",
112+
"emoji>=2.14.0",
113113
]
114114
keyring-provider = "subprocess"
115115
#extra-index-url = ["https://[email protected]/pypi/codegen/simple/"]

src/codegen/gscli/generate/commands.py

Lines changed: 0 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,13 @@
55
import shutil
66

77
import click
8-
import inflection
98
from termcolor import colored
109

1110
from codegen.gscli.generate.runner_imports import _generate_runner_imports
1211
from codegen.gscli.generate.utils import LanguageType, generate_builtins_file
1312
from codegen.sdk.code_generation.codegen_sdk_codebase import get_codegen_sdk_codebase
1413
from codegen.sdk.code_generation.doc_utils.generate_docs_json import generate_docs_json
15-
from codegen.sdk.code_generation.doc_utils.skills import format_all_skills
1614
from codegen.sdk.code_generation.mdx_docs_generation import render_mdx_page_for_class
17-
from codegen.sdk.python import PyClass
18-
from codegen.sdk.skills.core.utils import get_all_skills, get_guide_skills_dict
1915

2016
logger = logging.getLogger(__name__)
2117

@@ -113,26 +109,6 @@ def generate_docs(docs_dir: str) -> None:
113109
# generate_guides(docs_dir)
114110

115111

116-
def generate_guides(docs_dir: str):
117-
"""Updates code snippets in the guides with the latest skill implementations"""
118-
guide_skills = get_guide_skills_dict()
119-
for guide_relative_path in guide_skills:
120-
guide_file_path = os.path.join(docs_dir, "api-reference", str(guide_relative_path) + ".mdx")
121-
122-
with open(guide_file_path) as f:
123-
file_content = f.read()
124-
125-
for skill in guide_skills[guide_relative_path]:
126-
# Perform the regex search and replace
127-
target_name = inflection.camelize(skill.name)
128-
pattern = get_snippet_pattern(target_name)
129-
replacement = f"[//]: # (--{target_name}--)\n[//]: # (--{AUTO_GENERATED_COMMENT}--)\n\n{skill.generate_snippet()}"
130-
file_content = re.sub(pattern, replacement, file_content, flags=re.DOTALL)
131-
132-
with open(guide_file_path, "w") as f:
133-
f.write(file_content)
134-
135-
136112
def get_snippet_pattern(target_name: str) -> str:
137113
pattern = rf"\[//\]: # \(--{re.escape(target_name)}--\)\s*(?:\[//\]: # \(--{re.escape(AUTO_GENERATED_COMMENT)}--\)\s*)?"
138114
pattern += CODE_SNIPPETS_REGEX
@@ -210,29 +186,3 @@ def generate_codegen_sdk_docs(docs_dir: str) -> None:
210186
json.dump(mint_data, mint_file, indent=2)
211187

212188
print(colored("Updated mint.json with new page sets", "green"))
213-
214-
215-
def generate_skills_docs(docs_dir: str) -> None:
216-
"""Generates docs for all skills"""
217-
print(colored("Generating skills docs", "green"))
218-
# Interim Modification: We need to refactor all skills
219-
skills = [skill for skill in get_all_skills() if not skill.guide]
220-
skills_doc = format_all_skills(skills)
221-
222-
# =====[ Write the skills docs to the file system ]=====
223-
core_dir = os.path.join(docs_dir, "codebase-sdk", "examples")
224-
file_path = os.path.join(core_dir, "skills.mdx")
225-
print(colored(f"> Writing to {file_path}", "green"))
226-
open(file_path, "w").write(skills_doc)
227-
228-
229-
def document_skill(skill: PyClass):
230-
return "skill" in [decorator.name for decorator in skill.decorators]
231-
232-
233-
def filter_class(cls: PyClass):
234-
for method in cls.methods:
235-
for decorator in method.decorators:
236-
if decorator.name == "skill_impl" and "external=True" in decorator.source:
237-
return True
238-
return False

src/codegen/gscli/main.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33

44
import click
55

6-
from codegen.gscli.codemod.commands import codemod
76
from codegen.gscli.generate.commands import generate
87

98

@@ -13,7 +12,6 @@ def cli() -> None:
1312

1413

1514
# ============= Import all command groups =============
16-
cli.add_command(codemod)
1715
cli.add_command(generate)
1816

1917

src/codegen/sdk/code_generation/doc_utils/skills.py

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

src/codegen/sdk/skills/core/__init__.py

Whitespace-only changes.

0 commit comments

Comments
 (0)