Skip to content

Commit

Permalink
fix(read_configuration_file): Add isinstance for optional inputs.
Browse files Browse the repository at this point in the history
It is necessary to check if optional path inputs are Path if they are set to None by default, unlike the required inputs which can be converted to str without any isinstance
  • Loading branch information
mgcooper committed May 6, 2024
1 parent 216d027 commit d68885d
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 5 deletions.
4 changes: 2 additions & 2 deletions examples/susquehanna/run_simulation_mpas.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import os, sys
from pathlib import Path

from pyflowline.configuration.change_json_key_value import pyflowline_change_json_key_value
from pyflowline.configuration.read_configuration_file import pyflowline_read_configuration_file
from pyflowline.configuration.change_json_key_value import pyflowline_change_json_key_value
from pyflowline.configuration import path_manager as pyflowline_path_manager

#%% Define the case information (configuration file parameters)
Expand Down Expand Up @@ -103,7 +103,7 @@
iCase_index_in=iCase_index,
sDate_in=sDate)

# Check the model parameters
#%% Check the model parameters
oPyflowline.pyflowline_print()

#%% Now we can change some model parameters
Expand Down
9 changes: 6 additions & 3 deletions pyflowline/configuration/read_configuration_file.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,10 @@ def pyflowline_read_configuration_file(
_type_: _description_
"""
# Ensure input filenames are strings
sFilename_configuration_in = str(sFilename_configuration_in)
sWorkspace_output_in = str(sWorkspace_output_in)
if isinstance(sFilename_configuration_in, Path):
sFilename_configuration_in = str(sFilename_configuration_in)
if isinstance(sWorkspace_output_in, Path):
sWorkspace_output_in = str(sWorkspace_output_in)

if not os.path.isfile(sFilename_configuration_in):
print(sFilename_configuration_in + ' does not exist')
Expand Down Expand Up @@ -120,8 +122,9 @@ def pyflowline_read_configuration_file(
# try to create this output folder first using

try:
print(sWorkspace_output)
print("Creating the specified output workspace (if it does not exist): \n", sWorkspace_output)
Path(sWorkspace_output).mkdir(parents=True, exist_ok=True)
print("The specified output workspace is: \n", sWorkspace_output)
except ValueError:
print("The specified output workspace cannot be created!")
exit
Expand Down

0 comments on commit d68885d

Please sign in to comment.