Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bundle Python, create virtual environment and install datasette on startup #25

Closed
simonw opened this issue Aug 31, 2021 · 5 comments
Closed
Labels
ci electron-wrapper Features that go in the Node.js/Electron code packaging Anything involving making stuff installable

Comments

@simonw
Copy link
Owner

simonw commented Aug 31, 2021

  1. Bundle a copy of standalone python inside the application folder itself
  2. On the first start up, create a virtual environment in ~/.datasette.app/venv using python -m venv with that bundles Python
  3. Run bin/pip install datasette in that virtual environment

Originally posted by @simonw in #22 (comment)

@simonw simonw added ci electron-wrapper Features that go in the Node.js/Electron code packaging Anything involving making stuff installable labels Aug 31, 2021
@simonw simonw added this to the First public installer release milestone Aug 31, 2021
@simonw
Copy link
Owner Author

simonw commented Aug 31, 2021

I built a prototype of this using https://github.com/indygreg/python-build-standalone/releases/tag/20210724 and it worked surprisingly well!

The key challenge I am solving here relates to plugins, see #5. In order to install plugins I need to have a full Python environment with the entire standard library, in case any future plugins need to use that.

I need to be able to run pip install successfully. I need a Python installation that I can trust has everything I need, and that is completely independent from anything else the user may have already installed on their machine.

So... I'm going to try bundling a full standalone Python from https://github.com/indygreg/python-build-standalone in the Datasette.app application that I distribute. On startup, this will be used to create a virtual environment in ~/.datasette-app/venv which will then be used to install both Datasette and the datasette-app-support plugin.

This will then be launched by Electron.

Is this a good idea? I honestly don't know, but I'm going to get a working version of it up and see what people think.

@simonw
Copy link
Owner Author

simonw commented Aug 31, 2021

https://pypi.org/project/datasette-app-support/ is now on PyPI.

@simonw
Copy link
Owner Author

simonw commented Aug 31, 2021

In development mode this expects there to be a python folder inside datasette-app with the standalone Python bundle unzipped into it.

This works:

wget https://github.com/indygreg/python-build-standalone/releases/download/20210724/cpython-3.9.6-x86_64-apple-darwin-install_only-20210724T1424.tar.gz
tar -xzvf cpython-3.9.6-x86_64-apple-darwin-install_only-20210724T1424.tar.gz                                                                          
# Now delete the test/ folder, saving about 22MB of disk space
rm -rf python/lib/python3.9/test

@simonw
Copy link
Owner Author

simonw commented Aug 31, 2021

Switching to a PR.

@simonw
Copy link
Owner Author

simonw commented Aug 31, 2021

It totally worked!

I downloaded the artifact from https://github.com/simonw/datasette-app/actions/runs/1188102495 and installed the application from the DMG (to /Applications/Datasette.app) - then I ran it and it told me I couldn't because it wasn't signed.

So I went to Security & Privacy in the system preferences and clicked "open it anyway"... and it launched and installed everything it needed into ~/.datasette-app/venv and the application worked!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
ci electron-wrapper Features that go in the Node.js/Electron code packaging Anything involving making stuff installable
Projects
None yet
Development

No branches or pull requests

1 participant