Skip to content

Commit

Permalink
fix: :zip:embedded source directory should read from sh_work_dir
Browse files Browse the repository at this point in the history
Signed-off-by: ANGkeith <[email protected]>
  • Loading branch information
ANGkeith committed Apr 10, 2024
1 parent 54b8256 commit bfa1bde
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 1 deletion.
8 changes: 8 additions & 0 deletions package.py
Original file line number Diff line number Diff line change
Expand Up @@ -916,16 +916,24 @@ def execute(self, build_plan, zip_stream, query):
# XXX: timestamp=0 - what actually do with it?
zs.write_dirs(rd, prefix=prefix, timestamp=0)
elif cmd == "sh":
r, w = os.pipe()
side_ch = os.fdopen(r)
path, script = action[1:]
script = "{} && pwd >&{}".format(script, w)
p = subprocess.Popen(
script,
shell=True,
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
cwd=path,
pass_fds=(w,),
)

p.wait()
os.close(w)
sh_work_dir = side_ch.read().strip()
log.info("WD: %s", sh_work_dir)
side_ch.close()
call_stdout, call_stderr = p.communicate()
exit_code = p.returncode
log.info("exit_code: %s", exit_code)
Expand Down
47 changes: 46 additions & 1 deletion tests/test_package_toml.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import os
from package import get_build_system_from_pyproject_toml, BuildPlanManager
from pytest import raises
from unittest.mock import Mock
from unittest.mock import MagicMock, Mock


def test_get_build_system_from_pyproject_toml_inexistent():
Expand Down Expand Up @@ -39,3 +40,47 @@ def test_get_build_system_from_pyproject_toml_poetry():
)
== "poetry"
)


def test_zip_source_path_sh_work_dir():
zs = Mock()
zs.write_dirs = MagicMock()

bpm = BuildPlanManager(args=Mock())
bpm._zip_write_with_filter = MagicMock()

bpm.execute(
build_plan=[
["sh", ".", "cd $(mktemp -d)\n echo pip install"],
["zip:embedded", ".", "./python"],
],
zip_stream=zs,
query=None,
)

zs.write_dirs.assert_called_once()

zip_source_path = zs.write_dirs.call_args_list[0][0][0]
assert zip_source_path != f"{os.getcwd()}"


def test_zip_source_path():
zs = Mock()
zs.write_dirs = MagicMock()

bpm = BuildPlanManager(args=Mock())
bpm._zip_write_with_filter = MagicMock()

bpm.execute(
build_plan=[
["sh", ".", "echo pip install"],
["zip:embedded", ".", "./python"],
],
zip_stream=zs,
query=None,
)

zs.write_dirs.assert_called_once()

zip_source_path = zs.write_dirs.call_args_list[0][0][0]
assert zip_source_path == f"{os.getcwd()}"

0 comments on commit bfa1bde

Please sign in to comment.