Skip to content

Commit

Permalink
remove comments
Browse files Browse the repository at this point in the history
  • Loading branch information
reschandreas committed Dec 21, 2023
1 parent a817b52 commit dc6bd3c
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 18 deletions.
3 changes: 2 additions & 1 deletion cli/classes/generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,9 +87,10 @@ def generate(self) -> Optional[str]:
if self.output_settings.verbose:
logger.info(
"📄",
f"Generated {self.target} pipeline:\n{result}",
f"Generated {self.target} pipeline:",
self.output_settings.emoji,
)
print(result)
if self.check_syntax:
if actual_generator.check(result):
logger.info(
Expand Down
28 changes: 13 additions & 15 deletions cli/generators/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,10 +60,8 @@ def add_postfix(self) -> None:
Add the postfix to the bash script.
E.g. some output settings, the callable functions etc.
"""
self.result.append("\n")
self.result.append("# main function")
self.result.append("main () {")
# to enable sourceing the script, we need to skip execution if we do so
self.result.append("\nmain () {")
# to enable sourcing the script, we need to skip execution if we do so
# for that, we check if the first parameter is sourcing, which is not ever given to the script elsewhere
self.add_line(indentation=2, line='local _current_lifecycle="${1}"')
self.add_line(indentation=4, line='if [[ "${_current_lifecycle}" == "aeolus_sourcing" ]]; then')
Expand All @@ -89,7 +87,6 @@ def handle_always_steps(self, steps: list[str]) -> None:
:param steps: to call always
:return: CI action
"""
self.result.append("\n# always steps")
self.result.append("final_aeolus_post_action () " + "{")
self.add_line(indentation=2, line="set +e # from now on, we don't exit on errors")
self.add_line(indentation=2, line="echo '⚙️ executing final_aeolus_post_action'")
Expand Down Expand Up @@ -122,18 +119,23 @@ def add_lifecycle_guards(self, name: str, exclusions: Optional[List[Lifecycle]],
indentations -= 2
self.add_line(indentation=indentations, line="fi")

def handle_result_list(self, indentation: int, results: List[Result]) -> None:
def handle_result_list(self, indentation: int, results: List[Result], workdir: Optional[str]) -> None:
"""
Process the results of a step.
https://askubuntu.com/a/889746
https://stackoverflow.com/a/8088439
:param indentation: indentation level
:param results: list of results
:param workdir: workdir of the step
"""
self.add_line(indentation=indentation, line=f'cd "${{{self.initial_directory_variable}}}"')
self.add_line(indentation=indentation, line=f"mkdir -p {self.results_directory_variable}")
self.add_line(indentation=indentation, line="shopt -s extglob")
for result in results:
self.add_line(indentation=indentation, line=f'local _sources="{result.path}"')
source_path: str = result.path
if workdir:
source_path = f"{workdir}/{result.path}"
self.add_line(indentation=indentation, line=f'local _sources="{source_path}"')
self.add_line(indentation=indentation, line="local _directory")
self.add_line(indentation=indentation, line='_directory=$(dirname "${_sources}")')
if result.ignore:
Expand All @@ -152,7 +154,7 @@ def handle_before_results(self, step: ScriptAction) -> None:
return
before: List[Result] = [result for result in step.results if result.before]
if before:
self.handle_result_list(indentation=2, results=before)
self.handle_result_list(indentation=2, results=before, workdir=step.workdir)

def handle_after_results(self, step: ScriptAction) -> None:
"""
Expand All @@ -163,7 +165,7 @@ def handle_after_results(self, step: ScriptAction) -> None:
return
after: List[Result] = [result for result in step.results if not result.before]
if after:
self.handle_result_list(indentation=2, results=after)
self.handle_result_list(indentation=2, results=after, workdir=step.workdir)

def handle_step(self, name: str, step: ScriptAction, call: bool) -> None:
"""
Expand All @@ -173,18 +175,14 @@ def handle_step(self, name: str, step: ScriptAction, call: bool) -> None:
:param call: whether to call the step or not
:return: CI action
"""
original_name: Optional[str] = self.metadata.get_original_name_of(name)
original_type: Optional[str] = self.metadata.get_meta_for_action(name).get("original_type")
if original_type == "platform":
if original_type == "platform" or (step.platform and step.platform != Target.cli):
logger.info(
"🔨",
"Platform action detected. Skipping...",
self.output_settings.emoji,
)
return None
self.result.append(f"# step {name}")
self.result.append(f"# generated from step {original_name}")
self.result.append(f"# original type was {original_type}")
valid_funtion_name: str = re.sub("[^a-zA-Z]+", "", name)
if call:
self.functions.append(valid_funtion_name)
Expand Down Expand Up @@ -212,7 +210,7 @@ def handle_step(self, name: str, step: ScriptAction, call: bool) -> None:
self.add_line(indentation=2, line=line)

self.handle_after_results(step=step)
self.result.append("}")
self.result.append("}\n")
return None

def check(self, content: str) -> bool:
Expand Down
4 changes: 2 additions & 2 deletions cli/test/test_generate.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,8 @@ def test_generate_valid_cli_script(self) -> None:
result: str = cli.generate()
self.assertTrue(result.count("#!/usr/bin/env bash") == 1)
self.assertTrue("set -e" in result)
# two comments, one echo for execution, one echo in the actual action
self.assertTrue(result.count("internal-action") == 3)
# one echo for execution, one echo in the actual action
self.assertTrue(result.count("internal-action") == 1)
# one call to the function and the function itself
self.assertTrue(result.count("internalaction") == 2)
self.assertTrue(result.count("{") == result.count("}"))
Expand Down

0 comments on commit dc6bd3c

Please sign in to comment.