Resolve script paths in config.
(script_arg_name, config)
| 21 | |
| 22 | |
| 23 | def process_test_script_path(script_arg_name, config): |
| 24 | """Resolve script paths in config.""" |
| 25 | config_file = config.config_name |
| 26 | script_input_path = getattr(config, script_arg_name, None) |
| 27 | if script_input_path is None: |
| 28 | return config |
| 29 | |
| 30 | # Check if the script path is absolute and keep the same path |
| 31 | if isinstance(script_input_path, str) and script_input_path.startswith("/"): |
| 32 | if not os.path.exists(script_input_path): |
| 33 | raise FileNotFoundError( |
| 34 | f"File not found: Path for {script_arg_name} not found: {script_input_path}. Set it to the absolute path or relative to the config file.\n" |
| 35 | ) |
| 36 | return config |
| 37 | |
| 38 | # Otherwise the script path is relative |
| 39 | # First look for it in the config file directory, then the renderer directory |
| 40 | config_dir = os.path.dirname(os.path.abspath(config_file)) |
| 41 | config_relative_path = os.path.join(config_dir, script_input_path) |
| 42 | renderer_dir = os.path.dirname(os.path.abspath(__file__)) |
| 43 | renderer_relative_path = os.path.join(renderer_dir, script_input_path) |
| 44 | if os.path.exists(config_relative_path): |
| 45 | setattr(config, script_arg_name, config_relative_path) |
| 46 | elif os.path.exists(renderer_relative_path): |
| 47 | setattr(config, script_arg_name, renderer_relative_path) |
| 48 | else: |
| 49 | raise FileNotFoundError( |
| 50 | f"File not found: Path for {script_arg_name} not found: {script_input_path}. Set it to the absolute path or relative to the config file.\n" |
| 51 | ) |
| 52 | return config |
| 53 | |
| 54 | |
| 55 | def non_empty_string(s): |