Skip to content

Commit f695b36

Browse files
authored
Refactor run_state in script automation (#754)
1 parent 35739cd commit f695b36

File tree

6 files changed

+136
-233
lines changed

6 files changed

+136
-233
lines changed

.github/workflows/build_wheel_off.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
name: Build wheel and release into PYPI (off now)
22

3+
34
on:
45
push:
56
branches:

automation/script/cache_utils.py

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -219,10 +219,6 @@ def validate_cached_scripts(i, found_cached_scripts):
219219
if len(found_cached_scripts) > 0:
220220
for cached_script in found_cached_scripts:
221221
if is_cached_entry_valid(i, cached_script):
222-
i['logger'].debug(
223-
i['recursion_spaces'] +
224-
f' - Validated cached entry: {cached_script.path}'
225-
)
226222
valid.append(cached_script)
227223

228224
return valid
@@ -301,10 +297,6 @@ def run_validate_cache_if_present(i, cached_script):
301297
'''
302298
import copy
303299

304-
i['logger'].debug(
305-
i['recursion_spaces'] +
306-
f' - Validating cached entry: {cached_script.path}'
307-
)
308300
os_info = i['self'].os_info
309301
# Bat extension for this host OS
310302
bat_ext = os_info['bat_ext']
@@ -314,6 +306,11 @@ def run_validate_cache_if_present(i, cached_script):
314306
if not os.path.exists(validate_script):
315307
return None
316308

309+
i['logger'].debug(
310+
i['recursion_spaces'] +
311+
f' - Validating cached entry: {cached_script.path}'
312+
)
313+
317314
# reconstruct env/state from cached metadata
318315
env_tmp = copy.deepcopy(i['env'])
319316
state_tmp = copy.deepcopy(i['state'])
@@ -350,7 +347,7 @@ def run_validate_cache_if_present(i, cached_script):
350347
'',
351348
i['show_time'],
352349
i['extra_recursion_spaces'],
353-
{}
350+
i['run_state']
354351
)
355352
if r['return'] > 0:
356353
return None

automation/script/docker.py

Lines changed: 23 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -49,13 +49,17 @@ def dockerfile(self_module, input_params):
4949
script_alias = metadata.get('alias', '')
5050
script_uid = metadata.get('uid', '')
5151

52-
run_state = {
53-
'deps': [],
54-
'fake_deps': [],
55-
'parent': None,
52+
if not hasattr(self_module, 'run_state'):
53+
self_module.run_state = self_module.init_run_state(
54+
input_params.get('run_state'))
55+
56+
run_state = self_module.run_state
57+
58+
run_state.update({
5659
'script_id': f"{script_alias},{script_uid}",
5760
'script_variation_tags': variation_tags
5861
}
62+
)
5963

6064
docker_settings = metadata.get('docker', {})
6165
docker_settings_default_env = docker_settings.get('default_env', {})
@@ -73,12 +77,6 @@ def dockerfile(self_module, input_params):
7377
# Update state with metadata and variations
7478
update_state_result = self_module.update_state_from_meta(
7579
metadata,
76-
deps=[],
77-
post_deps=[],
78-
prehook_deps=[],
79-
posthook_deps=[],
80-
new_env_keys=[],
81-
new_state_keys=[],
8280
run_state=run_state,
8381
i=input_params
8482
)
@@ -88,19 +86,13 @@ def dockerfile(self_module, input_params):
8886
update_variations_result = self_module._update_state_from_variations(
8987
input_params, metadata, variation_tags, metadata.get(
9088
'variations', {}),
91-
deps=[], # Add your dependencies if needed
92-
post_deps=[], # Add post dependencies if needed
93-
prehook_deps=[], # Add prehook dependencies if needed
94-
posthook_deps=[], # Add posthook dependencies if needed
95-
new_env_keys_from_meta=[], # Add keys from meta if needed
96-
new_state_keys_from_meta=[], # Add state keys from meta if needed
9789
run_state=run_state
9890
)
9991
if update_variations_result['return'] > 0:
10092
return update_variations_result
10193

10294
# Set Docker-specific configurations
103-
docker_settings = state_data['docker']
95+
docker_settings = run_state['docker']
10496

10597
if is_true(docker_settings.get('pass_docker_to_script', False)):
10698
input_params['docker'] = True
@@ -124,18 +116,13 @@ def dockerfile(self_module, input_params):
124116

125117
update_state_result = self_module.update_state_from_meta(
126118
metadata,
127-
deps=[],
128-
post_deps=[],
129-
prehook_deps=[],
130-
posthook_deps=[],
131-
new_env_keys=[],
132-
new_state_keys=[],
133119
run_state=run_state,
134120
i=input_params
135121
)
136122
if update_state_result['return'] > 0:
137123
return update_state_result
138-
docker_settings = state_data['docker']
124+
125+
docker_settings = run_state['docker']
139126

140127
# Prune temporary environment variables
141128
run_command = copy.deepcopy(run_command_arc)
@@ -324,37 +311,33 @@ def docker_run(self_module, i):
324311
for key in docker_settings_default_env:
325312
env.setdefault(key, docker_settings_default_env[key])
326313

327-
self_module.state['docker'] = docker_settings
328-
run_state = {
329-
'deps': [], 'fake_deps': [], 'parent': None,
314+
if not hasattr(self_module, 'run_state'):
315+
self_module.run_state = self_module.init_run_state(
316+
input_params.get('run_state'))
317+
318+
run_state = self_module.run_state
319+
320+
run_state['docker'] = docker_settings
321+
run_state.update({
330322
'script_id': f"{script_alias},{script_uid}",
331323
'script_variation_tags': variation_tags,
332324
'file_path_env_keys': file_path_env_keys,
333325
'folder_path_env_keys': folder_path_env_keys
334326
}
327+
)
335328

336329
# Update state and handle variations
337-
r = self_module.update_state_from_meta(meta, deps=[],
338-
post_deps=[],
339-
prehook_deps=[],
340-
posthook_deps=[],
341-
new_env_keys=[],
342-
new_state_keys=[], run_state=run_state, i=i)
330+
r = self_module.update_state_from_meta(meta, run_state=run_state, i=i)
343331
if r['return'] > 0:
344332
return r
345333

346334
r = self_module._update_state_from_variations(
347-
i, meta, variation_tags, variations, deps=[],
348-
post_deps=[],
349-
prehook_deps=[],
350-
posthook_deps=[],
351-
new_env_keys_from_meta=[],
352-
new_state_keys_from_meta=[],
335+
i, meta, variation_tags, variations,
353336
run_state=run_state)
354337
if r['return'] > 0:
355338
return r
356339

357-
docker_settings = self_module.state['docker']
340+
docker_settings = self_module.run_state['docker']
358341

359342
deps = docker_settings.get('deps', [])
360343
if deps:
@@ -367,12 +350,6 @@ def docker_run(self_module, i):
367350
# For updating meta from update_meta_if_env
368351
r = self_module.update_state_from_meta(
369352
meta,
370-
deps=[],
371-
post_deps=[],
372-
prehook_deps=[],
373-
posthook_deps=[],
374-
new_env_keys=[],
375-
new_state_keys=[],
376353
run_state=run_state,
377354
i=i)
378355
if r['return'] > 0:

0 commit comments

Comments
 (0)