Skip to content

maint: add taplo pre-commit hook to format and sort toml files #3968

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

Closed
wants to merge 3 commits into from

Conversation

tkoyama010
Copy link
Contributor

@tkoyama010 tkoyama010 commented May 28, 2025

Description

Please provide a brief description of the changes made in this pull request.
See pyvista/pyvista#6781

Issue linked

Please mention the issue number or describe the problem this pull request addresses.

Checklist

Summary by Sourcery

Add a taplo pre-commit hook for automatic formatting and consistent key ordering in TOML files, and apply taplo to reformat and sort entries in pyproject.toml

New Features:

  • Introduce the taplo-format hook in .pre-commit-config.yaml to format and reorder TOML files automatically

Enhancements:

  • Reformat pyproject.toml by sorting keys and entries in each section according to taplo conventions

Summary by Sourcery

Integrate Taplo into the pre-commit workflow to automatically format and sort TOML files.

Enhancements:

  • Reformat pyproject.toml to align with Taplo conventions by sorting keys and entries

CI:

  • Add Taplo-format pre-commit hook to .pre-commit-config.yaml with options to reorder arrays and keys

@ansys-reviewer-bot
Copy link
Contributor

Thanks for opening a Pull Request. If you want to perform a review write a comment saying:

@ansys-reviewer-bot review

Copy link
Contributor

sourcery-ai bot commented May 28, 2025

Reviewer's Guide

Adds a Taplo-based pre-commit hook for automatic TOML formatting and applies it to existing TOML files (e.g., pyproject.toml) to enforce consistent key and array ordering.

Sequence Diagram: TOML Formatting with Taplo on Commit

sequenceDiagram
    actor Developer
    participant Git
    participant PreCommitFramework as "pre-commit Framework"
    participant TaploHook as "taplo-format Hook"

    Developer->>Git: git commit
    Git->>PreCommitFramework: Trigger hooks for staged files
    PreCommitFramework->>TaploHook: Execute on TOML files (with args: reorder_arrays=true, reorder_keys=true)
    activate TaploHook
    TaploHook->>TaploHook: Load TOML file(s)
    TaploHook->>TaploHook: Format content & Sort keys/arrays
    TaploHook->>TaploHook: Save modified TOML file(s) if changes were made
    TaploHook-->>PreCommitFramework: Report status (e.g., success, files modified)
    deactivate TaploHook
    PreCommitFramework-->>Git: Aggregated results from all hooks
    alt All hooks pass
        Git-->>Developer: Commit proceeds (TOML files are formatted)
    else Hook failure or files changed requiring user action
        Git-->>Developer: Commit aborted / User action required (e.g., re-stage files)
    end
Loading

File-Level Changes

Change Details Files
Introduce taplo-format pre-commit hook for TOML files
  • Add ComPWA/taplo-pre-commit repository at rev v0.9.3
  • Configure hook id as taplo-format
  • Set formatter options: reorder_arrays=true and reorder_keys=true
.pre-commit-config.yaml
Reformat TOML files to enforce consistent ordering
  • Apply taplo-format to pyproject.toml
  • Sort table keys in each section
  • Reorder array entries according to taplo conventions
pyproject.toml

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. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the 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 exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

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

@tkoyama010 tkoyama010 marked this pull request as ready for review May 28, 2025 20:49
@Copilot Copilot AI review requested due to automatic review settings May 28, 2025 20:49
@tkoyama010 tkoyama010 requested a review from a team as a code owner May 28, 2025 20:50
@tkoyama010 tkoyama010 requested review from germa89 and clatapie May 28, 2025 20:50
Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This pull request adds a taplo pre-commit hook to automatically format and reorder TOML files using taplo conventions.

  • Introduces a new repository entry for taplo-pre-commit in .pre-commit-config.yaml
  • Configures taplo-format with options to reorder arrays and keys

Copy link
Contributor

@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 @tkoyama010 - I've reviewed your changes - here's some feedback:

  • Consider adding a dedicated taplo configuration file (e.g., .taplo.toml) to centralize formatting options instead of inlining args in the pre-commit config.
  • Specify a files pattern in the taplo-format hook (e.g., files: \.toml$) to scope formatting explicitly to your project’s TOML files.
  • Pin the rev to an exact commit SHA instead of a version tag for more reproducible hook behavior.
Here's what I looked at during the review
  • 🟡 General issues: 1 issue found
  • 🟢 Security: all looks good
  • 🟢 Testing: 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.

Copy link
Collaborator

@germa89 germa89 left a comment

Choose a reason for hiding this comment

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

Hi @tkoyama010 !!

Thank you for opening this! :D

@germa89
Copy link
Collaborator

germa89 commented May 29, 2025

Since this PR is coming from a fork, let's migrate it to PyMAPDL repo.

@pyansys-ci-bot migrate

@germa89
Copy link
Collaborator

germa89 commented May 29, 2025

@pyansys-ci-bot migrate

@pyansys-ci-bot
Copy link
Contributor

❌ Error ❌

An error occurred while migrating and syncing the PR. Please check the action logs for more details.

@germa89
Copy link
Collaborator

germa89 commented May 29, 2025

@pyansys-ci-bot migrate

@pyansys-ci-bot
Copy link
Contributor

🚀 Migration completed!

The PR #3971 has been created successfully.

@tkoyama010 tkoyama010 deleted the maint/taplo branch May 30, 2025 13:15
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.

3 participants