Skip to content

Commit bd098ed

Browse files
committed
Eliminated re-fetch of remote config file
1 parent 445fc5b commit bd098ed

2 files changed

Lines changed: 18 additions & 16 deletions

File tree

  • remove-json-keys/src/remove_json_keys/lib
  • translate-messages/src/translate_messages/lib

remove-json-keys/src/remove_json_keys/lib/init.py

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -23,14 +23,15 @@ def config_file(cli):
2323
return
2424
cli.config_filename = f'.{cli.name}.config.jsonc'
2525
cli.config_filepath = os.path.join(cli.project_root, cli.config_filename)
26-
try:
27-
jsd_url = f'{cli.urls.jsdelivr}/{cli.name}/{cli.config_filename}'
28-
resp = requests.get(jsd_url, timeout=5)
29-
resp.raise_for_status()
30-
cli.file_config = resp.json()
31-
except (requests.RequestException, ValueError) as err:
32-
raise RuntimeError(f"Failed to fetch default config from {jsd_url}: {err}")
33-
data.json.write(cli.file_config, cli.config_filepath)
26+
if not cli.default_file_config:
27+
try:
28+
jsd_url = f'{cli.urls.jsdelivr}/{cli.name}/{cli.config_filename}'
29+
resp = requests.get(jsd_url, timeout=5)
30+
resp.raise_for_status()
31+
cli.default_file_config = resp.json()
32+
except (requests.RequestException, ValueError) as err:
33+
raise RuntimeError(f"Failed to fetch default config from {jsd_url}: {err}")
34+
data.json.write(cli.default_file_config, cli.config_filepath)
3435
log.success(f'Default config created at {cli.config_filepath}')
3536

3637
def locales_dir(target_dir):

translate-messages/src/translate_messages/lib/init.py

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,15 @@ def config_file(cli):
1717
return
1818
cli.config_filename = f'.{cli.short_name}.config.jsonc'
1919
cli.config_filepath = os.path.join(cli.project_root, cli.config_filename)
20-
try:
21-
jsd_url = f'{cli.urls.jsdelivr}/{cli.name}/{cli.config_filename}'
22-
resp = requests.get(jsd_url, timeout=5)
23-
resp.raise_for_status()
24-
cli.file_config = resp.json()
25-
except (requests.RequestException, ValueError) as err:
26-
raise RuntimeError(f"Failed to fetch default config from {jsd_url}: {err}")
27-
data.json.write(cli.file_config, cli.config_filepath)
20+
if not cli.default_file_config:
21+
try:
22+
jsd_url = f'{cli.urls.jsdelivr}/{cli.name}/{cli.config_filename}'
23+
resp = requests.get(jsd_url, timeout=5)
24+
resp.raise_for_status()
25+
cli.default_file_config = resp.json()
26+
except (requests.RequestException, ValueError) as err:
27+
raise RuntimeError(f"Failed to fetch default config from {jsd_url}: {err}")
28+
data.json.write(cli.default_file_config, cli.config_filepath)
2829
log.success(f'Default config created at {cli.config_filepath}')
2930

3031
def locales_dir(target_dir):

0 commit comments

Comments
 (0)