Skip to content

Commit

Permalink
feat(normalizer): check manifest cfg in both config.yml and manifest.…
Browse files Browse the repository at this point in the history
…yml (#52)

* refactor(normalizer): check manifest cfg in both config.yml and manifest.yml

* refactor(normalizer): check manifest cfg in metas field under config.yml
  • Loading branch information
Andrei997 committed Sep 1, 2022
1 parent b166fa2 commit e330b46
Showing 1 changed file with 15 additions and 4 deletions.
19 changes: 15 additions & 4 deletions normalizer/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -405,6 +405,7 @@ def normalize(
)

dockerfile_path = work_path / 'Dockerfile'
manifest_cfg = None
manifest_path = work_path / 'manifest.yml'
config_path = work_path / 'config.yml'
readme_path = work_path / 'README.md'
Expand All @@ -424,7 +425,7 @@ def normalize(
if class_name is None:
raise Exception('Not found jtype in config.yml')

metas_py_modules = config.get('metas', {}).get('py_modules', None);
metas_py_modules = config.get('metas', {}).get('py_modules', None)
root_py_modules = config.get('py_modules', None)

if metas_py_modules and root_py_modules:
Expand Down Expand Up @@ -455,14 +456,24 @@ def normalize(
py_glob.append(extended_path)
break

# checking if metas configuration is available in config
if 'metas' in config:
metas_keys = config['metas']
if 'name' in metas_keys:
manifest_cfg = config_path

# if metas configuration is not available, try loading the manifest file
if manifest_cfg is None and manifest_path.exists():
manifest_cfg = manifest_path

else:
py_glob = list(work_path.glob('*.py')) + list(work_path.glob('executor/*.py'))

py_glob = list(set(py_glob))

completeness = {
'Dockerfile': dockerfile_path,
'manifest.yml': manifest_path,
'manifest': manifest_cfg,
'config.yml': config_path,
'README.md': readme_path,
'requirements.txt': requirements_path,
Expand All @@ -473,15 +484,15 @@ def normalize(
logger.info(
f'=> checking executor repository ...\n'
+ '\n'.join(
f'\t{colored("✓", "green") if (v if isinstance(v, list) else v.exists()) else colored("✗", "red"):>4} {k:<20} {v}'
f'\t{colored("✓", "green") if (None if v is None else v if isinstance(v, list) else v.exists()) else colored("✗", "red"):>4} {k:<20} {v}'
for k, v in completeness.items()
)
+ '\n'
)

hubble_score_metrics = {
'dockerfile_exists': dockerfile_path.exists(),
'manifest_exists': manifest_path.exists(),
'manifest_exists': manifest_cfg is not None,
'config_exists': config_path.exists(),
'readme_exists': readme_path.exists(),
'requirements_exists': requirements_path.exists(),
Expand Down

0 comments on commit e330b46

Please sign in to comment.