Skip to content

Conversation

@kairos-xx
Copy link
Owner

@kairos-xx kairos-xx commented Jan 3, 2025

Summary by Sourcery

Update Replit workflows configuration, add "demo" workflow, improve source code extraction and AST building, enhance tree visualization, and refine git commit and zip creation processes.

Build:

  • Update workflows in .replit configuration.

CI:

  • Add "demo" workflow to run examples and log output.
  • Update existing workflows to log output and improve error handling.

Tests:

  • Add tests for rich printer and tree core functionalities.

kairos-xx and others added 13 commits December 30, 2024 09:09
…mits

Assistant generated file changes:
- scripts/git_commit.py: Fix git commit and push process

---

User prompt:

my script git_commit doesnt put the files visible on github
Assistant generated file changes:
- scripts/git_commit.py: Update git authentication and push logic

---

User prompt:

[replit f3dbe71] Auto commit:2024-12-31 23:07:19
 1 file changed, 8 insertions(+), 6 deletions(-)
remote: Support for password authentication was removed on August 13, 2021.
remote: Please see https://docs.github.com/get-started/getting-started-with-git/about-remote-repositories#cloning-with-https-urls for information on currently recommended modes of authentication.
fatal: Authentication failed for 'https://github.com/kairos-xx/tree-interval/'
error: src refspec master does not match any
error: failed to push some refs to 'https://github.com/kairos-xx/tree-interval'
🚀 Starting automated operations...

Cleaning merge conflicts and committing changes...
✅ Cleaned merge conflicts in ./scripts/git_commit.py
❌ Error in git operations: Command '['git', 'push', 'origin', 'master']' returned non-zero exit status 1.
…rmat

Assistant generated file changes:
- scripts/update_workflows.py: Convert workflows to Python dictionary format

---

User prompt:

convert:
into:
@sourcery-ai
Copy link

sourcery-ai bot commented Jan 3, 2025

Reviewer's Guide by Sourcery

This pull request refactors the workflows update process, introduces a demo workflow, improves source code handling for Position and AST building, enhances the Rich printer, and adds custom styling examples. It also updates the git commit process and the create zip script.

Class diagram for updated Position and Tree visualization classes

classDiagram
    class Position {
        +int start
        +int end
        +int lineno
        +int end_lineno
        +int col_offset
        +int end_col_offset
        +__init__(start, end)
        +__eq__(other)
    }

    class TreeVisualizer {
        +visualize(tree, config, root)
        -format_node_info(node, level, info_len)
        -_print_node(node, prefix, is_last, level)
    }

    class RichTreePrinter {
        +RichPrintConfig config
        +Console console
        +print_tree(tree, root)
        -_format_node(node, is_root, level)
        -_add_children(node, rich_node, level)
    }

    class RichPrintConfig {
        +int terminal_size
        +bool show_info
        +bool show_size
        +bool show_position
    }

    RichTreePrinter --> RichPrintConfig
    note for RichTreePrinter "Added support for custom root node visualization"
    note for TreeVisualizer "Enhanced with terminal size handling and custom root support"
Loading

File-Level Changes

Change Details Files
Refactored workflows update process to directly define workflows in the script.
  • Removed TOML parsing and file I/O.
  • Directly defines workflows as a list of dictionaries in the script.
  • Uses subprocess to get the Repl author ID.
scripts/update_workflows.py
Introduced a demo workflow.
  • Added a new workflow named "[Util] demo" that runs the examples module.
scripts/update_workflows.py
Improved source code handling for Position and AST building.
  • Simplified Position initialization from a frame.
  • Removed unnecessary indentation handling in ASTBuilder.
  • Used dedent to normalize source code in ASTBuilder.
  • Improved accuracy of start and end positions.
src/tree_interval/core/interval_core.py
src/tree_interval/core/ast_builder.py
Enhanced Rich printer to support custom root nodes and improved info display.
  • Added support for visualizing subtrees from a specified root node.
  • Improved info display by truncating long info strings and adding ellipsis.
  • Added tests for custom root visualization.
src/tree_interval/rich_printer/printer.py
src/tree_interval/rich_printer/config.py
tests/test_rich_printer.py
Added custom styling examples.
  • Added examples for syntax highlighting and selected node styling.
  • Demonstrated custom styling in the main demo.
examples/styling_examples.py
main.py
Updated git commit process.
  • Improved merge conflict cleaning.
  • Added git init if .git directory doesn't exist.
  • Added all files using git add -A.
  • Set default branch to replit.
  • Added a replit remote.
  • Improved error handling and reporting.
scripts/git_commit.py
Updated create zip script.
  • Updated ignore patterns.
  • Simplified zip file creation.
scripts/create_zip.py
Added replit.nix and updated .replit
  • Added nano, python312Full to replit.nix
replit.nix
Removed frame_dev.py
  • Removed frame_dev.py
frame_dev.py

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time. You can also use
    this command to specify where the summary should be inserted.

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

Copy link

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

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

Hey @kairos-xx - I've reviewed your changes - here's some feedback:

Overall Comments:

  • The removal of tree traversal methods (find_parent, find_child, find_sibling) appears to be a functionality regression. Consider keeping these utility methods or document why they were removed.
  • Git credentials are hardcoded in git_commit.py. Consider making these configurable through environment variables or configuration files instead.
Here's what I looked at during the review
  • 🟢 General issues: all looks good
  • 🟡 Security: 1 issue found
  • 🟢 Testing: all looks good
  • 🟢 Complexity: all looks good
  • 🟢 Documentation: all looks good

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.


# Configure git if needed
subprocess.run([
"git", "config", "--global", "user.email", "[email protected]"
Copy link

Choose a reason for hiding this comment

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

🚨 issue (security): Avoid hardcoding Git credentials

Hardcoded credentials pose a security risk and make the code less maintainable. Consider using environment variables or a configuration file for Git credentials.

Comment on lines 91 to 93
pos = self.ast_builder._get_node_position(
cast(AST, node.ast_node), line_positions)
cast(AST, node.ast_node))
if pos:
Copy link

Choose a reason for hiding this comment

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

suggestion (code-quality): Use named expression to simplify assignment and conditional (use-named-expression)

Suggested change
pos = self.ast_builder._get_node_position(
cast(AST, node.ast_node), line_positions)
cast(AST, node.ast_node))
if pos:
if pos := self.ast_builder._get_node_position(
cast(AST, node.ast_node)
):

self.console.print(rich_tree)

def _format_node(self, node: Leaf, is_root: bool = False) -> str:
def _format_node(self,
Copy link

Choose a reason for hiding this comment

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

issue (code-quality): Low code quality found in RichTreePrinter._format_node - 22% (low-code-quality)


ExplanationThe quality score for this function is below the quality threshold of 25%.
This score is a combination of the method length, cognitive complexity and working memory.

How can you solve this?

It might be worth refactoring this function to make it shorter and more readable.

  • Reduce the function length by extracting pieces of functionality out into
    their own functions. This is the most important thing you can do - ideally a
    function should be less than 10 lines.
  • Reduce nesting, perhaps by introducing guard clauses to return early.
  • Ensure that variables are tightly scoped, so that code using related concepts
    sits together within the function rather than being scattered.

kairos-xx and others added 4 commits January 3, 2025 09:49
Co-authored-by: sourcery-ai[bot] <58596630+sourcery-ai[bot]@users.noreply.github.com>
Co-authored-by: sourcery-ai[bot] <58596630+sourcery-ai[bot]@users.noreply.github.com>
Co-authored-by: sourcery-ai[bot] <58596630+sourcery-ai[bot]@users.noreply.github.com>
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.

1 participant