augur.config moduleď
Helpers for YAML-based configuration files.
- 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: ...