Skip to content

Commit

Permalink
Merge pull request #354 from DigitalSlideArchive/devops-pip
Browse files Browse the repository at this point in the history
Provision additional modules via pip slightly more efficiently
  • Loading branch information
manthey authored Aug 20, 2024
2 parents 5e59ecb + e224b11 commit 76f7b26
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 30 deletions.
41 changes: 26 additions & 15 deletions devops/dsa/provision.py
Original file line number Diff line number Diff line change
Expand Up @@ -228,22 +228,41 @@ def get_slicer_images(imageList, adminUser, alwaysPull=False):
raise Exception('Failed to pull and load images')


def preprovision(opts):
def pip_install(packages):
"""
Preprovision the instance. This includes installing python modules with
pip and rebuilding the girder client if desired.
Pip install a list of packages via the shell pip install command. This
first tries installing all of the packages in a single command; if it
fails, they are tried individually to betetr show where the failure occurs.
:param opts: the argparse options.
:param packages: a list of strings to add to the end of the pip install
command.
"""
if getattr(opts, 'pip', None) and len(opts.pip):
for entry in opts.pip:
if not packages or not len(packages):
return
cmd = 'pip install -q ' + ' '.join(packages)
logger.info('Installing: %s', cmd)
try:
subprocess.check_call(cmd, shell=True)
except Exception:
logger.error(f'Failed to run {cmd}; trying pip install individually.')
for entry in packages:
cmd = 'pip install %s' % entry
logger.info('Installing: %s', cmd)
try:
subprocess.check_call(cmd, shell=True)
except Exception:
logger.error(f'Failed to run {cmd}')
raise


def preprovision(opts):
"""
Preprovision the instance. This includes installing python modules with
pip and rebuilding the girder client if desired.
:param opts: the argparse options.
"""
pip_install(getattr(opts, 'pip', None))
if getattr(opts, 'shell', None) and len(opts.shell):
for entry in opts.shell:
cmd = entry
Expand Down Expand Up @@ -360,15 +379,7 @@ def preprovision_worker(opts):
Preprovision the worker.
"""
settings = dict({}, **(opts.worker or {}))
if settings.get('pip') and len(settings['pip']):
for entry in settings['pip']:
cmd = 'pip install %s' % entry
logger.info('Installing: %s', cmd)
try:
subprocess.check_call(cmd, shell=True)
except Exception:
logger.error(f'Failed to run {cmd}')
raise
pip_install(settings.get('pip'))
if settings.get('shell') and len(settings['shell']):
for entry in settings['shell']:
cmd = entry
Expand Down
41 changes: 26 additions & 15 deletions devops/minimal/provision.py
Original file line number Diff line number Diff line change
Expand Up @@ -228,22 +228,41 @@ def get_slicer_images(imageList, adminUser, alwaysPull=False):
raise Exception('Failed to pull and load images')


def preprovision(opts):
def pip_install(packages):
"""
Preprovision the instance. This includes installing python modules with
pip and rebuilding the girder client if desired.
Pip install a list of packages via the shell pip install command. This
first tries installing all of the packages in a single command; if it
fails, they are tried individually to betetr show where the failure occurs.
:param opts: the argparse options.
:param packages: a list of strings to add to the end of the pip install
command.
"""
if getattr(opts, 'pip', None) and len(opts.pip):
for entry in opts.pip:
if not packages or not len(packages):
return
cmd = 'pip install -q ' + ' '.join(packages)
logger.info('Installing: %s', cmd)
try:
subprocess.check_call(cmd, shell=True)
except Exception:
logger.error(f'Failed to run {cmd}; trying pip install individually.')
for entry in packages:
cmd = 'pip install %s' % entry
logger.info('Installing: %s', cmd)
try:
subprocess.check_call(cmd, shell=True)
except Exception:
logger.error(f'Failed to run {cmd}')
raise


def preprovision(opts):
"""
Preprovision the instance. This includes installing python modules with
pip and rebuilding the girder client if desired.
:param opts: the argparse options.
"""
pip_install(getattr(opts, 'pip', None))
if getattr(opts, 'shell', None) and len(opts.shell):
for entry in opts.shell:
cmd = entry
Expand Down Expand Up @@ -360,15 +379,7 @@ def preprovision_worker(opts):
Preprovision the worker.
"""
settings = dict({}, **(opts.worker or {}))
if settings.get('pip') and len(settings['pip']):
for entry in settings['pip']:
cmd = 'pip install %s' % entry
logger.info('Installing: %s', cmd)
try:
subprocess.check_call(cmd, shell=True)
except Exception:
logger.error(f'Failed to run {cmd}')
raise
pip_install(settings.get('pip'))
if settings.get('shell') and len(settings['shell']):
for entry in settings['shell']:
cmd = entry
Expand Down

0 comments on commit 76f7b26

Please sign in to comment.