Skip to content

Refactors remote config path resolution#89

Merged
Kilo59 merged 6 commits intomainfrom
expanded-config
Mar 11, 2026
Merged

Refactors remote config path resolution#89
Kilo59 merged 6 commits intomainfrom
expanded-config

Conversation

@Kilo59
Copy link
Owner

@Kilo59 Kilo59 commented Mar 10, 2026

Description

Refactors remote configuration path resolution and enhances error handling with proactive suggestions.

Changes

  • Path Resolution: Introduces _get_target_path to centralize and deduplicate logic across GitHub, GitLab, and local fetching.
  • Explicit TOML Support: Allows direct specification of .toml files in addition to inferring pyproject.toml from a directory.
  • Enhanced Error Messages: When an HTTP download fails, the tool now attempts to convert the URL to a Git SSH URL and suggests a ruff-sync pull command as an alternative.
  • URL Conversion: Added to_git_url to handle browser-to-git URL transformations.
  • Cleanup: Consolidated URL-related tests into [tests/test_url_handling.py] and bumped version to 0.0.5.dev1.

Introduces a dedicated helper to determine the target configuration file path.

Allows direct specification of TOML files in addition to inferring `pyproject.toml` from a directory. This change centralizes and deduplicates path construction logic across GitHub, GitLab, and local fetching functions, improving clarity and flexibility.
@sourcery-ai
Copy link

sourcery-ai bot commented Mar 10, 2026

Reviewer's Guide

Refactors configuration path resolution so that GitHub, GitLab, and local git-clone fetchers share a single helper that can resolve either directory-based pyproject.toml paths or explicit TOML file paths.

Flow diagram for _get_target_path helper logic

flowchart TD
    A[start _get_target_path path] --> B{path is not None?}
    B -- no --> C[return pyproject.toml]
    B -- yes --> D{path endswith .toml?}
    D -- yes --> E[strip trailing slashes from path]
    E --> F[return stripped path]
    D -- no --> G[strip trailing slashes from path]
    G --> H[append /pyproject.toml]
    H --> I[return combined path]
Loading

Flow diagram for shared configuration target path resolution

flowchart TD
    subgraph Callers
        A[_convert_github_url] --> D[_get_target_path]
        B[_convert_gitlab_url] --> D
        C[_git_clone_and_read] --> D
    end

    D --> E[resolved_target_path]

    E --> F[GitHub raw URL path construction]
    E --> G[GitLab raw URL path construction]
    E --> H[Local pathlib.Path creation]
Loading

File-Level Changes

Change Details Files
Introduce shared helper for resolving target configuration paths from optional directory or explicit TOML file.
  • Add _get_target_path(path: str
None) helper that returns path unchanged when it ends with .toml and otherwise appends pyproject.toml, handling None and leading/trailing slashes.
  • Use string-based resolution for remote URLs while preserving existing default pyproject.toml behavior when no path is provided.
  • Update GitHub and GitLab URL conversion to use centralized path resolution and document TOML file support.
    • In _convert_github_url, replace inline pyproject.toml path construction with _get_target_path(path) when handling repo URLs.
    • In _convert_gitlab_url, replace inline pyproject.toml path construction with _get_target_path(path) for repo URLs with non-empty path_prefix.
    • Clarify docstrings for _convert_github_url and _convert_gitlab_url to note support for explicit TOML file paths and conditional pyproject.toml defaulting.
    ruff_sync.py
    Align local git-clone-based configuration reading with new path resolution helper.
    • In _git_clone_and_read, replace manual pathlib.Path composition of pyproject.toml with pathlib.Path(_get_target_path(path)) so local behavior matches remote URL handling.
    ruff_sync.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. 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

    @codecov
    Copy link

    codecov bot commented Mar 10, 2026

    Codecov Report

    ❌ Patch coverage is 90.69767% with 4 lines in your changes missing coverage. Please review.
    ✅ Project coverage is 90.38%. Comparing base (d32833b) to head (8a342e7).
    ⚠️ Report is 1 commits behind head on main.

    Files with missing lines Patch % Lines
    ruff_sync.py 90.69% 4 Missing ⚠️
    Additional details and impacted files
    @@            Coverage Diff             @@
    ##             main      #89      +/-   ##
    ==========================================
    - Coverage   90.48%   90.38%   -0.11%     
    ==========================================
      Files           1        1              
      Lines         410      447      +37     
    ==========================================
    + Hits          371      404      +33     
    - Misses         39       43       +4     

    ☔ View full report in Codecov by Sentry.
    📢 Have feedback on the report? Share it here.

    🚀 New features to boost your workflow:
    • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

    @Kilo59 Kilo59 self-assigned this Mar 10, 2026
    @Kilo59 Kilo59 marked this pull request as ready for review March 11, 2026 00:01
    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 - I've left some high level feedback:

    • In _get_target_path, consider using pathlib.PurePosixPath (or at least normalizing via URL-style joins) instead of manual strip('/') and string concatenation to avoid subtle path edge cases and make the URL path handling more robust.
    • The .endswith('.toml') check in _get_target_path is case-sensitive; if you want to support configuration files with different TOML filename casing, you may want to normalize the extension before checking.
    Prompt for AI Agents
    Please address the comments from this code review:
    
    ## Overall Comments
    - In `_get_target_path`, consider using `pathlib.PurePosixPath` (or at least normalizing via URL-style joins) instead of manual `strip('/')` and string concatenation to avoid subtle path edge cases and make the URL path handling more robust.
    - The `.endswith('.toml')` check in `_get_target_path` is case-sensitive; if you want to support configuration files with different TOML filename casing, you may want to normalize the extension before checking.

    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.

    @Kilo59 Kilo59 force-pushed the expanded-config branch 2 times, most recently from ba0b101 to fc37e91 Compare March 11, 2026 00:23
    @github-actions
    Copy link

    ╒═══════════════╤════════════╤═════════════════╤═════════════════╤══════════════╕
    │ File          │ Unique     │ Maintainabili   │ Lines of Code   │ Cyclomatic   │
    │               │ Operands   │ ty Index        │                 │ Complexity   │
    ╞═══════════════╪════════════╪═════════════════╪═════════════════╪══════════════╡
    │ ruff_sync.py  │ 12 -> 14   │ 29.4918 ->      │ 889 -> 954      │ 120 -> 135   │
    │               │            │ 26.8178         │                 │              │
    ├───────────────┼────────────┼─────────────────┼─────────────────┼──────────────┤
    │ tests/test_ur │ 1 -> 3     │ 84.6128 ->      │ 113 -> 218      │ 2 -> 6       │
    │ l_handling.py │            │ 67.7977         │                 │              │
    ╘═══════════════╧════════════╧═════════════════╧═════════════════╧══════════════╛
    

    @Kilo59 Kilo59 merged commit dcf83fb into main Mar 11, 2026
    12 checks passed
    @Kilo59 Kilo59 deleted the expanded-config branch March 11, 2026 00:38
    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