Skip to content

Rename codemod3 + nit cleanup #54

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
merged 1 commit into from
Jan 24, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/codegen/runner/sandbox/middlewares.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

from codegen.runner.models.apis import ServerInfo
from codegen.runner.sandbox.runner import SandboxRunner
from codegen.utils.compilation.exceptions import UserCodeException
from codegen.utils.exceptions.compilation import UserCodeException

logger = logging.getLogger(__name__)

Expand Down
4 changes: 2 additions & 2 deletions src/codegen/sdk/code_generation/doc_utils/skills.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@
import inflection
from typing_extensions import deprecated

from codegen.sdk.codemod import Codemod3
from codegen.sdk.core.codebase import Codebase
from codegen.sdk.enums import ProgrammingLanguage
from codegen.sdk.python import PyClass
from codegen.sdk.python.function import PyFunction
from codegen.sdk.skills.core.skill import Skill
from codegen.sdk.skills.core.skill_implementation import SkillImplementation
from codegen.sdk.skills.core.utils import get_all_evaluation_skills
from codemods.canonical.codemod import Codemod


def remove_leading_tab_or_spaces(text: str) -> str:
Expand Down Expand Up @@ -108,7 +108,7 @@ def format_all_skills(skill_classes: list[Skill]) -> str:

# Step 2: Format each skill into an .mdx compatible string
for skill in sorted_skills:
if issubclass(skill, Codemod3):
if issubclass(skill, Codemod):
continue
sk_inst = skill
formatted_skills.append(sk_inst.generate_snippet(skill_doc=True))
Expand Down
10 changes: 0 additions & 10 deletions src/codegen/sdk/exceptions.py

This file was deleted.

2 changes: 1 addition & 1 deletion src/codegen/sdk/python/statements/attribute.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@
from codegen.sdk.core.autocommit import reader
from codegen.sdk.core.interfaces.editable import Editable
from codegen.sdk.core.statements.attribute import Attribute
from codegen.sdk.exceptions import APINotApplicableForLanguageError
from codegen.sdk.python.assignment import PyAssignment
from codegen.sdk.python.statements.assignment_statement import PyAssignmentStatement
from codegen.utils.decorators.docs import noapidoc, py_apidoc
from codegen.utils.exceptions.api import APINotApplicableForLanguageError

if TYPE_CHECKING:
from codegen.sdk.python.class_definition import PyClass
Expand Down
4 changes: 2 additions & 2 deletions src/codegen/sdk/testing/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
except (FileNotFoundError, json.decoder.JSONDecodeError):
REPO_ID_TO_URL = {}
if TYPE_CHECKING:
from codegen.sdk.codemod import Codemod3
from codemods.canonical.codemod import Codemod


@unique
Expand Down Expand Up @@ -78,7 +78,7 @@ def to_op(self, name: str, token: str | None) -> LocalRepoOperator:

@dataclass
class CodemodMetadata:
codemod: type["Codemod3"]
codemod: type["Codemod"]
category: str
directory: Path
company: str | None = None
Expand Down
10 changes: 3 additions & 7 deletions src/codegen/sdk/testing/test_discovery.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,16 @@
import textwrap
from collections.abc import Generator, Iterator
from pathlib import Path
from typing import TYPE_CHECKING

import emoji
from loguru import logger

from codegen.gscli.generate.runner_imports import get_runner_imports
from codegen.sdk.codemod import Codemod3
from codegen.sdk.enums import ProgrammingLanguage
from codegen.sdk.testing.constants import DIFF_FILEPATH
from codegen.sdk.testing.models import BASE_PATH, CODEMOD_PATH, REPO_ID_TO_URL, TEST_DIR, VERIFIED_CODEMOD_DATA_DIR, VERIFIED_CODEMOD_DIFFS, ClonedRepoTestCase, CodemodMetadata, Repo, Size
from codegen.sdk.testing.verified_codemod_utils import CodemodAPI, RepoCodemodMetadata, SkillTestConfig, anonymize_id

if TYPE_CHECKING:
pass
from codemods.canonical.codemod import Codemod


