Skip to content

Commit

Permalink
add no-normalize flag
Browse files Browse the repository at this point in the history
Signed-off-by: Evedel <svbiriukov@gmail.com>
  • Loading branch information
Evedel authored and muayyad-alsadi committed Aug 2, 2023
1 parent 57c527c commit bc9168b
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 5 deletions.
6 changes: 5 additions & 1 deletion podman_compose.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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"
)
Expand Down
5 changes: 4 additions & 1 deletion pytests/test_can_merge_build.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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:
Expand Down
1 change: 1 addition & 0 deletions pytests/test_can_merge_cmd_ent.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
13 changes: 10 additions & 3 deletions pytests/test_normalize_final_build.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand Down Expand Up @@ -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()

Expand All @@ -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:
Expand Down

0 comments on commit bc9168b

Please sign in to comment.