From d68885d6ff082a2e5e76fd523e92cebc4468e7de Mon Sep 17 00:00:00 2001 From: mgcooper Date: Mon, 6 May 2024 11:19:35 -0700 Subject: [PATCH] fix(read_configuration_file): Add isinstance for optional inputs. 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 --- examples/susquehanna/run_simulation_mpas.py | 4 ++-- pyflowline/configuration/read_configuration_file.py | 9 ++++++--- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/examples/susquehanna/run_simulation_mpas.py b/examples/susquehanna/run_simulation_mpas.py index 7b612eb..1bc32e8 100644 --- a/examples/susquehanna/run_simulation_mpas.py +++ b/examples/susquehanna/run_simulation_mpas.py @@ -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) @@ -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 diff --git a/pyflowline/configuration/read_configuration_file.py b/pyflowline/configuration/read_configuration_file.py index a982740..8d26d46 100644 --- a/pyflowline/configuration/read_configuration_file.py +++ b/pyflowline/configuration/read_configuration_file.py @@ -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') @@ -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