Skip to content

Conversation

@SubhadityaMukherjee
Copy link
Contributor

@SubhadityaMukherjee SubhadityaMukherjee commented Mar 19, 2025

This script can be used to build all/selected docker/singularity images. You can either recreate them or just rebuild. Works for both singularity and docker (atleast for me)

Summary by CodeRabbit

  • New Features

    • Introduced a command-line tool that builds container images for both Docker and Singularity modes. Users can select a mode, optionally force-delete existing container files, and target specific frameworks.
  • Chores

    • Updated version control settings to ignore local development environment directories.

@coderabbitai
Copy link

coderabbitai bot commented Mar 19, 2025

Walkthrough

The pull request introduces two major changes. First, an additional entry (.venv/) is added to the .gitignore file to ensure the virtual environment directory is ignored by Git. Second, a new script (scripts/build_images.py) is added. This script provides a command-line interface for building Docker or Singularity images, includes functionality for parsing arguments, optionally deleting existing files (with a --force flag), retrieving a list of frameworks, and executing a benchmark for each framework.

Changes

File Path Change Summary
.gitignore Added .venv/ directory entry to be ignored by Git.
scripts/build_images.py New script added to build Docker and Singularity images. Introduces functions for argument parsing, framework retrieval, deleting Singularity files, conditionally deleting images based on mode and flag, and executing benchmarks.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant Script
    participant ArgumentParser
    participant Cleaner
    participant FrameworkRunner

    User->>Script: Execute build_images.py
    Script->>ArgumentParser: Parse command-line arguments
    ArgumentParser-->>Script: Return mode, flags, and frameworks
    alt Docker mode with --force
        Script->>Cleaner: Delete Docker images for specified frameworks
    else Singularity mode with --force
        Script->>Cleaner: Delete Singularity files (Singularityfile, .sif)
    end
    Script->>FrameworkRunner: Run benchmark for each framework
    FrameworkRunner-->>Script: Benchmark execution complete
Loading

Poem

I'm a rabbit, quick and bright,
Hopping through code with pure delight.
.venv/ hides away like a secret burrow,
And build_images.py makes the images flow.
With flags and functions, we race ahead,
Coding magic—no need for bed!
🐇✨ Hop on, code trailblazers!

Tip

⚡🧪 Multi-step agentic review comment chat (experimental)
  • We're introducing multi-step agentic chat in review comments. This experimental feature enhances review discussions with the CodeRabbit agentic chat by enabling advanced interactions, including the ability to create pull requests directly from comments.
    - To enable this feature, set early_access to true under in the settings.
✨ Finishing Touches
  • 📝 Generate Docstrings

🪧 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 generate docstrings to generate docstrings for this 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.

@codecov-commenter
Copy link

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 69.53%. Comparing base (0f7b169) to head (6ad268c).

Additional details and impacted files
@@           Coverage Diff           @@
##           master     #703   +/-   ##
=======================================
  Coverage   69.53%   69.53%           
=======================================
  Files          57       57           
  Lines        6831     6831           
=======================================
  Hits         4750     4750           
  Misses       2081     2081           

☔ 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.

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: 1

🧹 Nitpick comments (6)
scripts/build_images.py (6)

1-16: Documentation looks good, but could use execution context.

The documentation clearly explains how to use the script with good examples. Consider adding a note about the expected working directory for running the script.

 """
 This script can be used to build all/selected docker/singularity images.
 0. Load your virtual environment like you would when using AMLB.
+0a. Navigate to the 'scripts' directory before running this script.
 1. Run the script with the required mode:
     python build_images.py -m docker
     python build_images.py -m singularity

18-23: Remove redundant import.

You're importing both pathlib and Path from pathlib, which is redundant.

 import os
 import argparse
-import pathlib
 from pathlib import Path
 from typing import List, Optional

Then update the type annotation in delete_singularity_files function accordingly.


25-44: Ensure consistent case handling in framework matching.

The function lowers the case of the file name but not the frameworks when checking if a framework is in the file name. While frameworks are lowercased when created in get_frameworks, there's no guarantee they'll be passed that way to this function.

 def delete_singularity_files(
-    directory: pathlib.Path, frameworks: Optional[List[str]] = None
+    directory: Path, frameworks: Optional[List[str]] = None
 ) -> None:
     """Deletes Singularity-related files from the specified directory."""
     for root, _, files in os.walk(directory):
         for file in files:
             if file == "Singularityfile" or file.endswith(".sif"):
                 file_path = Path(root) / file

                 if frameworks and not any(
-                    framework in file_path.name.lower() for framework in frameworks
+                    framework.lower() in file_path.name.lower() for framework in frameworks
                 ):
                     continue

46-63: Add validation for mode argument.

The parser should validate that the mode is either "docker" or "singularity" to prevent errors later in the script.

     parser.add_argument(
-        "-m", "--mode", help="Docker or singularity", type=str, required=True
+        "-m", "--mode", 
+        help="Docker or singularity", 
+        type=str, 
+        required=True,
+        choices=["docker", "singularity"]
     )

66-78: Validate user-specified frameworks.

The function doesn't check if user-specified frameworks exist in the framework directory, which could lead to errors later.

 def get_frameworks(framework_dir: Path, user_input: Optional[str]) -> List[str]:
     """Gets the list of frameworks based on user input or directory listing."""
+    available_frameworks = [
+        framework.lower()
+        for framework in os.listdir(framework_dir)
+        if "__" not in framework
+    ]
+    
     if user_input:
         frameworks = [framework.lower().strip() for framework in user_input.split(",")]
+        # Validate user-specified frameworks
+        invalid_frameworks = [f for f in frameworks if f not in available_frameworks]
+        if invalid_frameworks:
+            print(f"Warning: The following frameworks were not found: {invalid_frameworks}")
+            frameworks = [f for f in frameworks if f in available_frameworks]
+            if not frameworks:
+                print("No valid frameworks specified. Exiting.")
+                exit(1)
         print(f"Running for given frameworks - {frameworks}")
     else:
-        frameworks = [
-            framework.lower()
-            for framework in os.listdir(framework_dir)
-            if "__" not in framework
-        ]
+        frameworks = available_frameworks
         print(f"Running for all frameworks - {frameworks}")
     return frameworks

83-83: Use absolute paths for better reliability.

The script uses relative paths (../frameworks/ and ../runbenchmark.py), which means it must be run from a specific location. Using absolute paths would make the script more robust.

 def main() -> None:
     args = parse_arguments()
-    framework_dir = Path("../frameworks/")
+    # Get the absolute path of the script
+    script_dir = Path(__file__).parent.absolute()
+    # Get the absolute path of the project root (parent of scripts directory)
+    project_root = script_dir.parent
+    framework_dir = project_root / "frameworks"

Then update the path to runbenchmark.py in the subprocess call:

             subprocess.run(
-                ["python", "../runbenchmark.py", framework, "openml/t/3812", "--mode", mode, "--setup", "only"],
+                ["python", str(project_root / "runbenchmark.py"), framework, "openml/t/3812", "--mode", mode, "--setup", "only"],
                 input=b"yes\n" * 10,
                 check=True
             )
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 0f7b169 and 6ad268c.

📒 Files selected for processing (2)
  • .gitignore (1 hunks)
  • scripts/build_images.py (1 hunks)
🔇 Additional comments (1)
.gitignore (1)

14-14: LGTM: Good addition to .gitignore.

Adding .venv/ is a sensible enhancement that complements the existing venv/ entry, ensuring Git ignores virtual environments regardless of the naming convention used.

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.

2 participants