jupyterhub / the-littlest-jupyterhub

Simple JupyterHub distribution for 1-100 users on a single server
https://tljh.jupyter.org
BSD 3-Clause "New" or "Revised" License
1.03k stars 339 forks source link

tljh.installer: support --user-requirements-txt-path flag alongside the --user-requirements-txt-url flag #461

Open erinfry6 opened 4 years ago

erinfry6 commented 4 years ago

It would be really great if you could pip install packages from a .txt file on the VM, not necessarily from a URL .txt file.

I'm deploying on Google Cloud, so I have access to my requirements.txt in GCS easily using gcsfuse, but the URL of the file is much less reliable.

Thanks for everything!

Milchdealer commented 4 years ago

Hey erinfry6,

I know this is not really a fix, but I struggled with the same problem and took a look into the bootstrap.py.

pip_flags = ['--upgrade']
if os.environ.get('TLJH_BOOTSTRAP_DEV', 'no') == 'yes':
    pip_flags.append('--editable')
tljh_repo_path = os.environ.get(
    'TLJH_BOOTSTRAP_PIP_SPEC',
    'git+https://github.com/jupyterhub/the-littlest-jupyterhub.git'
)

run_subprocess([
    os.path.join(hub_prefix, 'bin', 'pip'),
    'install'
] + pip_flags + [tljh_repo_path])

If you look at it, you could change the ENVIRONMENT variable TLJH_BOOTSTRAP_PIP_SPEC to your dependencies (don't forgot to include the original dependencies) and it should install your requirements as well.

Did not test it yet, but I'm going to try to modify this or the bootstrap.py to get it to work. Will update if I have a proper way

*edit: I found out that the TLJH_BOOTSTRAP_PIP_SPEC can also be set to a folder

jtpio commented 4 years ago

@erinfry6 are you referring to the user requirements specified via --user-requirements-txt-url?

If so then it should already be supported, since the option is passed to pip directly:

https://github.com/jupyterhub/the-littlest-jupyterhub/blob/0656fbbb1495f7d2df5e3d990c783f2282d6551d/tljh/conda.py#L148-L152

consideRatio commented 2 years ago

Note that TLJH_BOOTSTRAP_PIP_SPEC is about locating the place to install the tljh package for use in the host systems root python environment that is installed via a setup.py within this repo, not additional packages for the user environment etc.

There is the --user-requirements-txt-url flag as documented here: https://tljh.jupyter.org/en/latest/topic/customizing-installer.html#installing-python-packages-in-the-user-environment

There is not a --user-requirements-txt-path or similar though to point to a local requirements.txt file. But, perhaps there should be?

For reference, these are the supported flags by the bootstrap.py script / tljh.installer, where the bootstrap.py script will just pass them onwards to the tljh.installer.

https://github.com/jupyterhub/the-littlest-jupyterhub/blob/0656fbbb1495f7d2df5e3d990c783f2282d6551d/tljh/installer.py#L468-L482