Skip to content

Commit

Permalink
Cleanup for validate cache in get-generic-python-lib
Browse files Browse the repository at this point in the history
  • Loading branch information
arjunsuresh committed Nov 25, 2024
1 parent c4fd10f commit bbc2de6
Show file tree
Hide file tree
Showing 2 changed files with 66 additions and 30 deletions.
89 changes: 61 additions & 28 deletions automation/script/module.py
Original file line number Diff line number Diff line change
Expand Up @@ -1169,6 +1169,30 @@ def _run(self, i):
cached_path = ''

local_env_keys_from_meta = meta.get('local_env_keys', [])

# Check if has customize.py
path_to_customize_py = os.path.join(path, 'customize.py')
customize_code = None

if os.path.isfile(path_to_customize_py):
r = utils.load_python_module(
{'path': path, 'name': 'customize'})
if r['return'] > 0:
return r

customize_code = r['code']

customize_common_input = {
'input': i,
'automation': self,
'artifact': script_artifact,
'customize': script_artifact.meta.get('customize', {}),
'os_info': os_info,
'recursion_spaces': recursion_spaces,
'script_tags': script_tags,
'variation_tags': variation_tags
}


#######################################################################
# Check if script is cached if we need to skip deps from cached entries
Expand All @@ -1185,6 +1209,8 @@ def _run(self, i):
'script_tags': script_tags,
'found_script_tags': found_script_tags,
'found_script_path': path,
'customize_code': customize_code,
'customize_common_input': customize_common_input,
'variation_tags': variation_tags,
'explicit_variation_tags': explicit_variation_tags,
'version': version,
Expand Down Expand Up @@ -1588,10 +1614,6 @@ def _run(self, i):
# Clean some output files
clean_tmp_files(clean_files, recursion_spaces)

# Check if has customize.py
path_to_customize_py = os.path.join(path, 'customize.py')
customize_code = None

# Prepare common input to prepare and run script
run_script_input = {
'path': path,
Expand Down Expand Up @@ -1621,33 +1643,16 @@ def _run(self, i):
'meta': meta,
'self': self
}
if customize_code:
run_script_input['customize_code'] = customize_code
run_script_input['customize_common_input'] = customize_common_input


if repro_prefix != '':
run_script_input['repro_prefix'] = repro_prefix
if ignore_script_error:
run_script_input['ignore_script_error'] = True

if os.path.isfile(path_to_customize_py):
r = utils.load_python_module(
{'path': path, 'name': 'customize'})
if r['return'] > 0:
return r

customize_code = r['code']

customize_common_input = {
'input': i,
'automation': self,
'artifact': script_artifact,
'customize': script_artifact.meta.get('customize', {}),
'os_info': os_info,
'recursion_spaces': recursion_spaces,
'script_tags': script_tags,
'variation_tags': variation_tags
}

run_script_input['customize_code'] = customize_code
run_script_input['customize_common_input'] = customize_common_input

# Assemble PIP versions
pip_version_string = ''
Expand Down Expand Up @@ -3873,6 +3878,12 @@ def run_native_script(self, i):
run_script_input = i['run_script_input']
script_name = i['script_name']
env = i.get('env', '')
detect_version = i.get('detect_version', '')

if detect_version:
postprocess="detect_version"
else:
postprocess=""

# Create and work on a copy to avoid contamination
env_copy = copy.deepcopy(run_script_input.get('env', {}))
Expand All @@ -3884,7 +3895,7 @@ def run_native_script(self, i):
run_script_input['env'] = env

r = prepare_and_run_script_with_postprocessing(
run_script_input, postprocess="")
run_script_input, postprocess=postprocess)

env_tmp = copy.deepcopy(run_script_input['env'])
r['env_tmp'] = env_tmp
Expand Down Expand Up @@ -4852,6 +4863,8 @@ def find_cached_script(i):
recursion_spaces = i['recursion_spaces']
script_tags = i['script_tags']
cached_tags = []
customize_code = i.get('customize_code')
customize_common_input = i.get('customize_common_input', {})
found_script_tags = i['found_script_tags']
variation_tags = i['variation_tags']
explicit_variation_tags = i['explicit_variation_tags']
Expand Down Expand Up @@ -5034,9 +5047,29 @@ def find_cached_script(i):
'recursion_spaces': recursion_spaces,
'tmp_file_run': self_obj.tmp_file_run,
'self': self_obj,
'meta': meta
'meta': meta,
'customize_code': customize_code,
'customize_common_input': customize_common_input,
'detect_version': True
}
ii = {'run_script_input': run_script_input, 'env': env, 'script_name': 'validate_cache'}

# Check if pre-process and detect
#if 'preprocess' in dir(customize_code):

#logging.debug(recursion_spaces + ' - Running preprocess ...')


# ii = copy.deepcopy(customize_common_input)
# ii['env'] = env
# ii['meta'] = meta
# # may need to detect versions in multiple paths
# ii['run_script_input'] = run_script_input

#r = customize_code.preprocess(ii)
#if r['return'] > 0:
# return r

ii = {'run_script_input': run_script_input, 'env': env, 'script_name': 'validate_cache', 'detect_version': True}
r = self_obj.run_native_script(ii)

if r['return'] > 0:
Expand Down
7 changes: 5 additions & 2 deletions script/get-generic-python-lib/customize.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,8 +127,11 @@ def detect_version(i):

env = i['env']

env_version_key = 'CM_' + \
env['CM_TMP_PYTHON_PACKAGE_NAME_ENV'].upper() + '_VERSION'
if env.get('CM_TMP_PYTHON_PACKAGE_NAME_ENV', '') != '':
env_version_key = 'CM_' + \
env['CM_TMP_PYTHON_PACKAGE_NAME_ENV'].upper() + '_VERSION'
else:
env_version_key = 'CM_CACHE_TMP_VERSION'

r = i['automation'].parse_version({'match_text': r'\s*([\d.a-z\-]+)',
'group_number': 1,
Expand Down

0 comments on commit bbc2de6

Please sign in to comment.