Skip to content

Commit d00a057

Browse files
committed
Deleted remove_keys() in utils/lib/data/json.py
1 parent f6b1d6b commit d00a057

4 files changed

Lines changed: 8 additions & 80 deletions

File tree

  • find-project-root/utils/lib/data
  • latin-locales/utils/lib/data
  • non-latin-locales/utils/lib/data
  • project-markers/utils/lib/data

find-project-root/utils/lib/data/json.py

Lines changed: 2 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
import json, re
1+
import json
22
from pathlib import Path
3-
from typing import Any, Dict, List, Union
3+
from typing import Any, Dict, Union
44

55
import json5
66

@@ -36,24 +36,6 @@ def read(input: Union[Path, str], encoding: str = 'utf-8') -> Any:
3636
return json5.load(file)
3737
else : return json5.loads(input_str)
3838

39-
def remove_keys(json_path: Path, keys: List[str]):
40-
keys_removed, keys_skipped, files_processed_cnt = [], [], 0
41-
for file_path in json_path.rglob('*.json'):
42-
json_data = file.read(file_path)
43-
modified = False
44-
for key in keys: # remove matched ones
45-
re_key = fr'"{re.escape(key)}"\s*:\s*(?:\{{[^}}]*\}}|"[^"]*"|\d+|true|false|null)\s*,?\s*'
46-
json_data, cnt = re.subn(re_key, '', json_data)
47-
rel_path = str(file_path.relative_to(json_path))
48-
if cnt > 0:
49-
keys_removed.append((key, rel_path))
50-
modified = True
51-
else:
52-
keys_skipped.append((key, rel_path))
53-
if modified : file.write(file_path, json_data)
54-
files_processed_cnt += 1
55-
return keys_removed, keys_skipped, files_processed_cnt
56-
5739
def write(file_path: Union[Path, str], data: Any, encoding: str = 'utf-8', ensure_ascii: bool = False,
5840
style: str = 'pretty', atomic: bool =True):
5941
Path(file_path).parent.mkdir(parents=True, exist_ok=True)

latin-locales/utils/lib/data/json.py

Lines changed: 2 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
import json, re
1+
import json
22
from pathlib import Path
3-
from typing import Any, Dict, List, Union
3+
from typing import Any, Dict, Union
44

55
import json5
66

@@ -36,24 +36,6 @@ def read(input: Union[Path, str], encoding: str = 'utf-8') -> Any:
3636
return json5.load(file)
3737
else : return json5.loads(input_str)
3838

39-
def remove_keys(json_path: Path, keys: List[str]):
40-
keys_removed, keys_skipped, files_processed_cnt = [], [], 0
41-
for file_path in json_path.rglob('*.json'):
42-
json_data = file.read(file_path)
43-
modified = False
44-
for key in keys: # remove matched ones
45-
re_key = fr'"{re.escape(key)}"\s*:\s*(?:\{{[^}}]*\}}|"[^"]*"|\d+|true|false|null)\s*,?\s*'
46-
json_data, cnt = re.subn(re_key, '', json_data)
47-
rel_path = str(file_path.relative_to(json_path))
48-
if cnt > 0:
49-
keys_removed.append((key, rel_path))
50-
modified = True
51-
else:
52-
keys_skipped.append((key, rel_path))
53-
if modified : file.write(file_path, json_data)
54-
files_processed_cnt += 1
55-
return keys_removed, keys_skipped, files_processed_cnt
56-
5739
def write(file_path: Union[Path, str], data: Any, encoding: str = 'utf-8', ensure_ascii: bool = False,
5840
style: str = 'pretty', atomic: bool =True):
5941
Path(file_path).parent.mkdir(parents=True, exist_ok=True)

non-latin-locales/utils/lib/data/json.py

Lines changed: 2 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
import json, re
1+
import json
22
from pathlib import Path
3-
from typing import Any, Dict, List, Union
3+
from typing import Any, Dict, Union
44

55
import json5
66

@@ -36,24 +36,6 @@ def read(input: Union[Path, str], encoding: str = 'utf-8') -> Any:
3636
return json5.load(file)
3737
else : return json5.loads(input_str)
3838

39-
def remove_keys(json_path: Path, keys: List[str]):
40-
keys_removed, keys_skipped, files_processed_cnt = [], [], 0
41-
for file_path in json_path.rglob('*.json'):
42-
json_data = file.read(file_path)
43-
modified = False
44-
for key in keys: # remove matched ones
45-
re_key = fr'"{re.escape(key)}"\s*:\s*(?:\{{[^}}]*\}}|"[^"]*"|\d+|true|false|null)\s*,?\s*'
46-
json_data, cnt = re.subn(re_key, '', json_data)
47-
rel_path = str(file_path.relative_to(json_path))
48-
if cnt > 0:
49-
keys_removed.append((key, rel_path))
50-
modified = True
51-
else:
52-
keys_skipped.append((key, rel_path))
53-
if modified : file.write(file_path, json_data)
54-
files_processed_cnt += 1
55-
return keys_removed, keys_skipped, files_processed_cnt
56-
5739
def write(file_path: Union[Path, str], data: Any, encoding: str = 'utf-8', ensure_ascii: bool = False,
5840
style: str = 'pretty', atomic: bool =True):
5941
Path(file_path).parent.mkdir(parents=True, exist_ok=True)

project-markers/utils/lib/data/json.py

Lines changed: 2 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
import json, re
1+
import json
22
from pathlib import Path
3-
from typing import Any, Dict, List, Union
3+
from typing import Any, Dict, Union
44

55
import json5
66

@@ -36,24 +36,6 @@ def read(input: Union[Path, str], encoding: str = 'utf-8') -> Any:
3636
return json5.load(file)
3737
else : return json5.loads(input_str)
3838

39-
def remove_keys(json_path: Path, keys: List[str]):
40-
keys_removed, keys_skipped, files_processed_cnt = [], [], 0
41-
for file_path in json_path.rglob('*.json'):
42-
json_data = file.read(file_path)
43-
modified = False
44-
for key in keys: # remove matched ones
45-
re_key = fr'"{re.escape(key)}"\s*:\s*(?:\{{[^}}]*\}}|"[^"]*"|\d+|true|false|null)\s*,?\s*'
46-
json_data, cnt = re.subn(re_key, '', json_data)
47-
rel_path = str(file_path.relative_to(json_path))
48-
if cnt > 0:
49-
keys_removed.append((key, rel_path))
50-
modified = True
51-
else:
52-
keys_skipped.append((key, rel_path))
53-
if modified : file.write(file_path, json_data)
54-
files_processed_cnt += 1
55-
return keys_removed, keys_skipped, files_processed_cnt
56-
5739
def write(file_path: Union[Path, str], data: Any, encoding: str = 'utf-8', ensure_ascii: bool = False,
5840
style: str = 'pretty', atomic: bool =True):
5941
Path(file_path).parent.mkdir(parents=True, exist_ok=True)

0 commit comments

Comments
 (0)