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

add harpy view #166

Merged
merged 7 commits into from
Nov 22, 2024
Merged

add harpy view #166

merged 7 commits into from
Nov 22, 2024

Conversation

pdimens
Copy link
Owner

@pdimens pdimens commented Nov 22, 2024

Adds harpy view as a convenience method to view logfiles and snakefiles

Summary by CodeRabbit

Release Notes

  • New Features

    • Introduced a new view command in the CLI to allow users to view the latest log or snakefile for a specified workflow directory, with options for error handling and file navigation.
  • Bug Fixes

    • Corrected the import path for the popgroup module in the CLI.
  • Chores

    • Updated the installation command in the build script for improved usability.
    • Removed outdated configuration from the project settings.

Copy link

coderabbitai bot commented Nov 22, 2024

📝 Walkthrough

Walkthrough

The changes in this pull request involve modifications to several files within the harpy project. Key updates include correcting the import path for the popgroup module, adding a new view command to the command-line interface, and updating the command group to include this new command. Additionally, the pyproject.toml file has had the [tool.setuptools_scm] section removed, and the buildlocal.sh script has been adjusted to enhance the installation process and error handling.

Changes

File Change Summary
harpy/main.py Updated import statement for popgroup; added view.view command to CLI; modified command group to include view.
harpy/view.py Introduced new view(directory, snakefile) function for viewing logs or snakefiles with error handling.
pyproject.toml Removed [tool.setuptools_scm] section.
resources/buildlocal.sh Modified installation command to use editable mode and disable pip version check; updated cleanup command.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant CLI
    participant ViewFunction

    User->>CLI: run view command
    CLI->>ViewFunction: call view(directory, snakefile)
    ViewFunction->>ViewFunction: check directory and files
    alt --snakefile flag set
        ViewFunction->>ViewFunction: search for .smk files
    else no --snakefile flag
        ViewFunction->>ViewFunction: search for .log files
    end
    ViewFunction->>ViewFunction: sort files by modification time
    ViewFunction->>ViewFunction: check read permissions
    ViewFunction->>ViewFunction: determine file type (gzipped or not)
    ViewFunction->>User: display file content
Loading

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.

Copy link

@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

🧹 Outside diff range and nitpick comments (4)
resources/buildlocal.sh (1)

15-15: LGTM! Consider adding error message for pip install failure

The pip install command changes are good improvements:

  • Editable install (-e) is appropriate for local development
  • Disabling pip version check speeds up installation

Consider adding error handling:

-pip install --no-deps --disable-pip-version-check -e . && \
+pip install --no-deps --disable-pip-version-check -e . || { echo "Error: Failed to install package"; exit 1; } && \
harpy/__main__.py (1)

Line range hint 19-75: Consider enhancing error handling and user feedback.

Since this is a CLI tool for viewing logfiles and snakefiles:

  1. Ensure proper error messages when files don't exist or are inaccessible
  2. Consider adding colorized output for better readability
  3. Add support for file type detection and appropriate formatting
  4. Consider implementing file watching functionality for live log viewing

Would you like me to provide specific implementation suggestions for any of these enhancements?

harpy/view.py (2)

11-28: Consider improving help text formatting.

The help text is comprehensive but could be more readable with consistent spacing. There's an extra blank line at line 17 and inconsistent spacing around the keyboard shortcuts table.

    """
    View a workflow log file or snakefile

-
    This convenience command lets you view the latest workflow log file
    of a Harpy output directory. You can use `--snakefile` to view the workflow
    snakefile instead. Output is printed to the screen via `less` and
    accepts the typical keyboard shortcuts to navigate the output, e.g.:
    
    | key                     | function                   |
    | :---------------------- | :------------------------- |
    | `up arrow`/`down arrow` | scroll up/down             |
    | `Page Up`/`Page Down`   | scroll up/down, but faster |
    | `q`                     | exit                       |
    """

31-59: Consider using enum for error codes and more specific file patterns.

  1. The numeric error codes (0, 1, 2) could be more maintainable using an enum.
  2. The log file pattern *.log* might match unintended files (e.g., *.logo).

Consider these improvements:

+from enum import Enum
+
+class ViewError(Enum):
+    SUCCESS = 0
+    DIRECTORY_NOT_FOUND = 1
+    FILES_NOT_FOUND = 2
+
-    err = 0
+    err = ViewError.SUCCESS
     if snakefile:
         files = [i for i in glob.iglob(f"{directory}/workflow/*.smk")]
         err_dir = f"{directory}/workflow/"
         err_file = "snakefiles"
         if not os.path.exists(f"{directory}/workflow"):
-            err = 1
+            err = ViewError.DIRECTORY_NOT_FOUND
         elif not files:
-            err = 2
+            err = ViewError.FILES_NOT_FOUND
     else:
-        files = [i for i in glob.iglob(f"{directory}/logs/snakemake/*.log*")]
+        files = [i for i in glob.iglob(f"{directory}/logs/snakemake/*.log") + 
+                glob.iglob(f"{directory}/logs/snakemake/*.log.gz")]
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 632f853 and 1475a93.

📒 Files selected for processing (4)
  • harpy/__main__.py (3 hunks)
  • harpy/view.py (1 hunks)
  • pyproject.toml (0 hunks)
  • resources/buildlocal.sh (1 hunks)
💤 Files with no reviewable changes (1)
  • pyproject.toml
🔇 Additional comments (5)
resources/buildlocal.sh (1)

16-16: 🛠️ Refactor suggestion

Review cleanup command changes

The current cleanup approach has potential issues:

  1. Using rm -rf without specific targets is risky
  2. Removing harpy.egg-info cleanup (commented out) might leave installation artifacts

Let's verify what files typically need cleanup:

Consider a more specific cleanup:

-    rm -rf build #harpy.egg-info
+    rm -rf build *.egg-info __pycache__ *.pyc
harpy/__main__.py (3)

19-19: LGTM! Import changes are well-structured.

The import changes look good:

  • Corrected import path for popgroup module
  • Clean addition of the view module import

Also applies to: 21-21


75-75: LGTM! Command group organization is appropriate.

The view command is correctly categorized under "Other Commands" and maintains alphabetical sorting.


48-48: Verify view command implementation.

The command registration looks correct, but let's verify the view command implementation.

✅ Verification successful

The view command implementation has been thoroughly verified through the shell script results. I can now provide the final response:

View command implementation is well-structured and complete

The command is properly implemented with:

  • Clear documentation and help text
  • Required directory argument with path validation
  • Optional --snakefile flag to toggle between log/snakefile viewing
  • Proper error handling for missing directories/files and permissions
  • Smart file selection (picks latest by modification time)
  • User-friendly output formatting using less with syntax highlighting
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the view command implementation and its interface

# Check if view.py exists and contains the view command implementation
fd "view.py" --type f --exec cat {} \;

# Look for any usage of the view command in tests or documentation
rg -A 5 "def view" 

Length of output: 3419

harpy/view.py (1)

1-10: LGTM! Well-organized imports and clear documentation.

The imports are appropriate for the functionality, and the module's docstring clearly describes its purpose.

harpy/view.py Show resolved Hide resolved
harpy/view.py Show resolved Hide resolved
@pdimens pdimens merged commit 736e540 into main Nov 22, 2024
3 checks passed
@pdimens pdimens deleted the logview branch November 22, 2024 19:08
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