Skip to content

Commit 125e12c

Browse files
committed
Let pip upgrade packages
Since we now longer pin versions to the patch version, we should make an install cause the packages upgrade within the version constraints rathern than just settle for the current version if it is already installed.
1 parent 6197784 commit 125e12c

File tree

2 files changed

+40
-25
lines changed

2 files changed

+40
-25
lines changed

tljh/conda.py

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,9 @@ def install_miniconda(installer_path, prefix):
9696
def ensure_conda_packages(prefix, packages):
9797
"""
9898
Ensure packages (from conda-forge) are installed in the conda prefix.
99+
100+
Note that conda seem to update dependencies by default, so there is probably
101+
no need to have a update parameter exposed for this function.
99102
"""
100103
conda_executable = [os.path.join(prefix, 'bin', 'mamba')]
101104
abspath = os.path.abspath(prefix)
@@ -124,32 +127,29 @@ def ensure_conda_packages(prefix, packages):
124127
fix_permissions(prefix)
125128

126129

127-
def ensure_pip_packages(prefix, packages):
130+
def ensure_pip_packages(prefix, packages, upgrade=False):
128131
"""
129132
Ensure pip packages are installed in the given conda prefix.
130133
"""
131134
abspath = os.path.abspath(prefix)
132135
pip_executable = [os.path.join(abspath, 'bin', 'python'), '-m', 'pip']
133-
134-
utils.run_subprocess(pip_executable + [
135-
'install',
136-
'--no-cache-dir',
137-
] + packages)
136+
pip_cmd = pip_executable + ['install', '--no-cache-dir']
137+
if upgrade:
138+
pip_cmd.append('--upgrade')
139+
utils.run_subprocess(pip_cmd + packages)
138140
fix_permissions(prefix)
139141

140142

141-
def ensure_pip_requirements(prefix, requirements_path):
143+
def ensure_pip_requirements(prefix, requirements_path, upgrade=False):
142144
"""
143145
Ensure pip packages from given requirements_path are installed in given conda prefix.
144146
145147
requirements_path can be a file or a URL.
146148
"""
147149
abspath = os.path.abspath(prefix)
148150
pip_executable = [os.path.join(abspath, 'bin', 'python'), '-m', 'pip']
149-
150-
utils.run_subprocess(pip_executable + [
151-
'install',
152-
'-r',
153-
requirements_path
154-
])
151+
pip_cmd = pip_executable + ['install', '--no-cache-dir']
152+
if upgrade:
153+
pip_cmd.append('--upgrade')
154+
utils.run_subprocess(pip_cmd + ['--requirement', requirements_path])
155155
fix_permissions(prefix)

tljh/installer.py

Lines changed: 27 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -124,9 +124,7 @@ def ensure_jupyterhub_package(prefix):
124124
'libcurl4-openssl-dev',
125125
'build-essential'
126126
])
127-
conda.ensure_pip_packages(prefix, [
128-
'pycurl==7.*'
129-
])
127+
conda.ensure_pip_packages(prefix, ['pycurl==7.*'], upgrade=True)
130128

131129
conda.ensure_pip_packages(
132130
prefix,
@@ -141,6 +139,7 @@ def ensure_jupyterhub_package(prefix):
141139
"jupyterhub-idle-culler==1.*",
142140
"git+https://github.com/yuvipanda/jupyterhub-configurator@317759e17c8e48de1b1352b836dac2a230536dba"
143141
],
142+
upgrade=True,
144143
)
145144
traefik.ensure_traefik_binary(prefix)
146145

@@ -193,20 +192,28 @@ def ensure_user_environment(user_requirements_txt_file):
193192
conda.install_miniconda(installer_path, USER_ENV_PREFIX)
194193
conda_version = '4.10.3'
195194

196-
conda.ensure_conda_packages(USER_ENV_PREFIX, [
197-
# Conda's latest version is on conda much more so than on PyPI.
198-
'conda==' + conda_version,
199-
'mamba==' + mambaforge_mamba_version,
200-
])
195+
conda.ensure_conda_packages(
196+
USER_ENV_PREFIX,
197+
[
198+
# Conda's latest version is on conda much more so than on PyPI.
199+
'conda==' + conda_version,
200+
'mamba==' + mambaforge_mamba_version,
201+
],
202+
)
201203

202204
conda.ensure_pip_requirements(
203205
USER_ENV_PREFIX,
204206
os.path.join(HERE, 'requirements-base.txt'),
207+
upgrade=True,
205208
)
206209

207210
if user_requirements_txt_file:
208211
# FIXME: This currently fails hard, should fail soft and not abort installer
209-
conda.ensure_pip_requirements(USER_ENV_PREFIX, user_requirements_txt_file)
212+
conda.ensure_pip_requirements(
213+
USER_ENV_PREFIX,
214+
user_requirements_txt_file,
215+
upgrade=True,
216+
)
210217

211218

212219
def ensure_admins(admin_password_list):
@@ -313,7 +320,7 @@ def setup_plugins(plugins=None):
313320
"""
314321
# Install plugins
315322
if plugins:
316-
conda.ensure_pip_packages(HUB_ENV_PREFIX, plugins)
323+
conda.ensure_pip_packages(HUB_ENV_PREFIX, plugins, upgrade=True)
317324

318325
# Set up plugin infrastructure
319326
pm = pluggy.PluginManager('tljh')
@@ -342,7 +349,11 @@ def run_plugin_actions(plugin_manager):
342349
logger.info('Installing {} hub pip packages collected from plugins: {}'.format(
343350
len(hub_pip_packages), ' '.join(hub_pip_packages)
344351
))
345-
conda.ensure_pip_packages(HUB_ENV_PREFIX, hub_pip_packages)
352+
conda.ensure_pip_packages(
353+
HUB_ENV_PREFIX,
354+
hub_pip_packages,
355+
upgrade=True,
356+
)
346357

347358
# Install conda packages
348359
conda_packages = list(set(itertools.chain(*hook.tljh_extra_user_conda_packages())))
@@ -358,7 +369,11 @@ def run_plugin_actions(plugin_manager):
358369
logger.info('Installing {} user pip packages collected from plugins: {}'.format(
359370
len(user_pip_packages), ' '.join(user_pip_packages)
360371
))
361-
conda.ensure_pip_packages(USER_ENV_PREFIX, user_pip_packages)
372+
conda.ensure_pip_packages(
373+
USER_ENV_PREFIX,
374+
user_pip_packages,
375+
upgrade=True,
376+
)
362377

363378
# Custom post install actions
364379
hook.tljh_post_install()

0 commit comments

Comments
 (0)