ktsn-ud commited on
Commit
c04ba23
·
1 Parent(s): b7b79b1

ユーティリティ関数の構成を変更

Browse files
scripts/1_build_dict.py CHANGED
@@ -7,7 +7,7 @@ import sys
7
  sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), "..")))
8
 
9
  from utils.logger import setup_logger
10
- from utils.path import get_file_path_from_config
11
 
12
  # --- ロギングの設定 ---
13
  log = setup_logger(__name__)
 
7
  sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), "..")))
8
 
9
  from utils.logger import setup_logger
10
+ from utils.json import get_file_path_from_config
11
 
12
  # --- ロギングの設定 ---
13
  log = setup_logger(__name__)
scripts/2_create_projects_data.py CHANGED
@@ -5,9 +5,9 @@ import pandas as pd
5
  sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), "..")))
6
 
7
  from utils.logger import setup_logger
8
- from utils.path import get_file_path_from_config
9
  from utils.text_process import remove_invisible_chars
10
- from utils.io import json_dumps
11
  import schemas.projects as projects_schema
12
 
13
  # --- ロギングの設定 ---
 
5
  sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), "..")))
6
 
7
  from utils.logger import setup_logger
8
+ from utils.json import get_file_path_from_config
9
  from utils.text_process import remove_invisible_chars
10
+ from utils.json import json_dumps
11
  import schemas.projects as projects_schema
12
 
13
  # --- ロギングの設定 ---
utils/io.py DELETED
@@ -1,17 +0,0 @@
1
- import json
2
- from pathlib import Path
3
- from typing import Any
4
-
5
-
6
- def _write_atomic(path: Path, data: str) -> None:
7
- temp = path.with_suffix(path.suffix + ".tmp")
8
- temp.write_bytes(data)
9
- temp.replace(path)
10
-
11
-
12
- def json_dumps(obj: Any, path: str | Path) -> None:
13
- """
14
- オブジェクトをJSON形式のファイルに書き出す。
15
- """
16
- json_bytes = json.dumps(obj, ensure_ascii=False, indent=2).encode("utf-8")
17
- _write_atomic(Path(path), json_bytes)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
utils/{path.py → json.py} RENAMED
@@ -1,4 +1,5 @@
1
  import json
 
2
  from typing import Any
3
 
4
  FILE_CONFIG_PATH = "config/files.json"
@@ -40,3 +41,17 @@ def get_file_path_from_config(
40
  if default is not None:
41
  return default
42
  raise TypeError(f"Value at '{key}' is not a string: {type(value).__name__}")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  import json
2
+ from pathlib import Path
3
  from typing import Any
4
 
5
  FILE_CONFIG_PATH = "config/files.json"
 
41
  if default is not None:
42
  return default
43
  raise TypeError(f"Value at '{key}' is not a string: {type(value).__name__}")
44
+
45
+
46
+ def _write_atomic(path: Path, data: str) -> None:
47
+ temp = path.with_suffix(path.suffix + ".tmp")
48
+ temp.write_bytes(data)
49
+ temp.replace(path)
50
+
51
+
52
+ def json_dumps(obj: Any, path: str | Path) -> None:
53
+ """
54
+ オブジェクトをJSON形式のファイルに書き出す。
55
+ """
56
+ json_bytes = json.dumps(obj, ensure_ascii=False, indent=2).encode("utf-8")
57
+ _write_atomic(Path(path), json_bytes)