Skip to content

Commit

Permalink
CLI argument handling and some package inclusion fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
j-bryan committed Mar 4, 2024
1 parent 1a3c742 commit 2285dff
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 17 deletions.
25 changes: 19 additions & 6 deletions package/raven_framework.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,28 +23,41 @@
from ravenframework.Driver import main
from ui import run_from_gui
from utils import add_local_bin_to_path
import multiprocessing


if __name__ == '__main__':
# For Windows, this is required to avoid an infinite loop when running a multiprocessing script from a frozen executable.
# cx_Freeze provides a hook for this that is supposed to be called automatically to fix this issue on all platforms,
# but for now, it doesn't seem to resolve the issue on macOS.
multiprocessing.freeze_support()

# Adds the "local/bin" directory to the system path in order to find ipopt and other executables
add_local_bin_to_path()

# Parse the command line arguments
import argparse
parser = argparse.ArgumentParser(description='RAVEN')
parser.add_argument('-w', action='store_true', default=False, required=False,help='Run in the GUI')
parser.add_argument('input', nargs='?', help='RAVEN input file')
parser.add_argument('input', nargs='*', help='RAVEN input file')
args, unknown = parser.parse_known_args()

# if the input file is not an xml file, assume it's an unknown argument
if args.input and not args.input.endswith('.xml'):
unknown.insert(unknown, args.input)
args.input = None
# More than one argument may be parsed for "input". Move any arguments that aren't an XML file to
# the unknown arguments list.
args_to_move = []
for arg in args.input:
if not arg.endswith('.xml'):
args_to_move.append(arg)
for arg in args_to_move:
args.input.remove(arg)
unknown.insert(0, arg)

# sys.argv is used by the main function, so we need to remove the -w argument
if args.w:
sys.argv.remove('-w')

print('FORCE/package/raven_framework.py sys.argv =', sys.argv)
print('FORCE/package/raven_framework.py args =', args)
print('FORCE/package/raven_framework.py unknown =', unknown)
if args.w or not args.input: # run the GUI if asked to (-w) or if no input file is given
run_from_gui(main, checkLibraries=True)
else:
Expand Down
10 changes: 7 additions & 3 deletions package/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@


build_exe_options = {
"packages": ["ravenframework","msgpack","ray","crow_modules","AMSC","sklearn","pyomo","HERON","TEAL","pyarrow","netCDF4","cftime","distributed"],
"includes": ["ray.thirdparty_files.colorama","ray.autoscaler._private","pyomo.common.plugins","HERON.templates.template_driver"],
"packages": ["ravenframework","msgpack","ray","crow_modules","AMSC","sklearn","pyomo","HERON","TEAL","pyarrow","netCDF4","cftime","distributed","dask","tensorflow"],
"includes": ["ray.thirdparty_files.colorama","ray.autoscaler._private","pyomo.common.plugins","HERON.templates.template_driver","dask.distributed"],
"include_files": [(HERON.templates.write_inner.__file__,"lib/HERON/templates/write_inner.py")],
}

Expand All @@ -23,7 +23,11 @@
]
# Include the Microsoft Visual C++ Runtime
build_exe_options["include_msvcr"] = True

else:
ipopt_path = os.path.join(os.path.dirname(sys.executable), "ipopt")
build_exe_options["include_files"] += [
(ipopt_path, "local/bin/ipopt")
]

setup(
name="force",
Expand Down
6 changes: 2 additions & 4 deletions package/ui/controllers/file_dialog.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,7 @@ def __init__(self, view, file_type=None, is_output=False, persistence=None):
else:
self.view.browse_button.config(command=self.open_selection_dialog)

@property
def filename(self):
def get_filename(self):
"""
filename getter
@In, None
Expand All @@ -38,8 +37,7 @@ def filename(self):
return None
return self._filename

@filename.setter
def filename(self, value):
def set_filename(self, value):
"""
filename setter
@In, value, str, the filename
Expand Down
8 changes: 4 additions & 4 deletions package/ui/controllers/file_selection.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ def __init__(self, model, view):
self.file_dialog_controllers = {}

# Remember the file locations for the user
self.file_location_persistence = FileLocationPersistence()
self.persistence = FileLocationPersistence()

# Create the file selectors, adding any files specified from the command line
model_package_name = model.get_package_name().strip().lower()
Expand All @@ -80,11 +80,11 @@ def __init__(self, model, view):
view=self.file_selection.file_selectors[spec.description],
file_type=spec.file_type,
is_output=spec.is_output,
persistence=self.file_location_persistence
persistence=self.persistence
)
if filename := args.get(spec.arg_name, None):
file_dialog_controller.set_filename(filename)
self.file_location_persistence.set_file_location(filename)
self.persistence.set_location(filename)
self.file_dialog_controllers[spec.description] = file_dialog_controller

def get_sys_args_from_file_selection(self):
Expand All @@ -97,7 +97,7 @@ def get_sys_args_from_file_selection(self):
args = []
for spec in self._file_specs:
# Get the filename from the file selector
filename = self.file_dialog_controllers[spec.description].filename
filename = self.file_dialog_controllers[spec.description].get_filename()
# Add the filename with its corresponding argument flag to the list
if not os.path.exists(filename) and spec.arg_name != '-o':
raise FileNotFoundError(f"File {filename} not found")
Expand Down

0 comments on commit 2285dff

Please sign in to comment.