Skip to content

Commit 0fe4deb

Browse files
Allow pip to take arguments coming after install (#530)
Replace index_url with more general install_args There could be other arguments that need to be passed to 'pip install' that must come *after* the install. Include all of them. Add unit test for pip install args Update docs Switch unit test to single arg Signed-off-by: Dylan Eustice <deustice@nvidia.com>
1 parent ff7ed3e commit 0fe4deb

3 files changed

Lines changed: 20 additions & 0 deletions

File tree

docs/building_blocks.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3911,6 +3911,9 @@ empty.
39113911
upgraded prior to installing any PyPi packages. The default is
39123912
False.
39133913

3914+
- __install_args__: List of arguments to pass to `pip install`. The
3915+
default is an empty list. Only applies to the `packages` parameter.
3916+
39143917
__Examples__
39153918

39163919

hpccm/building_blocks/pip.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,9 @@ class pip(bb_base, hpccm.templates.rm):
6666
upgraded prior to installing any PyPi packages. The default is
6767
False.
6868
69+
install_args: List of arguments to pass to `pip install`. The
70+
default is an empty list. Only applies to the `packages` parameter.
71+
6972
# Examples
7073
7174
```python
@@ -96,6 +99,7 @@ def __init__(self, **kwargs):
9699
self.__requirements = kwargs.get('requirements', None)
97100
self.__upgrade = kwargs.get('upgrade', False)
98101
self.__wd = kwargs.get('wd', hpccm.config.g_wd) # working directory
102+
self.__install_args = kwargs.get('install_args', [])
99103

100104
self.__debs = [] # Filled in below
101105
self.__rpms = [] # Filled in below
@@ -170,4 +174,7 @@ def __instructions(self):
170174
quoted_packages = [shlex_quote(pkg) for pkg in self.__packages]
171175
cmds.append('{0} install {1}'.format(self.__pip,
172176
' '.join(quoted_packages)))
177+
if self.__install_args:
178+
cmds[-1] += ' {0}'.format(' '.join(self.__install_args))
179+
173180
self += shell(commands=cmds)

test/test_pip.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,3 +175,13 @@ def test_package_with_version(self):
175175
self.assertEqual(str(p),
176176
r"""# pip
177177
RUN pip --no-cache-dir install 'hpccm>=1.0'""")
178+
179+
@ubuntu
180+
@docker
181+
def test_install_args(self):
182+
"""install_args option"""
183+
p = pip(ospackages=[], packages=['hpccm'],
184+
install_args=['--index-url https://my-index.com'])
185+
self.assertEqual(str(p),
186+
r'''# pip
187+
RUN pip --no-cache-dir install hpccm --index-url https://my-index.com''')

0 commit comments

Comments
 (0)