Skip to content

Commit 2406a46

Browse files
committed
Added logic to 'read_config()' to look for a 'MURFEY_CLIENT_CONFIGURATION' file first before defaulting to looking for 'MURFEY_CLIENT_CONFIG_HOME' and then the default home
1 parent 896a4a9 commit 2406a46

File tree

1 file changed

+12
-5
lines changed

1 file changed

+12
-5
lines changed

src/murfey/util/client.py

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,20 @@
2525
def read_config() -> configparser.ConfigParser:
2626
config = configparser.ConfigParser()
2727
try:
28-
mcch = os.environ.get("MURFEY_CLIENT_CONFIG_HOME")
29-
murfey_client_config_home = Path(mcch) if mcch else Path.home()
30-
with open(murfey_client_config_home / ".murfey") as configfile:
31-
config.read_file(configfile)
28+
# Look for 'MURFEY_CLIENT_CONFIGURATION' environment variable first
29+
mcc = os.environ.get("MURFEY_CLIENT_CONFIGURATION")
30+
if mcc:
31+
config_file = Path(mcc)
32+
# If not set, look for 'MURFEY_CLIENT_CONFIG_HOME' or '~', and then to look for '.murfey'
33+
else:
34+
mcch = os.environ.get("MURFEY_CLIENT_CONFIG_HOME")
35+
murfey_client_config_home = Path(mcch) if mcch else Path.home()
36+
config_file = murfey_client_config_home / ".murfey"
37+
with open(config_file) as file:
38+
config.read_file(file)
3239
except FileNotFoundError:
3340
logger.warning(
34-
f"Murfey client configuration file {murfey_client_config_home / '.murfey'} not found"
41+
f"Murfey client configuration file {str(config_file)!r} not found"
3542
)
3643
if "Murfey" not in config:
3744
config["Murfey"] = {}

0 commit comments

Comments
 (0)