Pi66

merodi
A markdown-based static site generator.
git clone https://git.pi66.xyz/merodi

← back to log

refactor: remove global CONFIG, pass config explicitly

author: pi66
date: 2026-07-15 00:10
hash: 53ff5b38eb2428072ce540c02f98b0dd789bc0c2

Diffstat:

M

src/hash.py
24 ++++++++++++++----------------

M

src/settings.py
3 ----
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
diff --git a/src/hash.py b/src/hash.py
index c56a088..096210b 100644
--- a/src/hash.py
+++ b/src/hash.py
@@ -3,24 +3,23 @@ import json
 from os import path

 from src.fileops import read_file, write_file
-from src.log import info, warn
-from . import settings
+from src.log import warn

 HASH_FILE_CONTENT: dict | None = None


-def read_hash_file():
+def read_hash_file(config):
     global HASH_FILE_CONTENT
     if HASH_FILE_CONTENT is None:
-        with open(settings.CONFIG.cache.hash, "r") as f:
+        with open(config.cache.hash, "r") as f:
             HASH_FILE_CONTENT = json.load(f)

     return


-def write_hash_file():
+def write_hash_file(config):
     global HASH_FILE_CONTENT
-    with open(settings.CONFIG.cache.hash, "w") as f:
+    with open(config.cache.hash, "w") as f:
         json.dump(HASH_FILE_CONTENT, f)

 def md5_handler(md_path):
@@ -41,30 +40,29 @@ def append_md5(key, value):
     HASH_FILE_CONTENT[key] = value


-def handle_hash_sync(md_path):
+def handle_hash_sync(config, md_path):
     global HASH_FILE_CONTENT
     try:
-        hash_dir = settings.CONFIG.cache.hash
-        if settings.CONFIG is None:
+        hash_dir = config.cache.hash
+        if config is None:
             return
         if not (path.exists(hash_dir) and path.isfile(hash_dir)):
             write_file(hash_dir, "{}")

-        read_hash_file()
+        read_hash_file(config)

         if HASH_FILE_CONTENT is None:
             HASH_FILE_CONTENT = {}

         current_hash = md5_handler(md_path)
-        md_rel_path = path.relpath(md_path, settings.CONFIG.tree.markdown)
+        md_rel_path = path.relpath(md_path, config.tree.markdown)
         new_hash = hash_is_modified(md_rel_path, current_hash)

         if new_hash is None:
             return None

-        info(f"File hash: {new_hash}")
         append_md5(md_rel_path, new_hash)
-        write_hash_file()
+        write_hash_file(config)
         return True

     except Exception as e:
diff --git a/src/settings.py b/src/settings.py
index b81f448..c02319b 100644
--- a/src/settings.py
+++ b/src/settings.py
@@ -1,5 +1,2 @@
-from .modules import Config
-
 VERBOSE  = False
 NO_COLOR = False
-CONFIG: Config | None = None