From 6d7a4f0e0d230188be0aea75d7c81659ee60ecbf Mon Sep 17 00:00:00 2001 From: Rickard Bolin Date: Tue, 24 May 2022 14:17:58 +0000 Subject: MLBEDSW-4783: Fix issue with relative paths to config files One level deep relative paths (ie ./vela.ini) were treated as the name of a folder in config_files was ".". They are now treated as relative paths. The warning message when using an absolute path has also been moved to to the error message instead for a better user experience. Signed-off-by: Rickard Bolin Change-Id: I7f7d4f904b9fbba97593e42203566057a2d36925 --- ethosu/vela/vela.py | 27 ++++++++++++++++++--------- 1 file changed, 18 insertions(+), 9 deletions(-) diff --git a/ethosu/vela/vela.py b/ethosu/vela/vela.py index ee4de5d..bbacc9c 100644 --- a/ethosu/vela/vela.py +++ b/ethosu/vela/vela.py @@ -467,20 +467,29 @@ def main(args=None): if not config.endswith(".ini"): raise InputFileError(config, "Configuration files must use the .ini extension") - if len(config.split(os.path.sep)) == 2 and not config.startswith(os.path.sep): + if ( + len(config.split(os.path.sep)) == 2 + and not config.startswith(os.path.sep) + and not config.startswith(".") + and not config.startswith("~") + ): config_path = os.path.join(CONFIG_FILES_PATH, config) else: - print( - f"Warning: Configuration file `{config}` is either not located in a folder directly under the " - "`config_files` directory or has not been provided correctly. Note that the file depth from the " - "`config_files` directory must be exactly 2 to be discovered via the --list-config-files " - "mechanism (e.g. `directory_name/my_config_file.ini` located in the config_files directory). " - "This config file will still be parsed however, and treated as an absolute path config instead." - ) + # Check if the configuration file is correctly placed inside the config_files directory + if os.access(os.path.join(CONFIG_FILES_PATH, *config.split(os.path.sep)[-2:]), os.R_OK): + rel_path = os.path.join(*config.split(os.path.sep)[-2:]) + print( + f"Warning: Consider accessing the configuration by --config {rel_path} since it is located " + "inside the config_files directory." + ) config_path = config if not os.access(config_path, os.R_OK): - raise InputFileError(config_path, "File not found or is not readable") + raise InputFileError( + config_path, + "File not found or is not readable. The configuration file is either not located in a folder " + "directly under the `config_files` directory or its path has not been provided correctly.", + ) return config_path -- cgit v1.2.1