From bc9168b03927ff48120fa89cbebf5d1a47f1c74f Mon Sep 17 00:00:00 2001 From: Evedel Date: Sun, 11 Jun 2023 15:19:14 +1000 Subject: [PATCH] add no-normalize flag Signed-off-by: Evedel --- podman_compose.py | 6 +++++- pytests/test_can_merge_build.py | 5 ++++- pytests/test_can_merge_cmd_ent.py | 1 + pytests/test_normalize_final_build.py | 13 ++++++++++--- 4 files changed, 20 insertions(+), 5 deletions(-) diff --git a/podman_compose.py b/podman_compose.py index aefb9ec..d4cc1d4 100755 --- a/podman_compose.py +++ b/podman_compose.py @@ -1627,7 +1627,8 @@ def _parse_compose_file(self): compose.get("services", {}), set(args.profile) ) compose["services"] = resolved_services - compose = normalize_final(compose, self.dirname) + if not args.no_normalize: + compose = normalize_final(compose, self.dirname) self.merged_yaml = yaml.safe_dump(compose) merged_json_b = json.dumps(compose, separators=(",", ":")).encode("utf-8") self.yaml_hash = hashlib.sha256(merged_json_b).hexdigest() @@ -3082,6 +3083,9 @@ def compose_build_parse(parser): @cmd_parse(podman_compose, "config") def compose_config_parse(parser): + parser.add_argument( + "--no-normalize", help="Don't normalize compose model.", action="store_true" + ) parser.add_argument( "--services", help="Print the service names, one per line.", action="store_true" ) diff --git a/pytests/test_can_merge_build.py b/pytests/test_can_merge_build.py index a020cb5..d08081a 100644 --- a/pytests/test_can_merge_build.py +++ b/pytests/test_can_merge_build.py @@ -138,7 +138,9 @@ def test__parse_compose_file_when_multiple_composes() -> None: if actual_compose != expected_result: print("compose: ", test_input) print("override: ", test_override) - print("result: ", expected_result) + print("expected: ", expected_result) + print("actual: ", actual_compose) + compose_expected = expected_result assert compose_expected == actual_compose @@ -151,6 +153,7 @@ def set_args(podman_compose: PodmanCompose, file_names: list[str]) -> None: podman_compose.global_args.env_file = None podman_compose.global_args.profile = [] podman_compose.global_args.in_pod = True + podman_compose.global_args.no_normalize = True def dump_yaml(compose: dict, name: str) -> None: diff --git a/pytests/test_can_merge_cmd_ent.py b/pytests/test_can_merge_cmd_ent.py index 5175673..2120632 100644 --- a/pytests/test_can_merge_cmd_ent.py +++ b/pytests/test_can_merge_cmd_ent.py @@ -107,6 +107,7 @@ def set_args(podman_compose: PodmanCompose, file_names: list[str]) -> None: podman_compose.global_args.env_file = None podman_compose.global_args.profile = [] podman_compose.global_args.in_pod = True + podman_compose.global_args.no_normalize = None def dump_yaml(compose: dict, name: str) -> None: diff --git a/pytests/test_normalize_final_build.py b/pytests/test_normalize_final_build.py index f76cfd2..49ff3cd 100644 --- a/pytests/test_normalize_final_build.py +++ b/pytests/test_normalize_final_build.py @@ -146,7 +146,7 @@ def test__parse_compose_file_when_single_compose() -> None: dump_yaml(compose_test, "test-compose.yaml") podman_compose = PodmanCompose() - set_args(podman_compose, ["test-compose.yaml"]) + set_args(podman_compose, ["test-compose.yaml"], no_normalize=None) podman_compose._parse_compose_file() @@ -271,7 +271,11 @@ def test__parse_compose_file_when_multiple_composes() -> None: dump_yaml(compose_test_2, "test-compose-2.yaml") podman_compose = PodmanCompose() - set_args(podman_compose, ["test-compose-1.yaml", "test-compose-2.yaml"]) + set_args( + podman_compose, + ["test-compose-1.yaml", "test-compose-2.yaml"], + no_normalize=None, + ) podman_compose._parse_compose_file() @@ -288,13 +292,16 @@ def test__parse_compose_file_when_multiple_composes() -> None: assert compose_expected == actual_compose -def set_args(podman_compose: PodmanCompose, file_names: list[str]) -> None: +def set_args( + podman_compose: PodmanCompose, file_names: list[str], no_normalize: bool +) -> None: podman_compose.global_args = argparse.Namespace() podman_compose.global_args.file = file_names podman_compose.global_args.project_name = None podman_compose.global_args.env_file = None podman_compose.global_args.profile = [] podman_compose.global_args.in_pod = True + podman_compose.global_args.no_normalize = no_normalize def dump_yaml(compose: dict, name: str) -> None: