From dea2f45155e5b3a6e91f39b8456c9b0b39058a97 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Guilhem=20Faur=C3=A9?= Date: Wed, 21 Jun 2023 11:54:27 +0200 Subject: [PATCH] =?UTF-8?q?config=20don=E2=80=99t=20read=20cli=20args=20di?= =?UTF-8?q?rectly?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- spip2md/config.py | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/spip2md/config.py b/spip2md/config.py index 38ecb66..aae0471 100644 --- a/spip2md/config.py +++ b/spip2md/config.py @@ -23,12 +23,10 @@ from yaml import Loader, load NAME: str = "spip2md" # Name of program, notably used in logs -# Searches for a configuration file from all CLI args and in standard locations -# & return his path if found +# Searches for a configuration file from standard locations or params def config(*start_locations: str) -> Optional[str]: - # Search for config files in CLI arguments and function params first - argv = __import__("sys").argv - config_locations: list[str] = argv[1:] + list(start_locations) + # Search for config files in function params first + config_locations: list[str] = list(start_locations) if "XDG_CONFIG_HOME" in environ: config_locations += [ @@ -50,6 +48,7 @@ def config(*start_locations: str) -> Optional[str]: "/spip2md.yaml", ] + # Return the first path that actually exists for path in config_locations: if isfile(path): return path @@ -98,6 +97,3 @@ class Configuration: setattr(self, attr, directory) else: setattr(self, attr, config[attr]) - - -CFG = Configuration(config())