Skip to content

Commit

Permalink
fix: consistent output for same input file (#39)
Browse files Browse the repository at this point in the history
COPY instructions and installed package order was not consistent due to usage of pythons set()
  • Loading branch information
the-working-rene authored Oct 14, 2024
1 parent b300345 commit 91c25f2
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
9 changes: 6 additions & 3 deletions poetry_dockerize_plugin/builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -252,11 +252,14 @@ def generate_extra_instructions_str(instructions: List[str]) -> str:
return ""
return "\n".join(instructions)

def _remove_duplicates(lst: List[str]) -> List[str]:
# remove duplicates while keeping order
return list(dict.fromkeys(lst))

def generate_apt_packages_str(apt_packages: List[str]) -> str:
if not len(apt_packages):
return ""
apt_packages_str = " ".join(list(set(apt_packages)))
apt_packages_str = " ".join(_remove_duplicates(apt_packages))
return f"""
ARG DEBIAN_FRONTEND=noninteractive
Expand All @@ -269,7 +272,7 @@ def generate_apt_packages_str(apt_packages: List[str]) -> str:
def generate_add_project_toml_str(config: ProjectConfiguration, real_context_path: str) -> str:
add_str = "RUN mkdir /app\n"
add_str += "COPY pyproject.toml poetry.lock* README* /app/\n"
for package in list(set(config.deps_packages)):
for package in _remove_duplicates(config.deps_packages):
if os.path.exists(os.path.join(real_context_path, package)):
add_str += f"COPY ./{package} /app/{package}\n"
else:
Expand All @@ -278,7 +281,7 @@ def generate_add_project_toml_str(config: ProjectConfiguration, real_context_pat

def generate_add_packages_str(config: ProjectConfiguration, real_context_path: str) -> str:
add_str = ""
for package in list(set(config.app_packages)):
for package in _remove_duplicates(config.app_packages):
if os.path.exists(os.path.join(real_context_path, package)):
add_str += f"COPY ./{package} /app/{package}\n"
else:
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "poetry-dockerize-plugin"
version = "1.3.0"
version = "1.3.1"
description = "Poetry application to Docker, automatically."
authors = ["Nicolò Boschi <[email protected]>"]
license = "MIT"
Expand Down

0 comments on commit 91c25f2

Please sign in to comment.