-
Notifications
You must be signed in to change notification settings - Fork 3
Move get_command_path() to separate module #438
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| import os | ||
|
|
||
|
|
||
| def get_command_path(executable: str) -> str: | ||
| """ | ||
| Get path of the backend executable script | ||
|
|
||
| Args: | ||
| executable (str): Name of the backend executable script, either mpiexec.py or serial.py | ||
|
|
||
| Returns: | ||
| str: absolute path to the executable script | ||
| """ | ||
| return os.path.abspath(os.path.join(__file__, "..", "..", "backend", executable)) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 💡 Codebase verification Path resolution logic needs correction The current implementation has issues:
🔗 Analysis chainVerify the path resolution logic across the codebase. Let's ensure the path resolution works correctly in different contexts where this function might be used. Let me gather more information about the backend directory structure and the actual Python files being referenced. 🏁 Scripts executedThe following scripts were executed for the analysis: Script: #!/bin/bash
# Description: Verify the backend directory structure and usage of get_command_path
# Test 1: Check if backend directory exists and contains expected files
echo "Checking backend directory structure..."
fd -t f -p "backend/(mpiexec|serial)\.py$"
# Test 2: Find all references to get_command_path to understand usage patterns
echo -e "\nChecking get_command_path usage..."
rg "get_command_path\(" -A 2
Length of output: 1247 Script: #!/bin/bash
# Check the actual backend directory content and verify the Python files
echo "Listing all files in backend directory:"
fd . "backend/"
echo -e "\nChecking content of the Python files to verify they exist and are properly referenced:"
for file in "interactive_parallel.py" "interactive_serial.py" "cache_parallel.py" "cache_serial.py"; do
echo -e "\nChecking $file:"
fd -t f "$file"
done
# Check the actual implementation of get_command_path function
echo -e "\nChecking get_command_path implementation:"
rg -A 5 "def get_command_path" executorlib/shared/command.py
Length of output: 1746 |
||
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.
Add input validation and path verification.
While the function works, it could benefit from additional safety checks:
Here's a suggested improvement:
def get_command_path(executable: str) -> str: """ Get path of the backend executable script Args: - executable (str): Name of the backend executable script, either mpiexec.py or serial.py + executable (str): Name of the backend executable script + + Raises: + ValueError: If executable is not one of: mpiexec.py, serial.py + FileNotFoundError: If the executable path does not exist Returns: str: absolute path to the executable script """ + allowed_executables = {'mpiexec.py', 'serial.py'} + if executable not in allowed_executables: + raise ValueError(f"Executable must be one of: {', '.join(allowed_executables)}") + path = os.path.abspath(os.path.join(__file__, "..", "..", "backend", executable)) + if not os.path.exists(path): + raise FileNotFoundError(f"Executable not found at: {path}") + return path📝 Committable suggestion