def find_repos(
Expand Down Expand Up @@ -65,7 +61,7 @@ def codemods_from_dir(codemod_dir: Path) -> Iterator[CodemodMetadata]:
import_path = str(relative).removeprefix("src/").replace("/", ".")
mod = importlib.import_module(import_path)
for name, value in inspect.getmembers(mod, inspect.isclass):
if issubclass(value, Codemod3) and name != "Codemod3":
if issubclass(value, Codemod) and name != "Codemod":
yield CodemodMetadata(codemod=value, category=codemod_dir.parent.name, directory=codemod_dir)


Expand Down Expand Up @@ -163,7 +159,7 @@ def generate_codemod_test_cases(repo: Repo, codemods: list[CodemodMetadata], cod
# add the execute method to the codemod
execute_func = create_function_from_string("execute", codemod_data)
name = escape_codemod_name(codemod_data.name) + "-" + str(codemod_data.codemod_id)
codemod = Codemod3(name=name, execute=execute_func)
codemod = Codemod(name=name, execute=execute_func)

codemod_metadata = CodemodMetadata(
codemod=codemod,
Expand Down
2 changes: 1 addition & 1 deletion src/codegen/utils/compilation/codeblock_validation.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import re

from codegen.utils.compilation.exceptions import DangerousUserCodeException
from codegen.utils.exceptions.compilation import DangerousUserCodeException


def check_for_dangerous_operations(user_code: str) -> None:
Expand Down
2 changes: 1 addition & 1 deletion src/codegen/utils/compilation/function_compilation.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import traceback
from collections.abc import Callable

from codegen.utils.compilation.exceptions import InvalidUserCodeException
from codegen.utils.exceptions.compilation import InvalidUserCodeException

logger = logging.getLogger(__name__)

Expand Down
2 changes: 2 additions & 0 deletions src/codegen/utils/exceptions/api.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
class APINotApplicableForLanguageError(Exception):
pass
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
from codegen.sdk.codemod import Codemod3
from codegen.sdk.core.codebase import Codebase
from codegen.sdk.enums import ProgrammingLanguage
from codegen.sdk.skills.core.skill import Skill
from codegen.sdk.skills.core.utils import skill, skill_impl
from codegen.sdk.writer_decorators import canonical
from codemods.canonical.codemod import Codemod


@skill(
Expand All @@ -14,7 +14,7 @@
uid="d62a3590-14ef-4759-853c-39c5cf755ce5",
)
@canonical
class AddFunctionParameterTypeAnnotations(Codemod3, Skill):
class AddFunctionParameterTypeAnnotations(Codemod, Skill):
"""Adds type annotation for function parameters that takes in a 'db' parameter, which is a `SessionLocal` from `app.db`.
It also adds the necessary import if not already present.

Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
from codegen.sdk.codemod import Codemod3
from codegen.sdk.core.codebase import Codebase
from codegen.sdk.enums import ProgrammingLanguage
from codegen.sdk.skills.core.skill import Skill
from codegen.sdk.skills.core.utils import skill, skill_impl
from codegen.sdk.writer_decorators import canonical
from codemods.canonical.codemod import Codemod


@skill(
Expand All @@ -13,7 +13,7 @@
uid="302d8f7c-c848-4020-9dea-30e8e622d709",
)
@canonical
class AddInternalToNonExportedComponents(Codemod3, Skill):
class AddInternalToNonExportedComponents(Codemod, Skill):
"""This codemod renames all React function components that are not exported from their file to be suffixed with 'Internal'.

Example:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
from codegen.sdk.codemod import Codemod3
from codegen.sdk.core.codebase import Codebase
from codegen.sdk.enums import ProgrammingLanguage
from codegen.sdk.skills.core.skill import Skill
from codegen.sdk.skills.core.utils import skill, skill_impl
from codegen.sdk.writer_decorators import canonical
from codemods.canonical.codemod import Codemod


@skill(
Expand All @@ -14,7 +14,7 @@
uid="d1ece8d3-7da9-4696-9288-4087737e2952",
)
@canonical
class BangBangToBoolean(Codemod3, Skill):
class BangBangToBoolean(Codemod, Skill):
"""This codemod converts !!(expression) to Boolean(expression)"""

language = ProgrammingLanguage.TYPESCRIPT
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
from codegen.sdk.codemod import Codemod3
from codegen.sdk.core.codebase import Codebase
from codegen.sdk.enums import ProgrammingLanguage
from codegen.sdk.skills.core.skill import Skill
from codegen.sdk.skills.core.utils import skill, skill_impl
from codegen.sdk.writer_decorators import canonical
from codemods.canonical.codemod import Codemod


@skill(
Expand All @@ -14,7 +14,7 @@
uid="b2cd98af-d3c5-4e45-b396-e7abf06df924",
)
@canonical
class BuiltInTypeAnnotation(Codemod3, Skill):
class BuiltInTypeAnnotation(Codemod, Skill):
"""Replaces type annotations using typing module with builtin types.

Examples:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
from codegen.sdk.codemod import Codemod3
from codegen.sdk.core.codebase import Codebase
from codegen.sdk.enums import ProgrammingLanguage
from codegen.sdk.skills.core.skill import Skill
from codegen.sdk.skills.core.utils import skill, skill_impl
from codegen.sdk.writer_decorators import canonical
from codemods.canonical.codemod import Codemod


@skill(
Expand All @@ -14,7 +14,7 @@
uid="ab5879e3-e3ea-4231-b928-b756473f290d",
)
@canonical
class ChangeJSXElementName(Codemod3, Skill):
class ChangeJSXElementName(Codemod, Skill):
"""This codemod updates specific JSX elements inside of React components

In particular, this:
Expand Down
4 changes: 2 additions & 2 deletions src/codemods/canonical/classnames_to_backtick.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
from codegen.sdk.codemod import Codemod3
from codegen.sdk.core.codebase import Codebase
from codegen.sdk.enums import ProgrammingLanguage
from codegen.sdk.skills.core.skill import Skill
from codegen.sdk.skills.core.utils import skill, skill_impl
from codegen.sdk.writer_decorators import canonical
from codemods.canonical.codemod import Codemod


@skill(
Expand All @@ -14,7 +14,7 @@
uid="bf22f4d7-a93a-458f-be78-470c24487d4c",
)
@canonical
class ClassNamesToBackTick(Codemod3, Skill):
class ClassNamesToBackTick(Codemod, Skill):
"""This Codemod converts all `classNames="..."` props in JSX elements to use backticks.

Example:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from collections.abc import Callable


class Codemod3:
class Codemod:
execute: Callable | None = None

def __init__(self, name: str | None = None, execute: Callable | None = None, *args, **kwargs):
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
from codegen.sdk.codemod import Codemod3
from codegen.sdk.core.codebase import Codebase
from codegen.sdk.core.expressions.generic_type import GenericType
from codegen.sdk.enums import ProgrammingLanguage
from codegen.sdk.skills.core.skill import Skill
from codegen.sdk.skills.core.utils import skill, skill_impl
from codegen.sdk.writer_decorators import canonical
from codemods.canonical.codemod import Codemod


@skill(
Expand All @@ -15,7 +15,7 @@
uid="97184a15-5992-405b-be7b-30122556fe8b",
)
@canonical
class ConvertArrayTypeToSquareBracket(Codemod3, Skill):
class ConvertArrayTypeToSquareBracket(Codemod, Skill):
"""This codemod converts types of the form `Array<T>` to `T[]`, while avoiding edge cases like nested Array types"""

language = ProgrammingLanguage.TYPESCRIPT
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
from codegen.sdk.codemod import Codemod3
from codegen.sdk.core.codebase import Codebase
from codegen.sdk.enums import ProgrammingLanguage
from codegen.sdk.skills.core.skill import Skill
from codegen.sdk.skills.core.utils import skill, skill_impl
from codegen.sdk.writer_decorators import canonical
from codemods.canonical.codemod import Codemod


@skill(
Expand All @@ -14,7 +14,7 @@
uid="b200fb43-dad4-4241-a0b2-75a6fbf5aca6",
)
@canonical
class ConvertAttributeToDecorator(Codemod3, Skill):
class ConvertAttributeToDecorator(Codemod, Skill):
"""This converts any class attributes that initializes a set of Session objects to a decorator.

For example, before:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
from codegen.sdk.codemod import Codemod3
from codegen.sdk.core.codebase import Codebase
from codegen.sdk.enums import ProgrammingLanguage
from codegen.sdk.skills.core.skill import Skill
from codegen.sdk.skills.core.utils import skill, skill_impl
from codegen.sdk.writer_decorators import canonical
from codemods.canonical.codemod import Codemod


@skill(
Expand All @@ -15,7 +15,7 @@
uid="846a3894-b534-4de2-9810-94bc691a5687",
)
@canonical
class ConvertCommentsToJSDocStyle(Codemod3, Skill):
class ConvertCommentsToJSDocStyle(Codemod, Skill):
"""This codemod converts the comments on any exported function or class to JSDoc style if they aren't already in JSDoc style.

A JSDoc style comment is one that uses /** */ instead of //
Expand Down
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
from codegen.sdk.codemod import Codemod3
from codegen.sdk.core.codebase import Codebase
from codegen.sdk.enums import ProgrammingLanguage
from codegen.sdk.skills.core.skill import Skill
from codegen.sdk.skills.core.utils import skill, skill_impl
from codegen.sdk.writer_decorators import canonical
from codemods.canonical.codemod import Codemod


@skill(
canonical=True,
prompt="""Generate a Python codemod class named `ConvertDocstringToGoogleStyle` that inherits from `Codemod3` and `Skill`. The class should have a docstring
prompt="""Generate a Python codemod class named `ConvertDocstringToGoogleStyle` that inherits from `Codemod` and `Skill`. The class should have a docstring
explaining its purpose: converting docstrings of functions and classes to Google style if they aren't already. The `execute` method should iterate
over the functions in a given `codebase`, check if each function has a docstring, and if so, convert it to Google style using a method
`to_google_docstring`.""",
uid="99da3cd9-6ba8-4a4e-8ceb-8c1b2a60562d",
)
@canonical
class ConvertDocstringToGoogleStyle(Codemod3, Skill):
class ConvertDocstringToGoogleStyle(Codemod, Skill):
"""This codemod converts docstrings on any function or class to Google docstring style if they aren't already.

A Google docstring style is one that specifies the args, return value, and raised exceptions in a structured format.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
from codegen.sdk.codemod import Codemod3
from codegen.sdk.core.codebase import Codebase
from codegen.sdk.enums import ProgrammingLanguage
from codegen.sdk.skills.core.skill import Skill
from codegen.sdk.skills.core.utils import skill, skill_impl
from codegen.sdk.writer_decorators import canonical
from codemods.canonical.codemod import Codemod


@skill(
Expand All @@ -14,7 +14,7 @@
uid="4024ceb5-54de-49de-b8f5-122ca2d3a6ee",
)
@canonical
class DeleteUnusedFunctionsCodemod(Codemod3, Skill):
class DeleteUnusedFunctionsCodemod(Codemod, Skill):
"""This Codemod deletes all functions that are not used in the codebase (no usages).
In general, when deleting unused things, it's good practice to check both usages and call-sites, even though
call-sites should be basically a subset of usages (every call-site should correspond to a usage).
Expand Down
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
from codegen.sdk.codemod import Codemod3
from codegen.sdk.core.codebase import Codebase
from codegen.sdk.enums import ProgrammingLanguage
from codegen.sdk.skills.core.skill import Skill
from codegen.sdk.skills.core.utils import skill, skill_impl
from codegen.sdk.writer_decorators import canonical
from codemods.canonical.codemod import Codemod


@skill(
canonical=True,
prompt="""Generate a Python codemod that iterates over all Python files in a codebase and adds a rainbow emoji comment at the beginning of each file. The
codemod should be implemented in the `execute` function of the `EmojifyPyFilesCodemod` class, which inherits from `Codemod3` and `Skill`. Ensure that
codemod should be implemented in the `execute` function of the `EmojifyPyFilesCodemod` class, which inherits from `Codemod` and `Skill`. Ensure that
the new content for each file starts with the comment '#🌈' followed by the original content of the file.""",
uid="5d8f1994-7f74-42e8-aaa8-0c41ced228ef",
)
@canonical
class EmojifyPyFilesCodemod(Codemod3, Skill):
class EmojifyPyFilesCodemod(Codemod, Skill):
"""Trivial codemod to add a rainbow emoji in a comment at the beginning of all Python files."""

language = ProgrammingLanguage.PYTHON
Expand Down
Loading
Loading