Skip to content

Commit 8efef32

Browse files
committed
Moved config file path resolution logic out of try-except block
1 parent ac91f96 commit 8efef32

File tree

1 file changed

+12
-9
lines changed

1 file changed

+12
-9
lines changed

src/murfey/util/client.py

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -24,16 +24,19 @@
2424

2525
def read_config() -> configparser.ConfigParser:
2626
config = configparser.ConfigParser()
27+
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+
38+
# Attempt to read the file and return the config
2739
try:
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"
3740
with open(config_file) as file:
3841
config.read_file(file)
3942
except FileNotFoundError:

0 commit comments

Comments
 (0)