augur.config module
Helpers for YAML-based configuration files.
- augur.config.get_search_paths(config_file=None)
Returns search paths for relative filepaths.
The working directory is always included.
If
config_fileis set, its parent directory is included.If
AUGUR_SEARCH_PATHSis set, each path in the colon-delimited list is included.
- augur.config.resolve_filepath(path, search_paths)
Resolve a filepath by searching through multiple directories.
- Parameters:
- Return type:
Examples
If the path is already absolute, verify it exists and return it.
>>> import tempfile >>> tmpdir1 = Path(tempfile.mkdtemp()).resolve() >>> tmpdir2 = Path(tempfile.mkdtemp()).resolve() >>> absolute_path = tmpdir1 / "file.txt" >>> with open(absolute_path, "w") as f: _ = f.write("test") >>> resolve_filepath(absolute_path, []) == absolute_path True
Otherwise, try resolving it relative to each directory in search_paths, in order. Return the first path that exists.
>>> with open(tmpdir2 / "file.txt", "w") as f: _ = f.write("test") >>> result = resolve_filepath(Path("file.txt"), [tmpdir1, tmpdir2]) >>> result == tmpdir1 / "file.txt" True
If an absolute path doesn’t exist, raise an error.
>>> resolve_filepath(Path("/nonexistent/file.txt"), [tmpdir1, tmpdir2]) Traceback (most recent call last): ... augur.errors.AugurError: File '/nonexistent/file.txt' does not exist.
If the relative path doesn’t exist anywhere, raise an error.
>>> resolve_filepath(Path("nonexistent.txt"), [tmpdir1, tmpdir2]) Traceback (most recent call last): ... augur.errors.AugurError: File 'nonexistent.txt' not resolvable from any of the following paths: ...