diff --git a/docs/building_blocks.md b/docs/building_blocks.md index a36694f..f776140 100644 --- a/docs/building_blocks.md +++ b/docs/building_blocks.md @@ -3911,6 +3911,9 @@ empty. upgraded prior to installing any PyPi packages. The default is False. +- __install_args__: List of arguments to pass to `pip install`. The +default is an empty list. Only applies to the `packages` parameter. + __Examples__ diff --git a/hpccm/building_blocks/pip.py b/hpccm/building_blocks/pip.py index 178b46c..d1a7176 100644 --- a/hpccm/building_blocks/pip.py +++ b/hpccm/building_blocks/pip.py @@ -66,6 +66,9 @@ class pip(bb_base, hpccm.templates.rm): upgraded prior to installing any PyPi packages. The default is False. + install_args: List of arguments to pass to `pip install`. The + default is an empty list. Only applies to the `packages` parameter. + # Examples ```python @@ -96,6 +99,7 @@ def __init__(self, **kwargs): self.__requirements = kwargs.get('requirements', None) self.__upgrade = kwargs.get('upgrade', False) self.__wd = kwargs.get('wd', hpccm.config.g_wd) # working directory + self.__install_args = kwargs.get('install_args', []) self.__debs = [] # Filled in below self.__rpms = [] # Filled in below @@ -170,4 +174,7 @@ def __instructions(self): quoted_packages = [shlex_quote(pkg) for pkg in self.__packages] cmds.append('{0} install {1}'.format(self.__pip, ' '.join(quoted_packages))) + if self.__install_args: + cmds[-1] += ' {0}'.format(' '.join(self.__install_args)) + self += shell(commands=cmds) diff --git a/test/test_pip.py b/test/test_pip.py index 1bc6498..d79f0ed 100644 --- a/test/test_pip.py +++ b/test/test_pip.py @@ -175,3 +175,13 @@ def test_package_with_version(self): self.assertEqual(str(p), r"""# pip RUN pip --no-cache-dir install 'hpccm>=1.0'""") + + @ubuntu + @docker + def test_install_args(self): + """install_args option""" + p = pip(ospackages=[], packages=['hpccm'], + install_args=['--index-url https://my-index.com']) + self.assertEqual(str(p), +r'''# pip +RUN pip --no-cache-dir install hpccm --index-url https://my-index.com''')