Skip to content
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

feat: support parsing and validating pydantic arguments #250

Merged
merged 17 commits into from
Jan 17, 2025

Conversation

rushilpatel0
Copy link
Collaborator

@rushilpatel0 rushilpatel0 commented Jan 16, 2025

Support for requiring and validating arguments of Pydantic BaseModel type

from pydantic import BaseModel, Field
import codegen.cli.sdk.decorator
# from app.codemod.compilation.models.context import CodemodContext
# from app.codemod.compilation.models.pr_options import PROptions
# from graph_sitter import PyCodebaseType

# context: CodemodContext

class CountFunctionsArgs(BaseModel):
    number_attr: int
    string_attr: str
    boolean_attr: bool
    list_attr: list[str]
    dict_attr: dict[str, str]
    complex_attr: str = Field(default_factory=lambda: "hello")


@codegen.cli.sdk.decorator.function('count-functions')
def run(codebase, pr_options, arguments: CountFunctionsArgs):
    # Count Functions in Codebase

    # Initialize a total function counter
    total_functions = 0

    # Optionally, track functions by directory for more insight
    functions_by_directory = {}

    # Iterate over all functions in the codebase
    for function in codebase.functions:
        total_functions += 1
    
        # Extract directory from function's file path
        directory = function.file.filepath.split('/')[0]
        functions_by_directory[directory] = functions_by_directory.get(directory, 0) + 1

    # Print the results
    print(f"🔢 Total Functions: {total_functions}")
    print("\n📂 Functions by Directory:")
    for directory, count in sorted(functions_by_directory.items(), key=lambda x: x[1], reverse=True):
        print(f"  {directory}: {count} functions")

@rushilpatel0 rushilpatel0 changed the title support parsing and validating pydantic arguments feat: support parsing and validating pydantic arguments Jan 16, 2025
@rushilpatel0 rushilpatel0 force-pushed the rpatel/pydantic-arguments branch from e25b637 to 58ce4ce Compare January 17, 2025 18:38
@codegen-team codegen-team enabled auto-merge (squash) January 17, 2025 18:43
@rushilpatel0 rushilpatel0 disabled auto-merge January 17, 2025 19:20
@rushilpatel0 rushilpatel0 merged commit 56bb29d into main Jan 17, 2025
3 of 4 checks passed
@rushilpatel0 rushilpatel0 deleted the rpatel/pydantic-arguments branch January 17, 2025 19:20
@codegen-team
Copy link
Contributor

🎉 This PR is included in version 1.24.0 🎉

The release is available on GitHub release

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants