Skip to content

Commit

Permalink
Do not fail when building the same PEX file twice (#215)
Browse files Browse the repository at this point in the history
Co-authored-by: Niklas Rosenstein <[email protected]>
  • Loading branch information
Tpt and NiklasRosenstein authored Mar 14, 2024
1 parent ec166ad commit 4c0424f
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 2 deletions.
6 changes: 6 additions & 0 deletions .changelog/_unreleased.toml
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
[[entries]]
id = "adc17a2c-58fc-48e5-a476-2bcfccb26a21"
type = "fix"
description = "Do not fail when building the same PEX file twice"
author = "@Tpt"

[[entries]]
id = "654174ac-b3d2-476a-b761-e65c8f4dd8a5"
type = "fix"
Expand Down
20 changes: 18 additions & 2 deletions kraken-build/src/kraken/std/python/tasks/pex_build_task.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
from kraken.core.system.property import Property
from kraken.core.system.task import Task, TaskStatus

logger = logging.getLogger(__name__)


class PexBuildTask(Task):
"""Build a PEX (Python EXecutable) from a Python requirement spec. Useful to install CLIs from PyPI. The PEX
Expand Down Expand Up @@ -147,8 +149,22 @@ def pex_build(
) -> PexBuildTask:
assert binary_name or console_script, "binary_name or console_script must be set"
binary_name = binary_name or console_script

task = (project or Project.current()).task(task_name or f"pexBuild.{binary_name}", PexBuildTask)
project = project or Project.current()
task_name = task_name or f"pexBuild.{binary_name}"

existing_task = project.tasks().get(task_name, None)
if (
isinstance(existing_task, PexBuildTask)
and existing_task.binary_name.get() == binary_name
and existing_task.requirements.get() == requirements
and existing_task.entry_point.get() == entry_point
and existing_task.console_script.get() == console_script
and existing_task.interpreter_constraint.get() == interpreter_constraint
and existing_task.venv.get() == venv
):
return existing_task

task = project.task(task_name, PexBuildTask)
task.binary_name = binary_name
task.requirements = requirements
task.entry_point = entry_point
Expand Down

0 comments on commit 4c0424f

Please sign in to comment.