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
3 changes: 3 additions & 0 deletions docs/building_blocks.md
Original file line number Diff line number Diff line change
Expand Up @@ -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__


Expand Down
7 changes: 7 additions & 0 deletions hpccm/building_blocks/pip.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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)
10 changes: 10 additions & 0 deletions test/test_pip.py
Original file line number Diff line number Diff line change
Expand Up @@ -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''')
Loading