Skip to content

Commit

Permalink
extra handling for finding raven_framework in common places
Browse files Browse the repository at this point in the history
  • Loading branch information
j-bryan committed Apr 12, 2024
1 parent 57d2811 commit fcdbf2e
Showing 1 changed file with 22 additions and 6 deletions.
28 changes: 22 additions & 6 deletions ravenframework/Models/Code.py
Original file line number Diff line number Diff line change
Expand Up @@ -582,18 +582,34 @@ def evaluateSample(self, myInput, samplerType, kwargs):
and sys.argv[0].endswith(".py"):
# command was "python path/to/raven_framework.py ..."
ravenExecutable = f"{sys.executable} {sys.argv[0]}"
# Ideally, we have already found the raven_framework executable, but if we haven't, we can look
# for it in a few other places before giving up. This seems to help mostly with cases where qsub
# is used for parallel execution, which can muddy the way the command was run. In both cases,
# we raise a message for the user to be explicit on how the executable was found and where it is
# located.
elif (ravenframeworkInPath := shutil.which("raven_framework")) is not None:
# This is the case where a raven_framework is in the path. This would be the case in a pip
# installed RAVEN.
ravenExecutable = ravenframeworkInPath
self.raiseAMessage(f"Using raven_framework found in path: {ravenExecutable}")
elif os.path.exists(os.path.join(kwargs["FRAMEWORK_DIR"], ".." "raven_framework")):
# Finally, we can look relative to the framework directory for a raven_framework file.
ravenExecutable = os.path.join(kwargs["FRAMEWORK_DIR"], ".." "raven_framework")
self.raiseAMessage(f"Using raven_framework found in framework directory: {ravenExecutable}")
else:
ravenExecutable = ''

if "%RAVENEXECUTABLE%" in command and ravenExecutable == '':
message = f"""The command contains %RAVENEXECUTABLE% but the way the outer framework was run
could not be inferred. Only using scripts or executables that contain 'raven_framework' or
using python to run a .py file with 'raven_framework' in the name is supported. sys.executable
is {sys.executable}, sys.argv[0] is {sys.argv[0]}. Here is everything else I can think you
might want to see:
command: {command}
kwargs: {kwargs}
sys.argv: {sys.argv}"""
using python to run a .py file with 'raven_framework' in the name is supported. Possibilities
considered were:
1. 'raven_framework' in sys.executable (received: {sys.executable})
2. 'raven_framework' in sys.argv[0] (received: {sys.argv[0]})
3. 'raven_framework' in the path (not found)
4. 'raven_framework' in directory {os.path.join(kwargs["FRAMEWORK_DIR"], "..")} (not found)
Note that users may also directly specify the path to an appropriate raven_framework
executable instead of using the %RAVENEXECUTABLE% placeholder."""
self.raiseAnError(IOError, message)

command = command.replace("%RAVENEXECUTABLE%", ravenExecutable)
Expand Down

0 comments on commit fcdbf2e

Please sign in to comment.