mirror of
https://github.com/jupyterhub/the-littlest-jupyterhub.git
synced 2025-12-18 21:54:05 +08:00
Add function to install packages from pip too
This commit is contained in:
@@ -51,3 +51,18 @@ def test_ensure_packages(prefix):
|
||||
'-c',
|
||||
'import numpy'
|
||||
])
|
||||
|
||||
|
||||
def test_ensure_pip_packages(prefix):
|
||||
"""
|
||||
Test installing pip packages in conda environment
|
||||
"""
|
||||
conda.ensure_conda_env(prefix)
|
||||
conda.ensure_conda_packages(prefix, ['pip'])
|
||||
conda.ensure_pip_packages(prefix, ['numpy'])
|
||||
# Throws an error if this fails
|
||||
subprocess.check_call([
|
||||
os.path.join(prefix, 'bin', 'python'),
|
||||
'-c',
|
||||
'import numpy'
|
||||
])
|
||||
|
||||
@@ -47,3 +47,16 @@ def ensure_conda_packages(prefix, packages):
|
||||
output = json.loads(filtered_output)
|
||||
if 'success' in output and output['success'] == True:
|
||||
return
|
||||
|
||||
|
||||
def ensure_pip_packages(prefix, packages):
|
||||
"""
|
||||
Ensure pip packages are installed in the given conda prefix.
|
||||
"""
|
||||
abspath = os.path.abspath(prefix)
|
||||
pip_executable = [os.path.join(abspath, 'bin', 'python'), '-m', 'pip']
|
||||
|
||||
subprocess.run(pip_executable + [
|
||||
'install',
|
||||
'--no-cache-dir',
|
||||
] + packages)
|
||||
|
||||
Reference in New Issue
Block a user