def run_plugin_actions(plugin_manager, plugins): """ Run installer hooks defined in plugins """ hook = plugin_manager.hook # Install apt packages apt_packages = list(set(itertools.chain(*hook.tljh_extra_apt_packages()))) if apt_packages: logger.info('Installing {} apt packages collected from plugins: {}'.format( len(apt_packages), ' '.join(apt_packages) )) apt.install_packages(apt_packages) # Install conda packages conda_packages = list(set(itertools.chain(*hook.tljh_extra_user_conda_packages()))) if conda_packages: logger.info('Installing {} conda packages collected from plugins: {}'.format( len(conda_packages), ' '.join(conda_packages) )) conda.ensure_conda_packages(USER_ENV_PREFIX, conda_packages) # Install pip packages pip_packages = list(set(itertools.chain(*hook.tljh_extra_user_pip_packages()))) if pip_packages: logger.info('Installing {} pip packages collected from plugins: {}'.format( len(pip_packages), ' '.join(pip_packages) )) conda.ensure_pip_packages(USER_ENV_PREFIX, pip_packages)
def ensure_user_environment(user_requirements_txt_file): """ Set up user conda environment with required packages """ print("Setting up user environment...") conda.ensure_conda_env(USER_ENV_PREFIX) conda.ensure_conda_packages( USER_ENV_PREFIX, [ # Conda's latest version is on conda much more so than on PyPI. 'conda==4.5.8' ]) conda.ensure_pip_packages( USER_ENV_PREFIX, [ # JupyterHub + notebook package are base requirements for user environment 'jupyterhub==0.9.1', 'notebook==5.6.0', # Install additional notebook frontends! 'jupyterlab==0.32.1', 'nteract-on-jupyter==1.8.1', # nbgitpuller for easily pulling in Git repositories 'nbgitpuller==0.6.1' ]) if user_requirements_txt_file: # FIXME: This currently fails hard, should fail soft and not abort installer conda.ensure_pip_requirements(USER_ENV_PREFIX, user_requirements_txt_file)
def test_ensure_packages(prefix): """ Test installing packages in conda environment """ conda.ensure_conda_packages(prefix, ["numpy"]) # Throws an error if this fails subprocess.check_call( [os.path.join(prefix, "bin", "python"), "-c", "import numpy"])
def test_ensure_packages(prefix): """ Test installing packages in conda environment """ conda.ensure_conda_packages(prefix, ['numpy']) # Throws an error if this fails subprocess.check_call( [os.path.join(prefix, 'bin', 'python'), '-c', 'import numpy'])
def ensure_user_environment(user_requirements_txt_file): """ Set up user conda environment with required packages """ logger.info("Setting up user environment...") miniconda_old_version = '4.5.4' miniconda_new_version = '4.7.10' conda_version = '4.5.8' # If no prior miniconda installation is found, we can install a newer version if not conda.check_miniconda_version( USER_ENV_PREFIX, miniconda_old_version) and not conda.check_miniconda_version( USER_ENV_PREFIX, miniconda_new_version): miniconda_installer_md5 = "1c945f2b3335c7b2b15130b1b2dc5cf4" conda_version = '4.8.1' logger.info('Downloading & setting up user environment...') with conda.download_miniconda_installer( miniconda_new_version, miniconda_installer_md5) as installer_path: conda.install_miniconda(installer_path, USER_ENV_PREFIX) conda.ensure_conda_packages( USER_ENV_PREFIX, [ # Conda's latest version is on conda much more so than on PyPI. 'conda==' + conda_version ]) conda.ensure_pip_packages( USER_ENV_PREFIX, [ # JupyterHub + notebook package are base requirements for user environment 'jupyterhub==1.0.0', 'notebook==5.7.8', # Install additional notebook frontends! 'jupyterlab==0.35.4', 'nteract-on-jupyter==2.0.7', # nbgitpuller for easily pulling in Git repositories 'nbgitpuller==0.6.1', # nbresuse to show people how much RAM they are using 'nbresuse==0.3.0', # Most people consider ipywidgets to be part of the core notebook experience 'ipywidgets==7.4.2', # Pin tornado 'tornado<6.0', ]) if user_requirements_txt_file: # FIXME: This currently fails hard, should fail soft and not abort installer conda.ensure_pip_requirements(USER_ENV_PREFIX, user_requirements_txt_file)
def test_ensure_pip_requirements(prefix): """ Test installing pip packages with requirements.txt in conda environment """ conda.ensure_conda_packages(prefix, ['pip']) with tempfile.NamedTemporaryFile() as f: # Sample small package to test f.write('there'.encode()) f.flush() conda.ensure_pip_requirements(prefix, f.name) subprocess.check_call( [os.path.join(prefix, 'bin', 'python'), '-c', 'import there'])
def prefix(): """ Provide a temporary directory with a conda environment """ miniconda_version = '4.5.4' miniconda_installer_md5 = "a946ea1d0c4a642ddf0c3a26a18bb16d" with tempfile.TemporaryDirectory() as tmpdir: with conda.download_miniconda_installer( miniconda_version, miniconda_installer_md5) as installer_path: conda.install_miniconda(installer_path, tmpdir) conda.ensure_conda_packages(tmpdir, ['conda==4.5.8']) yield tmpdir
def test_ensure_pip_requirements(prefix): """ Test installing pip packages with requirements.txt in conda environment """ conda.ensure_conda_packages(prefix, ["pip"]) with tempfile.NamedTemporaryFile() as f: # Sample small package to test f.write(b"there") f.flush() conda.ensure_pip_requirements(prefix, f.name) subprocess.check_call( [os.path.join(prefix, "bin", "python"), "-c", "import there"])
def prefix(): """ Provide a temporary directory with a miniforge conda environment """ miniforge_version = '4.10.0-0' miniforge_installer_sha256 = "9c81d4dd830991374d8041f6b835920cf7ad355ea3ae80c236cd74237d5315a1" installer_url = f"https://github.com/conda-forge/miniforge/releases/download/{miniforge_version}/Miniforge3-{os.uname().sysname}-{os.uname().machine}.sh" with tempfile.TemporaryDirectory() as tmpdir: with conda.download_miniforge_installer( installer_url, miniforge_installer_sha256) as installer_path: conda.install_miniforge(installer_path, tmpdir) conda.ensure_conda_packages(tmpdir, ['conda==4.10.0']) yield tmpdir
def prefix(): """ Provide a temporary directory with a conda environment """ miniconda_version = '4.7.10' miniconda_installer_sha256 = "1314b90489f154602fd794accfc90446111514a5a72fe1f71ab83e07de9504a7" installer_url = "https://repo.anaconda.com/miniconda/Miniconda3-latest-Linux-x86_64.sh" with tempfile.TemporaryDirectory() as tmpdir: with conda.download_miniconda_installer( installer_url, miniconda_installer_sha256) as installer_path: conda.install_miniconda(installer_path, tmpdir) conda.ensure_conda_packages(tmpdir, ['conda==4.9.2']) yield tmpdir
def prefix(): """ Provide a temporary directory with a conda environment """ miniconda_version = '4.7.10' miniconda_installer_md5 = "1c945f2b3335c7b2b15130b1b2dc5cf4" with tempfile.TemporaryDirectory() as tmpdir: with conda.download_miniconda_installer(miniconda_version, miniconda_installer_md5) as installer_path: conda.install_miniconda(installer_path, tmpdir) conda.ensure_conda_packages(tmpdir, [ 'conda==4.8.1' ]) yield tmpdir
def ensure_jupyterhub_package(prefix): """ Install JupyterHub into our conda environment if needed. Conda constructor does not play well with conda-forge, so we can ship this with constructor """ # FIXME: Use fully deterministic package lists here conda.ensure_conda_packages(prefix, ['jupyterhub==0.9.0']) conda.ensure_pip_packages(prefix, [ 'jupyterhub-dummyauthenticator==0.3.1', 'jupyterhub-systemdspawner==0.9.12', ])
def prefix(): """ Provide a temporary directory with a conda environment """ miniconda_version = '4.7.10' miniconda_installer_sha256 = "8a324adcc9eaf1c09e22a992bb6234d91a94146840ee6b11c114ecadafc68121" installer_url = "https://repo.continuum.io/miniconda/Miniconda3-{}-Linux-x86_64.sh".format( miniconda_version) with tempfile.TemporaryDirectory() as tmpdir: with conda.download_miniconda_installer( installer_url, miniconda_installer_sha256) as installer_path: conda.install_miniconda(installer_path, tmpdir) conda.ensure_conda_packages(tmpdir, ['conda==4.8.1']) yield tmpdir
def run_plugin_actions(plugin_manager): """ Run installer hooks defined in plugins """ hook = plugin_manager.hook # Install apt packages apt_packages = list(set(itertools.chain(*hook.tljh_extra_apt_packages()))) if apt_packages: logger.info( "Installing {} apt packages collected from plugins: {}".format( len(apt_packages), " ".join(apt_packages))) apt.install_packages(apt_packages) # Install hub pip packages hub_pip_packages = list( set(itertools.chain(*hook.tljh_extra_hub_pip_packages()))) if hub_pip_packages: logger.info( "Installing {} hub pip packages collected from plugins: {}".format( len(hub_pip_packages), " ".join(hub_pip_packages))) conda.ensure_pip_packages( HUB_ENV_PREFIX, hub_pip_packages, upgrade=True, ) # Install conda packages conda_packages = list( set(itertools.chain(*hook.tljh_extra_user_conda_packages()))) if conda_packages: logger.info( "Installing {} user conda packages collected from plugins: {}". format(len(conda_packages), " ".join(conda_packages))) conda.ensure_conda_packages(USER_ENV_PREFIX, conda_packages) # Install pip packages user_pip_packages = list( set(itertools.chain(*hook.tljh_extra_user_pip_packages()))) if user_pip_packages: logger.info( "Installing {} user pip packages collected from plugins: {}". format(len(user_pip_packages), " ".join(user_pip_packages))) conda.ensure_pip_packages( USER_ENV_PREFIX, user_pip_packages, upgrade=True, ) # Custom post install actions hook.tljh_post_install()
def ensure_user_environment(user_requirements_txt_file): """ Set up user conda environment with required packages """ logger.info("Setting up user environment...") miniconda_old_version = '4.5.4' miniconda_new_version = '4.7.10' miniconda_installer_sha256 = "8a324adcc9eaf1c09e22a992bb6234d91a94146840ee6b11c114ecadafc68121" miniforge_new_version = '4.8.0' miniforge_old_version = '4.7.0' if os.uname().machine == 'aarch64': miniforge_installer_sha256 = '57dd34c670cd499099464b094d26461f43365c2c6211f3bc0a87015f39dbb992' elif os.uname().machine == 'x86_64': miniforge_installer_sha256 = '9c81d4dd830991374d8041f6b835920cf7ad355ea3ae80c236cd74237d5315a1' if conda.check_miniforge_version(USER_ENV_PREFIX, miniforge_new_version): conda_version = '4.9.2' elif conda.check_miniforge_version(USER_ENV_PREFIX, miniforge_old_version): conda_version = '4.7.0' # If no prior miniconda installation is found, we can install a newer version else: logger.info('Downloading & setting up user environment...') miniforge_version = '4.10.0-0' logger.info("Getting miniforge") # installer_url = f"https://github.com/conda-forge/miniforge/releases/latest/download/Miniforge3-{os.uname().sysname}-{os.uname().machine}.sh" installer_url = f"https://github.com/conda-forge/miniforge/releases/download/{miniforge_version}/Miniforge3-{os.uname().sysname}-{os.uname().machine}.sh" with conda.download_miniforge_installer( installer_url, miniforge_installer_sha256) as installer_path: conda.install_miniforge(installer_path, USER_ENV_PREFIX) logger.info("Finished installing miniforge") conda_version = '4.10.0' conda.ensure_conda_packages( USER_ENV_PREFIX, [ # Conda's latest version is on conda much more so than on PyPI. 'conda==' + conda_version ]) conda.ensure_pip_requirements( USER_ENV_PREFIX, os.path.join(HERE, 'requirements-base.txt'), ) if user_requirements_txt_file: # FIXME: This currently fails hard, should fail soft and not abort installer conda.ensure_pip_requirements(USER_ENV_PREFIX, user_requirements_txt_file)
def prefix(): """ Provide a temporary directory with a conda environment """ miniconda_version = '4.8.3' miniconda_installer_sha256 = "879457af6a0bf5b34b48c12de31d4df0ee2f06a8e68768e5758c3293b2daf688" installer_url = "https://repo.continuum.io/miniconda/Miniconda3-{}-Linux-x86_64.sh".format( miniconda_version) with tempfile.TemporaryDirectory() as tmpdir: with conda.download_miniconda_installer( installer_url, miniconda_installer_sha256) as installer_path: conda.install_miniconda(installer_path, tmpdir) conda.ensure_conda_packages(tmpdir, ['conda==4.8.1']) yield tmpdir
def ensure_user_environment(user_requirements_txt_file): """ Set up user conda environment with required packages """ logger.info("Setting up user environment...") miniconda_version = '4.5.4' miniconda_installer_md5 = "a946ea1d0c4a642ddf0c3a26a18bb16d" if not conda.check_miniconda_version(USER_ENV_PREFIX, miniconda_version): logger.info('Downloading & setting up user environment...') with conda.download_miniconda_installer( miniconda_version, miniconda_installer_md5) as installer_path: conda.install_miniconda(installer_path, USER_ENV_PREFIX) # nbresuse needs psutil, which requires gcc apt.install_packages(['gcc']) conda.ensure_conda_packages( USER_ENV_PREFIX, [ # Conda's latest version is on conda much more so than on PyPI. 'conda==4.5.8' ]) conda.ensure_pip_packages( USER_ENV_PREFIX, [ # JupyterHub + notebook package are base requirements for user environment 'jupyterhub==0.9.4', 'notebook==5.7.0', # Install additional notebook frontends! 'jupyterlab==0.35.3', 'nteract-on-jupyter==1.9.12', # nbgitpuller for easily pulling in Git repositories 'nbgitpuller==0.6.1', # nbresuse to show people how much RAM they are using 'nbresuse==0.3.0', # Most people consider ipywidgets to be part of the core notebook experience 'ipywidgets==7.4.2', # Pin tornado 'tornado<6.0' ]) if user_requirements_txt_file: # FIXME: This currently fails hard, should fail soft and not abort installer conda.ensure_pip_requirements(USER_ENV_PREFIX, user_requirements_txt_file)
def ensure_user_environment(user_requirements_txt_file): """ Set up user conda environment with required packages """ logger.info("Setting up user environment...") miniconda_old_version = '4.5.4' miniconda_new_version = '4.7.10' miniconda_installer_sha256 = "80ecc86f8c2f131c5170e43df489514f80e3971dd105c075935470bbf2476dea" if conda.check_miniconda_version(USER_ENV_PREFIX, miniconda_new_version): logger.info('Conda exists - version 4.5.4') conda_version = '4.5.4' elif conda.check_miniconda_version(USER_ENV_PREFIX, miniconda_old_version): logger.info('Conda exists - version 4.7.10') conda_version = '4.5.4' # If no prior miniconda installation is found, we can install a newer version else: logger.info('Downloading & setting up user environment...') conda_version = '4.5.4' # FIXME: allow using miniforge installer_url = "https://repo.continuum.io/miniconda/Miniconda3-{}-Linux-x86_64.sh".format( conda_version) with conda.download_miniconda_installer( installer_url, miniconda_installer_sha256) as installer_path: conda.install_miniconda(installer_path, USER_ENV_PREFIX) conda.ensure_conda_packages( USER_ENV_PREFIX, [ # Conda's latest version is on conda much more so than on PyPI. 'conda==' + conda_version ]) conda.ensure_pip_requirements( USER_ENV_PREFIX, os.path.join(HERE, 'requirements-base.txt'), ) if user_requirements_txt_file: # FIXME: This currently fails hard, should fail soft and not abort installer conda.ensure_pip_requirements(USER_ENV_PREFIX, user_requirements_txt_file)
def ensure_jupyterhub_package(prefix): """ Install JupyterHub into our conda environment if needed. We install all python packages from PyPI as much as possible in the hub environment. A lot of spawners & authenticators do not have conda-forge packages, but do have pip packages. Keeping all python packages in the hub environment be installed with pip prevents accidental mixing of python and conda packages! """ conda.ensure_conda_packages(prefix, ['configurable-http-proxy==3.1.0']) conda.ensure_pip_packages(prefix, [ 'jupyterhub==0.9.1', 'jupyterhub-dummyauthenticator==0.3.1', 'jupyterhub-systemdspawner==0.11', 'jupyterhub-firstuseauthenticator==0.10', 'jupyterhub-ldapauthenticator==1.2.2', 'oauthenticator==0.7.3', ])
def prefix(): """ Provide a temporary directory with a mambaforge conda environment """ # see https://github.com/conda-forge/miniforge/releases mambaforge_version = "4.10.3-7" if os.uname().machine == "aarch64": installer_sha256 = ( "ac95f137b287b3408e4f67f07a284357b1119ee157373b788b34e770ef2392b2") elif os.uname().machine == "x86_64": installer_sha256 = ( "fc872522ec427fcab10167a93e802efaf251024b58cc27b084b915a9a73c4474") installer_url = "https://github.com/conda-forge/miniforge/releases/download/{v}/Mambaforge-{v}-Linux-{arch}.sh".format( v=mambaforge_version, arch=os.uname().machine) with tempfile.TemporaryDirectory() as tmpdir: with conda.download_miniconda_installer( installer_url, installer_sha256) as installer_path: conda.install_miniconda(installer_path, tmpdir) conda.ensure_conda_packages(tmpdir, ["conda==4.10.3"]) yield tmpdir
def ensure_user_environment(user_requirements_txt_file): """ Set up user conda environment with required packages """ logger.info("Setting up user environment...") miniconda_old_version = '4.5.4' miniconda_new_version = '4.7.10' miniconda_installer_sha256 = "8a324adcc9eaf1c09e22a992bb6234d91a94146840ee6b11c114ecadafc68121" if conda.check_miniconda_version(USER_ENV_PREFIX, miniconda_new_version): conda_version = '4.8.1' elif conda.check_miniconda_version(USER_ENV_PREFIX, miniconda_old_version): conda_version = '4.5.8' # If no prior miniconda installation is found, we can install a newer version else: logger.info('Downloading & setting up user environment...') # FIXME: allow using miniforge installer_url = "https://repo.continuum.io/miniconda/Miniconda3-{}-Linux-x86_64.sh".format( miniconda_new_version) with conda.download_miniconda_installer( installer_url, miniconda_installer_sha256) as installer_path: conda.install_miniconda(installer_path, USER_ENV_PREFIX) conda_version = '4.8.1' conda.ensure_conda_packages( USER_ENV_PREFIX, [ # Conda's latest version is on conda much more so than on PyPI. 'conda==' + conda_version ]) conda.ensure_pip_requirements( USER_ENV_PREFIX, os.path.join(HERE, 'requirements-base.txt'), ) if user_requirements_txt_file: # FIXME: This currently fails hard, should fail soft and not abort installer conda.ensure_pip_requirements(USER_ENV_PREFIX, user_requirements_txt_file)
def ensure_user_environment(user_requirements_txt_file): """ Set up user conda environment with required packages """ logger.info("Setting up user environment...") miniconda_old_version = '4.5.4' miniconda_new_version = '4.8.3' miniconda_installer_sha256 = "879457af6a0bf5b34b48c12de31d4df0ee2f06a8e68768e5758c3293b2daf688" if conda.check_miniconda_version(USER_ENV_PREFIX, miniconda_new_version): conda_version = '4.8.1' elif conda.check_miniconda_version(USER_ENV_PREFIX, miniconda_old_version): conda_version = '4.5.8' # If no prior miniconda installation is found, we can install a newer version else: logger.info('Downloading & setting up user environment...') # FIXME: allow using miniforge installer_url = "https://repo.continuum.io/miniconda/Miniconda3-py38_{}-Linux-x86_64.sh".format( miniconda_new_version) with conda.download_miniconda_installer( installer_url, miniconda_installer_sha256) as installer_path: conda.install_miniconda(installer_path, USER_ENV_PREFIX) conda_version = '4.8.3' conda.ensure_conda_packages( USER_ENV_PREFIX, [ # Conda's latest version is on conda much more so than on PyPI. 'conda==' + conda_version ]) conda.ensure_pip_requirements( USER_ENV_PREFIX, os.path.join(HERE, 'requirements-base.txt'), ) if user_requirements_txt_file: # FIXME: This currently fails hard, should fail soft and not abort installer conda.ensure_pip_requirements(USER_ENV_PREFIX, user_requirements_txt_file)
def ensure_user_environment(user_requirements_txt_file): """ Set up user conda environment with required packages """ logger.info("Setting up user environment...") miniconda_old_version = '4.5.4' miniconda_new_version = '4.7.10' miniconda_installer_sha256 = "1314b90489f154602fd794accfc90446111514a5a72fe1f71ab83e07de9504a7" if conda.check_miniconda_version(USER_ENV_PREFIX, miniconda_new_version): conda_version = '4.8.1' elif conda.check_miniconda_version(USER_ENV_PREFIX, miniconda_old_version): conda_version = '4.5.8' # If no prior miniconda installation is found, we can install a newer version else: logger.info('Downloading & setting up user environment...') # FIXME: allow using miniforge installer_url = "https://repo.anaconda.com/miniconda/Miniconda3-latest-Linux-x86_64.sh" with conda.download_miniconda_installer( installer_url, miniconda_installer_sha256) as installer_path: conda.install_miniconda(installer_path, USER_ENV_PREFIX) conda_version = '4.9.2' conda.ensure_conda_packages( USER_ENV_PREFIX, [ # Conda's latest version is on conda much more so than on PyPI. 'conda==' + conda_version ]) conda.ensure_pip_requirements( USER_ENV_PREFIX, os.path.join(HERE, 'requirements-base.txt'), ) if user_requirements_txt_file: # FIXME: This currently fails hard, should fail soft and not abort installer conda.ensure_pip_requirements(USER_ENV_PREFIX, user_requirements_txt_file)
def ensure_user_environment(user_requirements_txt_file): """ Set up user conda environment with required packages """ logger.info("Setting up user environment...") miniconda_old_version = '4.5.4' miniconda_new_version = '4.7.10' conda_version = '4.5.8' # If no prior miniconda installation is found, we can install a newer version if not conda.check_miniconda_version( USER_ENV_PREFIX, miniconda_old_version) and not conda.check_miniconda_version( USER_ENV_PREFIX, miniconda_new_version): miniconda_installer_md5 = "1c945f2b3335c7b2b15130b1b2dc5cf4" conda_version = '4.8.1' logger.info('Downloading & setting up user environment...') with conda.download_miniconda_installer( miniconda_new_version, miniconda_installer_md5) as installer_path: conda.install_miniconda(installer_path, USER_ENV_PREFIX) conda.ensure_conda_packages( USER_ENV_PREFIX, [ # Conda's latest version is on conda much more so than on PyPI. 'conda==' + conda_version ]) conda.ensure_pip_requirements( USER_ENV_PREFIX, os.path.join(HERE, 'requirements-base.txt'), ) if user_requirements_txt_file: # FIXME: This currently fails hard, should fail soft and not abort installer conda.ensure_pip_requirements(USER_ENV_PREFIX, user_requirements_txt_file)
def ensure_user_environment(user_requirements_txt_file): """ Set up user conda environment with required packages """ logger.info("Setting up user environment...") miniconda_version = '4.5.4' miniconda_installer_md5 = "a946ea1d0c4a642ddf0c3a26a18bb16d" if not conda.check_miniconda_version(USER_ENV_PREFIX, miniconda_version): logger.info('Downloading & setting up user environment...') with conda.download_miniconda_installer( miniconda_version, miniconda_installer_md5) as installer_path: conda.install_miniconda(installer_path, USER_ENV_PREFIX) conda.ensure_conda_packages( USER_ENV_PREFIX, [ # Conda's latest version is on conda much more so than on PyPI. 'conda==4.5.8' ]) conda.ensure_pip_packages( USER_ENV_PREFIX, [ # JupyterHub + notebook package are base requirements for user environment 'jupyterhub==0.9.1', 'notebook==5.6.0', # Install additional notebook frontends! 'jupyterlab==0.32.1', 'nteract-on-jupyter==1.8.1', # nbgitpuller for easily pulling in Git repositories 'nbgitpuller==0.6.1' ]) if user_requirements_txt_file: # FIXME: This currently fails hard, should fail soft and not abort installer conda.ensure_pip_requirements(USER_ENV_PREFIX, user_requirements_txt_file)
def ensure_user_environment(): """ Set up user conda environment with required packages """ print("Setting up user environment...") conda.ensure_conda_env(USER_ENV_PREFIX) conda.ensure_conda_packages( USER_ENV_PREFIX, [ # Conda's latest version is on conda much more so than on PyPI. 'conda==4.5.8' ]) conda.ensure_pip_packages( USER_ENV_PREFIX, [ # JupyterHub + notebook package are base requirements for user environment 'jupyterhub==0.9.0', 'notebook==5.5.0', # Install additional notebook frontends! 'jupyterlab==0.32.1', 'nteract-on-jupyter==1.8.1' ])
def ensure_user_environment(user_requirements_txt_file): """ Set up user conda environment with required packages """ logger.info("Setting up user environment...") miniconda_old_version = "4.5.4" miniconda_new_version = "4.7.10" # Install mambaforge using an installer from # https://github.com/conda-forge/miniforge/releases mambaforge_new_version = "4.10.3-7" # Check system architecture, set appropriate installer checksum if os.uname().machine == "aarch64": installer_sha256 = ( "ac95f137b287b3408e4f67f07a284357b1119ee157373b788b34e770ef2392b2") elif os.uname().machine == "x86_64": installer_sha256 = ( "fc872522ec427fcab10167a93e802efaf251024b58cc27b084b915a9a73c4474") # Check OS, set appropriate string for conda installer path if os.uname().sysname != "Linux": raise OSError("TLJH is only supported on Linux platforms.") # Then run `mamba --version` to get the conda and mamba versions # Keep these in sync with tests/test_conda.py::prefix mambaforge_conda_new_version = "4.10.3" mambaforge_mamba_version = "0.16.0" if conda.check_miniconda_version(USER_ENV_PREFIX, mambaforge_conda_new_version): conda_version = "4.10.3" elif conda.check_miniconda_version(USER_ENV_PREFIX, miniconda_new_version): conda_version = "4.8.1" elif conda.check_miniconda_version(USER_ENV_PREFIX, miniconda_old_version): conda_version = "4.5.8" # If no prior miniconda installation is found, we can install a newer version else: logger.info("Downloading & setting up user environment...") installer_url = "https://github.com/conda-forge/miniforge/releases/download/{v}/Mambaforge-{v}-Linux-{arch}.sh".format( v=mambaforge_new_version, arch=os.uname().machine) with conda.download_miniconda_installer( installer_url, installer_sha256) as installer_path: conda.install_miniconda(installer_path, USER_ENV_PREFIX) conda_version = "4.10.3" conda.ensure_conda_packages( USER_ENV_PREFIX, [ # Conda's latest version is on conda much more so than on PyPI. "conda==" + conda_version, "mamba==" + mambaforge_mamba_version, ], ) conda.ensure_pip_requirements( USER_ENV_PREFIX, os.path.join(HERE, "requirements-base.txt"), upgrade=True, ) if user_requirements_txt_file: # FIXME: This currently fails hard, should fail soft and not abort installer conda.ensure_pip_requirements( USER_ENV_PREFIX, user_requirements_txt_file, upgrade=True, )
ensure_jupyterhub_package(HUB_ENV_PREFIX) ensure_jupyterhub_service(HUB_ENV_PREFIX) user.ensure_group('jupyterhub-admins') user.ensure_group('jupyterhub-users') with open('/etc/sudoers.d/jupyterhub-admins', 'w') as f: # JupyterHub admins should have full passwordless sudo access f.write('%jupyterhub-admins ALL = (ALL) NOPASSWD: ALL\n') # `sudo -E` should preserve the $PATH we set. This allows # admins in jupyter terminals to do `sudo -E pip install <package>`, # `pip` is in the $PATH we set in jupyterhub_config.py to include the user conda env. f.write('Defaults exempt_group = jupyterhub-admins\n') conda.ensure_conda_env(USER_ENV_PREFIX) conda.ensure_conda_packages(USER_ENV_PREFIX, [ # Conda's latest version is on conda much more so than on PyPI. 'conda==4.5.4' ]) conda.ensure_pip_packages(USER_ENV_PREFIX, [ # JupyterHub + notebook package are base requirements for user environment 'jupyterhub==0.9.0', 'notebook==5.5.0', # Install additional notebook frontends! 'jupyterlab==0.32.1', 'nteract-on-jupyter==1.8.1' ])