summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorHarmen Stoppels <me@harmenstoppels.nl>2024-08-27 15:55:44 +0200
committerGitHub <noreply@github.com>2024-08-27 15:55:44 +0200
commit0fee2c234ef1eda5483a2da5c6bd679c48d7ab26 (patch)
tree222bff93df93104573cb214b1a8bfaa13ce6cb3b /lib
parent229cf49c71c7461f06d0b5a5a07976935c9da37d (diff)
downloadspack-0fee2c234ef1eda5483a2da5c6bd679c48d7ab26.tar.gz
spack-0fee2c234ef1eda5483a2da5c6bd679c48d7ab26.tar.bz2
spack-0fee2c234ef1eda5483a2da5c6bd679c48d7ab26.tar.xz
spack-0fee2c234ef1eda5483a2da5c6bd679c48d7ab26.zip
config.py: tell don't ask (#46040)
Diffstat (limited to 'lib')
-rw-r--r--lib/spack/spack/config.py33
1 files changed, 13 insertions, 20 deletions
diff --git a/lib/spack/spack/config.py b/lib/spack/spack/config.py
index 765954c8f2..82962d36fb 100644
--- a/lib/spack/spack/config.py
+++ b/lib/spack/spack/config.py
@@ -1090,7 +1090,7 @@ def validate(
def read_config_file(
- filename: str, schema: Optional[YamlConfigDict] = None
+ path: str, schema: Optional[YamlConfigDict] = None
) -> Optional[YamlConfigDict]:
"""Read a YAML configuration file.
@@ -1100,21 +1100,9 @@ def read_config_file(
# to preserve flexibility in calling convention (don't need to provide
# schema when it's not necessary) while allowing us to validate against a
# known schema when the top-level key could be incorrect.
-
- if not os.path.exists(filename):
- # Ignore nonexistent files.
- tty.debug(f"Skipping nonexistent config path {filename}", level=3)
- return None
-
- elif not os.path.isfile(filename):
- raise ConfigFileError(f"Invalid configuration. {filename} exists but is not a file.")
-
- elif not os.access(filename, os.R_OK):
- raise ConfigFileError(f"Config file is not readable: {filename}")
-
try:
- tty.debug(f"Reading config from file {filename}")
- with open(filename) as f:
+ with open(path) as f:
+ tty.debug(f"Reading config from file {path}")
data = syaml.load_config(f)
if data:
@@ -1125,15 +1113,20 @@ def read_config_file(
return data
- except StopIteration:
- raise ConfigFileError(f"Config file is empty or is not a valid YAML dict: {filename}")
+ except FileNotFoundError:
+ # Ignore nonexistent files.
+ tty.debug(f"Skipping nonexistent config path {path}", level=3)
+ return None
+
+ except OSError as e:
+ raise ConfigFileError(f"Path is not a file or is not readable: {path}: {str(e)}") from e
+
+ except StopIteration as e:
+ raise ConfigFileError(f"Config file is empty or is not a valid YAML dict: {path}") from e
except syaml.SpackYAMLError as e:
raise ConfigFileError(str(e)) from e
- except OSError as e:
- raise ConfigFileError(f"Error reading configuration file {filename}: {str(e)}") from e
-
def _override(string: str) -> bool:
"""Test if a spack YAML string is an override.