From b0be6f82858a94ae4087b98eb9f000da7b5af15d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20=C4=8Cern=C3=BD?= Date: Fri, 3 Jan 2025 11:14:11 +0100 Subject: [PATCH] Refactor: extract function --- ssg/build_sce.py | 31 ++++++++++++++++--------------- 1 file changed, 16 insertions(+), 15 deletions(-) diff --git a/ssg/build_sce.py b/ssg/build_sce.py index dda367bbb31..17906a0f560 100644 --- a/ssg/build_sce.py +++ b/ssg/build_sce.py @@ -34,29 +34,30 @@ def load_sce_and_metadata(file_path, local_env_yaml): return load_sce_and_metadata_parsed(raw_content) +def _process_raw_content_line(line, sce_content, metadata): + found_metadata = False + keywords = ['platform', 'check-import', 'check-export', 'complex-check', 'environment'] + for keyword in keywords: + if not line.startswith('# ' + keyword + ' = '): + continue + found_metadata = True + # Strip off the initial comment marker + _, value = line[2:].split('=', maxsplit=1) + metadata[keyword] = value.strip() + + if not found_metadata: + sce_content.append(line) + + def _parse_metadata(raw_content): metadata = dict() sce_content = [] - - keywords = ['platform', 'check-import', 'check-export', 'complex-check', 'environment'] shebang = "#!/usr/bin/bash" for line in raw_content.split("\n"): if line.startswith("#!"): shebang = line continue - found_metadata = False - for keyword in keywords: - if not line.startswith('# ' + keyword + ' = '): - continue - - found_metadata = True - - # Strip off the initial comment marker - _, value = line[2:].split('=', maxsplit=1) - metadata[keyword] = value.strip() - - if not found_metadata: - sce_content.append(line) + _process_raw_content_line(line, sce_content, metadata) return shebang, "\n".join(sce_content), metadata