Resolve the config file path by searching in two locations: 1. Directory of the plain file 2. Current working directory (where render is called from) Returns the resolved absolute path, or None if the file is not found in either location. Raises AmbiguousConfigFileError if the
(config_name: str, plain_file_path: str)
| 86 | |
| 87 | |
| 88 | def resolve_config_file(config_name: str, plain_file_path: str): |
| 89 | """ |
| 90 | Resolve the config file path by searching in two locations: |
| 91 | 1. Directory of the plain file |
| 92 | 2. Current working directory (where render is called from) |
| 93 | |
| 94 | Returns the resolved absolute path, or None if the file is not found in either location. |
| 95 | Raises AmbiguousConfigFileError if the file exists in both locations (and they differ). |
| 96 | """ |
| 97 | plain_file_dir = os.path.dirname(os.path.abspath(plain_file_path)) |
| 98 | cwd = os.getcwd() |
| 99 | |
| 100 | plain_dir_config = os.path.normpath(os.path.join(plain_file_dir, config_name)) |
| 101 | cwd_config = os.path.normpath(os.path.join(cwd, config_name)) |
| 102 | |
| 103 | in_plain_dir = os.path.exists(plain_dir_config) |
| 104 | in_cwd = os.path.exists(cwd_config) |
| 105 | same_location = plain_dir_config == cwd_config |
| 106 | |
| 107 | if in_plain_dir and in_cwd and not same_location: |
| 108 | raise AmbiguousConfigFileError( |
| 109 | f"Config file '{config_name}' was found in two locations:\n" |
| 110 | f" - Plain file directory: {plain_file_dir}\n" |
| 111 | f" - Current working directory: {cwd}\n" |
| 112 | f"Remove the config file from one of these locations to resolve the ambiguity." |
| 113 | ) |
| 114 | |
| 115 | if in_plain_dir: |
| 116 | return plain_dir_config |
| 117 | if in_cwd: |
| 118 | return cwd_config |
| 119 | return None |
| 120 | |
| 121 | |
| 122 | def update_args_with_config(args, parser): |