Skip to content

Commit 70971c4

Browse files
authored
fix: avoid reloading the configuration file multiple times (#70)
1 parent a3e46c0 commit 70971c4

File tree

1 file changed

+11
-3
lines changed

1 file changed

+11
-3
lines changed

gitstats/__init__.py

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,18 +26,26 @@
2626
}
2727

2828

29+
_config = None
30+
31+
2932
def load_config(file_path="gitstats.conf") -> dict:
3033
"""Load configuration from a file, or fall back to defaults."""
3134
import configparser
3235
import os
3336

34-
config = DEFAULT_CONFIG.copy() # Start with defaults
37+
global _config
38+
39+
if _config is not None:
40+
return _config
41+
42+
_config = DEFAULT_CONFIG.copy() # Start with defaults
3543
config_parser = configparser.ConfigParser()
3644

3745
if os.path.exists(file_path):
3846
config_parser.read(file_path)
39-
config = {
47+
_config = {
4048
k: int(v) if v.isdigit() else v
4149
for k, v in config_parser["gitstats"].items()
4250
}
43-
return config
51+
return _config

0 commit comments

Comments
 (0)