Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 18 additions & 8 deletions python/rpdk/python/codegen.py
Original file line number Diff line number Diff line change
Expand Up @@ -334,14 +334,24 @@ def _pip_build(cls, base_path):

LOG.warning("Starting pip build.")
try:
completed_proc = subprocess_run( # nosec
command,
stdout=PIPE,
stderr=PIPE,
cwd=base_path,
check=True,
shell=True,
)
# On windows run pip command through the default shell (CMD)
if os.name == "nt":
completed_proc = subprocess_run( # nosec
command,
stdout=PIPE,
stderr=PIPE,
cwd=base_path,
check=True,
shell=True,
)
else:
completed_proc = subprocess_run( # nosec
command,
stdout=PIPE,
stderr=PIPE,
cwd=base_path,
check=True,
)
LOG.warning("pip build finished.")
except (FileNotFoundError, CalledProcessError) as e:
raise DownstreamError("pip build failed") from e
Expand Down
37 changes: 37 additions & 0 deletions tests/plugin/codegen_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -416,6 +416,43 @@ def test__build_pip(plugin):
mock_pip.assert_called_once_with(sentinel.base_path)


def test__build_pip_posix(plugin):
patch_os_name = patch("rpdk.python.codegen.os.name", "posix")
patch_subproc = patch("rpdk.python.codegen.subprocess_run")

# Path must be set outside simulated os.name
temppath = Path(str(sentinel.base_path))
with patch_os_name, patch_subproc as mock_subproc:
plugin._pip_build(temppath)

mock_subproc.assert_called_once_with(
plugin._make_pip_command(temppath),
stdout=ANY,
stderr=ANY,
cwd=temppath,
check=ANY,
)


def test__build_pip_windows(plugin):
patch_os_name = patch("rpdk.python.codegen.os.name", "nt")
patch_subproc = patch("rpdk.python.codegen.subprocess_run")

# Path must be set outside simulated os.name
temppath = Path(str(sentinel.base_path))
with patch_os_name, patch_subproc as mock_subproc:
plugin._pip_build(temppath)

mock_subproc.assert_called_once_with(
plugin._make_pip_command(temppath),
stdout=ANY,
stderr=ANY,
cwd=temppath,
check=ANY,
shell=True,
)


def test__build_docker(plugin):
plugin._use_docker = True

Expand Down