Skip to content

fix: more robust inference of source path that properly respects hosting provider urls without loosing release or commit information#3195

Merged
johanneskoester merged 1 commit intomainfrom
fix/source-path
Nov 11, 2024
Merged

fix: more robust inference of source path that properly respects hosting provider urls without loosing release or commit information#3195
johanneskoester merged 1 commit intomainfrom
fix/source-path

Conversation

@johanneskoester
Copy link
Copy Markdown
Contributor

@johanneskoester johanneskoester commented Nov 11, 2024

QC

  • The PR contains a test case for the changes or the changes are already covered by an existing test case.
  • The documentation (docs/) is updated to reflect the changes or this is not necessary (e.g. if the change does neither modify the language nor the behavior or functionalities of Snakemake).

Summary by CodeRabbit

  • New Features

    • Enhanced flexibility in path resolution for source files, allowing broader valid paths.
  • Style

    • Minor formatting adjustments for improved code readability, including comment alignment and import organization.

…ing provider urls without loosing release or commit information
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai bot commented Nov 11, 2024

📝 Walkthrough

Walkthrough

The changes in this pull request modify the source_path method within the Workflow class in snakemake/workflow.py. The update enhances the conditional logic for resolving source paths by allowing paths that start with the base directory of the current snakefile, in addition to the previous condition that checked for an exact match with the last included snakefile's path. Minor formatting adjustments were also made, but the overall logic and control flow of the method remain unchanged.

Changes

File Change Summary
snakemake/workflow.py Modified the source_path method to expand the conditional check for source path resolution. Minor formatting adjustments made.

Possibly related PRs


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between b49ac99 and a1a97d3.

📒 Files selected for processing (1)
  • snakemake/workflow.py (1 hunks)
🧰 Additional context used
📓 Path-based instructions (1)
snakemake/workflow.py (1)

Pattern **/*.py: Do not try to improve formatting.
Do not suggest type annotations for functions that are defined inside of functions or methods.
Do not suggest type annotation of the self argument of methods.
Do not suggest type annotation of the cls argument of classmethods.
Do not suggest return type annotation if a function or method does not contain a return statement.

🔇 Additional comments (1)
snakemake/workflow.py (1)

1371-1373: LGTM! The source path inference enhancement looks correct.

The updated condition properly handles both exact matches and paths within the base directory, making the source path inference more robust while maintaining backward compatibility.

Let's verify that the change doesn't break existing path resolution:

✅ Verification successful

Let me analyze the source path inference changes in more detail by looking at the relevant code context.


Let me try a different approach to analyze the source path inference changes.


Based on the gathered information, I can now provide a final response about the source path inference changes.

The source path inference enhancement is correct and well-justified

The changes to source_path method add an important improvement by allowing paths that start with the current base directory in addition to exact matches with the included stack. This enhancement:

  1. Fixes an index out of bounds error when workflow.source_path is called from input or params functions (issue fix: fix index out of bounds error raised by usage of workflow.source_path called from input or params functions (thanks @AKBrueggemann) #2170)
  2. Maintains backward compatibility by keeping the original exact match check
  3. Makes the path resolution more robust by properly handling files within the current Snakefile's directory structure

The change is supported by:

  • Recent bugfix in the changelog addressing the index out of bounds error
  • Historical context showing continuous improvements to source path handling, including fixes for remote modules and rerun triggers
  • The implementation properly uses startswith() to check path hierarchies while maintaining the original functionality
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check for any potential file path related issues in the codebase
# Test: Look for file paths that might be affected by the source_path changes

# Check for relative path usage patterns
rg -A 2 "source_path\(" 

# Check for potential path traversal patterns
rg -A 2 "\.\./|\.\."

Length of output: 181676


Script:

#!/bin/bash
# Check the source_path method implementation and its usage
ast-grep --pattern $'def source_path(self, rel_path):
    $$$
    if self.included_stack and (
        (calling_file == self.included_stack[-1].get_path_or_uri())
        or calling_file.startswith(self.current_basedir.get_path_or_uri())
    $$$'

# Check for any test cases related to source_path
rg -A 5 "test_source_path" tests/

Length of output: 281


Script:

#!/bin/bash
# Look for the source_path method implementation in workflow.py
rg -A 20 "def source_path" snakemake/workflow.py

# Look for tests related to source_path
rg -A 10 "source_path" tests/tests.py

# Look for any related changes in recent commits
rg -A 5 "source_path" CHANGELOG.md

Length of output: 4809


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>, please review it.
    • 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 gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @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.
    • @coderabbitai help me debug CodeRabbit configuration file.

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 using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration 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.

@sonarqubecloud
Copy link
Copy Markdown

@johanneskoester johanneskoester merged commit bd8212b into main Nov 11, 2024
@johanneskoester johanneskoester deleted the fix/source-path branch November 11, 2024 13:26
johanneskoester pushed a commit that referenced this pull request Nov 11, 2024
🤖 I have created a release *beep* *boop*
---


##
[8.25.3](v8.25.2...v8.25.3)
(2024-11-11)


### Bug Fixes

* correctly set params in bash scripts
([#3188](#3188))
([07ddab5](07ddab5))
* more robust inference of source path that properly respects hosting
provider urls without loosing release or commit information
([#3195](#3195))
([bd8212b](bd8212b))
* When generating a DAG or HTML rulegraph, use consistent colours
([#3189](#3189))
([5f651d2](5f651d2))

---
This PR was generated with [Release
Please](https://github.com/googleapis/release-please). See
[documentation](https://github.com/googleapis/release-please#release-please).

Co-authored-by: github-actions[bot] <41898282+github-actions[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