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
5 changes: 4 additions & 1 deletion hpccm/building_blocks/pip.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
from packaging.version import Version
import logging
import posixpath
from six.moves import shlex_quote

import hpccm.config
import hpccm.templates.rm
Expand Down Expand Up @@ -165,6 +166,8 @@ def __instructions(self):
posixpath.basename(self.__requirements))]))

if self.__packages:
# Quote the packages to avoid shell expansion
quoted_packages = [shlex_quote(pkg) for pkg in self.__packages]
cmds.append('{0} install {1}'.format(self.__pip,
' '.join(self.__packages)))
' '.join(quoted_packages)))
self += shell(commands=cmds)
9 changes: 9 additions & 0 deletions test/test_pip.py
Original file line number Diff line number Diff line change
Expand Up @@ -166,3 +166,12 @@ def test_upgrade(self):
rm -rf /var/lib/apt/lists/*
RUN pip --no-cache-dir install --upgrade "pip < 21.0" && \
pip --no-cache-dir install hpccm''')

@ubuntu
@docker
def test_package_with_version(self):
"""package with version specifier is quoted"""
p = pip(ospackages=[], packages=['hpccm>=1.0'])
self.assertEqual(str(p),
r"""# pip
RUN pip --no-cache-dir install 'hpccm>=1.0'""")
Loading