aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRickard Bolin <rickard.bolin@arm.com>2022-05-24 14:17:58 +0000
committerRickard Bolin <rickard.bolin@arm.com>2022-05-24 14:43:38 +0000
commit6d7a4f0e0d230188be0aea75d7c81659ee60ecbf (patch)
tree3a16a679c9f5cbdd0bf1cc3e3bb78646c6348138
parent9b8b4489558e41b4e5862bf3793cd089e3ad28f8 (diff)
downloadethos-u-vela-6d7a4f0e0d230188be0aea75d7c81659ee60ecbf.tar.gz
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 <rickard.bolin@arm.com> Change-Id: I7f7d4f904b9fbba97593e42203566057a2d36925
-rw-r--r--ethosu/vela/vela.py27
1 files 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