-
Notifications
You must be signed in to change notification settings - Fork 8
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
Fix bugs with Sun Grid Engine #382
Conversation
for more information, see https://pre-commit.ci
WalkthroughThe pull request introduces a new static method Changes
Sequence DiagramsequenceDiagram
participant User
participant SunGridEngineCommands
User->>SunGridEngineCommands: get_job_id_from_output(queue_submit_output)
SunGridEngineCommands-->>User: Returns job ID as integer
Poem
📜 Recent review detailsConfiguration used: CodeRabbit UI 📒 Files selected for processing (1)
🚧 Files skipped from review as they are similar to previous changes (1)
⏰ Context from checks skipped due to timeout of 90000ms (1)
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? 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
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)
Other keywords and placeholders
CodeRabbit Configuration File (
|
There was a problem hiding this 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
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (1)
pysqa/wrapper/sge.py
(1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (6)
- GitHub Check: build (ubuntu-latest, 3.9)
- GitHub Check: build (ubuntu-latest, 3.13)
- GitHub Check: build (windows-latest, 3.13)
- GitHub Check: build
- GitHub Check: build (macos-latest, 3.13)
- GitHub Check: build
🔇 Additional comments (1)
pysqa/wrapper/sge.py (1)
85-88
: Verify consistency with other scheduler implementations.Let's ensure this implementation aligns with other scheduler wrappers and the base class.
✅ Verification successful
Implementation is consistent with scheduler framework
The
get_job_id_from_output
method:
- Follows the abstract base class contract
- Uses the same parsing strategy as Slurm for the -terse output format
- Is properly integrated with the job submission workflow
🏁 Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash # Description: Check for similar job ID parsing methods in other scheduler implementations # and verify the -terse flag behavior in SGE documentation. # Check for similar methods in other scheduler implementations echo "Checking for similar methods in other scheduler implementations..." rg -l "job_id.*output" --type py # Look for the base class implementation echo -e "\nChecking base class (SchedulerCommands) implementation..." rg -l "class SchedulerCommands" --type py # Check if other classes parse job IDs differently echo -e "\nChecking for other job ID parsing patterns..." rg "job.*id.*=|jobid.*=|id.*=.*job" --type py # Look for SGE documentation references echo -e "\nChecking for SGE documentation or test files..." fd -e rst -e md -e txt . | xargs rg -l "qsub.*terse"Length of output: 4089
Script:
#!/bin/bash # Check base class and implementations echo "Checking base class for job ID parsing methods..." ast-grep --pattern 'class SchedulerCommands { $$$ get_job_id_from_output($$$) { $$$ } $$$ }' echo -e "\nChecking specific implementations of get_job_id_from_output..." rg "get_job_id_from_output" -B 2 -A 4 --type py echo -e "\nChecking SGE submit command construction..." rg "submit_job_command" -B 2 -A 4 pysqa/wrapper/sge.pyLength of output: 5439
pysqa/wrapper/sge.py
Outdated
@staticmethod | ||
def get_job_id_from_output(queue_submit_output: str) -> int: | ||
"""Extracts the job ID from the output of the job submission command.""" | ||
return int(queue_submit_output.splitlines()[-1].rstrip().lstrip().split()[-1]) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🛠️ Refactor suggestion
Add error handling and simplify the parsing logic.
The current implementation makes assumptions about the output format and lacks error handling. Since the class uses the -terse
flag in submit_job_command
, the output should contain only the job ID.
Consider this safer implementation:
@staticmethod
def get_job_id_from_output(queue_submit_output: str) -> int:
- """Extracts the job ID from the output of the job submission command."""
+ """Extracts the job ID from the output of the job submission command.
+
+ Args:
+ queue_submit_output: Output string from qsub -terse command
+ containing only the job ID.
+
+ Returns:
+ The extracted job ID as an integer.
+
+ Raises:
+ ValueError: If the output is empty or contains an invalid job ID.
+
+ Example:
+ >>> SunGridEngineCommands.get_job_id_from_output("123456\\n")
+ 123456
+ """
+ if not queue_submit_output:
+ raise ValueError("Empty output from job submission command")
+ try:
+ return int(queue_submit_output.strip())
+ except ValueError as e:
+ raise ValueError(f"Invalid job ID in output: {queue_submit_output!r}") from e
📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
@staticmethod | |
def get_job_id_from_output(queue_submit_output: str) -> int: | |
"""Extracts the job ID from the output of the job submission command.""" | |
return int(queue_submit_output.splitlines()[-1].rstrip().lstrip().split()[-1]) | |
@staticmethod | |
def get_job_id_from_output(queue_submit_output: str) -> int: | |
"""Extracts the job ID from the output of the job submission command. | |
Args: | |
queue_submit_output: Output string from qsub -terse command | |
containing only the job ID. | |
Returns: | |
The extracted job ID as an integer. | |
Raises: | |
ValueError: If the output is empty or contains an invalid job ID. | |
Example: | |
>>> SunGridEngineCommands.get_job_id_from_output("123456\\n") | |
123456 | |
""" | |
if not queue_submit_output: | |
raise ValueError("Empty output from job submission command") | |
try: | |
return int(queue_submit_output.strip()) | |
except ValueError as e: | |
raise ValueError(f"Invalid job ID in output: {queue_submit_output!r}") from e |
Summary by CodeRabbit