diff --git a/newsfragments/1165-project-name-evaluation-order.bugfix b/newsfragments/1165-project-name-evaluation-order.bugfix new file mode 100644 index 0000000..d8834e1 --- /dev/null +++ b/newsfragments/1165-project-name-evaluation-order.bugfix @@ -0,0 +1 @@ +- Fixed project name evaluation order to match the order defined in the [compose spec](https://docs.docker.com/compose/how-tos/project-name/#set-a-project-name). diff --git a/podman_compose.py b/podman_compose.py index 379d9dc..62ec408 100755 --- a/podman_compose.py +++ b/podman_compose.py @@ -1981,15 +1981,20 @@ class PodmanCompose: content = normalize(content) # log(filename, json.dumps(content, indent = 2)) + # See also https://docs.docker.com/compose/how-tos/project-name/#set-a-project-name + # **project_name** is initialized to the argument of the `-p` command line flag. if not project_name: - project_name = content.get("name") - if project_name is None: - # More strict then actually needed for simplicity: - # podman requires [a-zA-Z0-9][a-zA-Z0-9_.-]* - project_name = self.environ.get("COMPOSE_PROJECT_NAME", dir_basename.lower()) - project_name = norm_re.sub("", project_name) - if not project_name: - raise RuntimeError(f"Project name [{dir_basename}] normalized to empty") + project_name = self.environ.get("COMPOSE_PROJECT_NAME") + if not project_name: + project_name = content.get("name") + if not project_name: + project_name = dir_basename.lower() + # More strict then actually needed for simplicity: + # podman requires [a-zA-Z0-9][a-zA-Z0-9_.-]* + project_name_normalized = norm_re.sub("", project_name) + if not project_name_normalized: + raise RuntimeError(f"Project name [{project_name}] normalized to empty") + project_name = project_name_normalized self.project_name = project_name self.environ.update({"COMPOSE_PROJECT_NAME": self.project_name})