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: init gritql python #337

Merged
merged 28 commits into from
May 23, 2024
Merged

feat: init gritql python #337

merged 28 commits into from
May 23, 2024

Conversation

morgante
Copy link
Contributor

@morgante morgante commented May 16, 2024

Exposes a basic wrapper package for GritQL that handles applying patterns from Python. This is currently done using the grit binary.

Other options explored

  1. Maturin looks great if/when we decide to make tighter Python bindings - we will probably just want to ship the compiled library, not the CLI as well.

Prior art

  1. namespace migrate subcommand, using typer + libCST
  2. openai migrate subcommand, using Grit + httpx + subprocess

Summary by CodeRabbit

  • New Features

    • Introduced GritQL, a declarative query language for searching and modifying source code.
    • Added a Python library for embedding the Grit CLI within other CLI tools.
    • Implemented functionality to download and install the Grit CLI tool.
  • Enhancements

    • Improved resolver functionality to support flags for specifying directories.
    • Updated CLI commands to use new resolver functions for enhanced flexibility.
    • Added new public field grit_dir to GlobalFormatFlags for better directory handling.
  • Tests

    • Added new tests for applying patterns with custom grit directories.
    • Introduced tests to list patterns with a custom grit directory.
  • Documentation

    • Added README files for GritQL and its Python library.
    • Updated .gitignore for Python development.
  • Dependencies

    • Updated requirements.txt to include typer and httpx dependencies.

@morgante morgante marked this pull request as ready for review May 23, 2024 00:34
@morgante morgante requested a review from a team as a code owner May 23, 2024 00:35
Copy link
Contributor

coderabbitai bot commented May 23, 2024

Warning

Rate Limit Exceeded

@morgante has exceeded the limit for the number of commits or files that can be reviewed per hour. Please wait 15 minutes and 40 seconds before requesting another review.

How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.
Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.
Please see our FAQ for further information.

Commits Files that changed from the base of the PR and between 7ca9e6c and 80630fc.

Walkthrough

The recent changes encompass renaming functions for clarity, updating import statements, restructuring resolver interfaces, and introducing new test functions and files. Additionally, a new Python library for GritQL has been added, complete with installation and runtime scripts, enhancing the functionality and usability of the Grit CLI tool. These updates aim to improve code readability, consistency, and extend the tool's capabilities for pattern application and testing.

Changes

Files/Directories Change Summary
.../commands/apply_pattern.rs Renamed function for clarity, updated parameter names for consistency.
.../commands/check.rs, .../commands/patterns_test.rs Renamed functions, updated try_join! block, and resolver initialization.
.../commands/parse.rs Reorganized imports, removed unnecessary code, and adjusted function calls.
.../commands/patterns_list.rs Modified resolver function calls.
.../flags.rs Added a new public field grit_dir to GlobalFormatFlags.
.../resolver.rs Restructured imports, added new methods, refactored async functions, and introduced new resolver functions.
.../override_custom_grit_dir/.grit/patterns/mine.grit Introduced a new pattern file for replacing os.getenv with dotenv.mygoodness in Python.
.../tests/apply.rs, .../tests/list.rs Added new test functions for applying patterns with custom grit directories.
python/.gitignore Added exclusions for common Python development files and directories.
python/README.md Introduced GritQL, a declarative query language for searching and modifying source code.
python/gritql/README.md Introduced a Python library for interacting with GritQL.
python/gritql/installer.py Added functionality to download and install the Grit CLI tool.
python/gritql/requirements.txt Updated to include dependencies: typer and httpx.
python/gritql/run.py Introduced functions to run the GritQL CLI and apply patterns.
python/pyproject.toml Added configuration settings for the "gritql" project, specifying metadata, dependencies, and build system details.

Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

Share
Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (invoked as PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger a review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai help to get help.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Configration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

python/gritql/installer.py Show resolved Hide resolved
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 3

import tarfile
import platform

from typing import TYPE_CHECKING, List
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove unused imports to clean up the code.

- from typing import TYPE_CHECKING, List
+ from typing import TYPE_CHECKING

Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.

Suggested change
from typing import TYPE_CHECKING, List
from typing import TYPE_CHECKING


def find_install() -> Path:
"""Installs the Grit CLI and returns the location of the binary"""
if sys.platform == "win32":
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider using a more specific exception type for better error handling.

- raise Exception("Windows is not supported yet in the migration CLI")
+ raise NotImplementedError("Windows is not supported yet in the migration CLI")

Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.

Suggested change
if sys.platform == "win32":
if sys.platform == "win32":
raise NotImplementedError("Windows is not supported yet in the migration CLI")

for error in errors:
sys.stdout.write(f"{error}\n")

raise CLIError("Could not locate Grit CLI binary - see above errors")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Define CLIError to resolve the undefined name error.

+ class CLIError(Exception):
+     """Custom exception for CLI-related errors."""

Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.

Suggested change
raise CLIError("Could not locate Grit CLI binary - see above errors")
class CLIError(Exception):
"""Custom exception for CLI-related errors."""
# ... other code ...
raise CLIError("Could not locate Grit CLI binary - see above errors")

def install() -> Path:
"""Installs the Grit CLI and returns the location of the binary"""
if sys.platform == "win32":
raise CLIError("Windows is not supported yet in the migration CLI")
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

/grit new Don't allow using undefined functions or classes.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have created a new review rule: Disallow Usage of Undefined Functions or Classes.

@morgante morgante merged commit c879bde into main May 23, 2024
7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants