nanobox-io / nanobox-engine-python

Engine for running Python apps on Nanobox
https://nanobox.io
MIT License
12 stars 13 forks source link

Install Python packages to location they can be cached #43

Closed benspaulding closed 2 years ago

benspaulding commented 7 years ago

Configure Python to install packages to a place they can be cached. From my testing this works with regular system installations, virtualenv, pipenv, and python -m venv using both normal and editable packages.

Note that I did not add any tests for these changes. I am not familiar with the testing setup used in the engines and know that someone else could do it faster. If you do want to add tests, I think something like these would help:

  1. pip, setuptools, and wheel are properly installed by get-pip.py.
  2. which pip returns the custom location, e.g. /app/.nanobox/python/bin/pip.
  3. pip install spam installs spam into the custom location.
  4. pip install -e /path/to/local/bacon installs bacon into the custom location (python -c "import bacon" succeeds).
  5. pip install -e git+https://github.com/spam/beans.git#egg=beans installs beans into the custom location (python -c "import beans" succeeds), and the source was put in the custom location, e.g., /app/.nanobox/python/pip/src
  6. For env in {sys, virtualenv, pipenv, python -m venv}:
  7. virtualenv /tmp/spam succeeds.
  8. /tmp/spam/bin/pip install eggs installs eggs in /tmp/spam.
  9. /tmp/spam/bin/pip install -e git+https://github.com/bacon/beans.git#egg=beans installs beans into the custom location (python -c "import beans" succeeds), and the source was not put in the custom location, but in /tmp/spam/src.
  10. pipenv install spam succeeds.
  11. The virtualenv pipenv just created is in the custom location, e.g., /app/.nanobox/python-venvs, and spam is in it.
  12. python -m venv /tmp/eggs succeeds. (Python 3 only)
  13. /tmp/eggs/bin/pip install bacon installs bacon in /tmp/eggs. (Python 3 only)
  14. For every kind of virtualenv, ensure that our custom site-packages (/app/.nanobox/python/lib/pythonX.Y/site-packages) is not in sys.path.
benspaulding commented 7 years ago

I now see tests failing, and realize that they will need updated. But I would like to leave that for a Nanobox dev if possible.

tylerflint commented 7 years ago

@benspaulding That's not a problem, we can get the tests updated. Thanks for this!

benspaulding commented 2 years ago

Closing this to get it off my PR list. 😁