1

I'm writing a small web app that I'd like to include the ability to download itself. The ideal solution would be for users to be able to "pip install" the full app but that users of the app would be able to download a version of it to use themselves (perhaps with reduced functionality or without some of the less essential dependencies).

I'm currently using Bottle as I'd like to keep everything as close to the standard library as possible. Users could be on different platforms or Python versions, which are other reasons for minimising the use of extra modules. (Though I'll assume 2.7 or 3.3 will be in use regardless of platform).

My current thinking is to have the app use __file__ or similar and zip itself up. It could also use setuptools/distribute and call sdist on itself. Users could then execute the zip file, or install the app using the source distribution. (ideally I'd like to provide both of these options).

The app would include aggressive import checking to fallback to available modules, with Bottle being the only requirement (and would be included in the downloaded file).

Can anyone think of a robust approach to providing this functionality?

Update: users of the app cannot be guaranteed to have internet access at all times, hence the requirement for being able to download a version of the app from someone who as previously installed it. Python experience cannot be assumed either, hence the idea of letting users run python -m myApp.zip to run their own version.

Update II: as the level of python experience also cannot be guaranteed I'd want the simplest way for a user to get a mostly working version of the app. Experienced users would then be free to 'upgrade' the app by installing their own choice of additional modules. The vast majority of these would be different servers to host the app from (CherryPy, Twisted, etc) and so would not strictly count as a dependency but a "nice to have".

Update III: based on the answer below I will look into a PyPI/buildout based solution but would still be interested in whether there is a specific solution to the above approach.

Lllama
  • 374
  • 1
  • 9

1 Answers1

3

Just package your app and put it on PyPI. Trying to automatically package the code running on the server seems over-engineered. Then you can let people use pip to install your app. In your app, provide a link to the PyPI page.

Then you can also add dependencies in the setup.py, and pip will install them for you. It seems like you are trying to build your own packaging infrastructure, but don't have to. Use what's out there.

Ned Batchelder
  • 364,293
  • 75
  • 561
  • 662
  • The issue will be that users of the app will often work in environments without internet access. While those with full access will be able to pip install from PyPI, I would like to have the ability for users to get a version as easily as possible if they do not have access to PyPI. – Lllama Feb 11 '13 at 17:38
  • If you build & deploy something to PyPi, PyPi is just hosting an sdist. Like Ned stated, you could just link to that sdist ( which you could host ) in addition to whatever dependencies. --- You can also make executables for Linux/Win/Mac . lots of answers on StackOverflow. start by reading this one... http://stackoverflow.com/questions/106725/how-to-bundle-a-python-application-including-dependencies-for-windows --- If you do want to include dependencies the common term for that is "bundling" (should help your searching). I think this project might work for you http://www.buildout.org – Jonathan Vanasco Feb 11 '13 at 17:52
  • If I could get the sdist to be included in the sdist that is downloaded from PyPI then I could serve that up from the app. I could also include the executables for the different platforms as well. Bundling could be an option as well (and give me an opportunity to learn buildout). – Lllama Feb 11 '13 at 18:07
  • I think I may go with a PyPI/buildout based solution but would be interested in whether there is an answer to the specific approach mentioned in the question. I'll leave this as unanswered as a result but thank you for the suggestions. – Lllama Feb 12 '13 at 11:33