Skip to main content

Create a complete self contained virtualenv bootstrap file by enbed 'get-pip.py'

Project description

bootstrap_env

Experimental project to create a complete self contained virtualenv bootstrap file. See: packaging-problems issues 55

info

Since virtualenv v1.10 you a virtualenv bootstrap file is not runnable without the pip and setuptools wheel files. There must be created a virtualenv_support with the wheels.

e.g.:

/bootstrap.py
/virtualenv_support/
        pip-1.5.6-py2.py3-none-any.whl
        setuptools-3.6-py2.py3-none-any.whl

With this project this is not needed. The current solution embed get_pip.py into the bootstrap file and call it after env creation.

the example

The included example will create a boot_example.py bootstrap file. Running this looks like:

~ $ python2 boot_example.py ~/testenv
The additional example extend_parser() code is called.
The additional example adjust_options() code is called.
New python executable in /home/jens/testenv/bin/python2
Also creating executable in /home/jens/testenv/bin/python
call to install pip with: '/home/jens/testenv/bin/python /path/to/bootstrap_env/boot_example.py --install-pip /home/jens/testenv'
install pip from self contained 'get_pip.py'
Downloading/unpacking pip
  Downloading pip-1.5.6-py2.py3-none-any.whl (1.0MB): 1.0MB downloaded
Downloading/unpacking setuptools
  Downloading setuptools-6.0.2-py2.py3-none-any.whl (543kB): 543kB downloaded
Installing collected packages: pip, setuptools
Successfully installed pip setuptools
Cleaning up...
The additional example after_install() code is called.

The example hook code stored separated files in example directory looks like this:

def extend_parser(parser):
    # --- CUT here ---
    sys.stdout.write("The additional example extend_parser() code is called.\n")
def adjust_options(options, args):
    # --- CUT here ---
    sys.stdout.write("The additional example adjust_options() code is called.\n")
def after_install(options, home_dir):
    # --- CUT here ---
    sys.stdout.write("The additional example after_install() code is called.\n")

Creating the example bootstrap file looks like this:

/path/to/bootstrap_env/ $ python2 example.py
Generate bootstrap file: 'boot_example.py'...
Reade code from: 'example/extend_parser.py'...
Reade code from: 'example/adjust_options.py'...
Reade code from: 'example/after_install.py'...
Reade code from: '/path/to/bootstrap_env/bootstrap_env/bootstrap_install_pip.py'...
Request: 'https://raw.githubusercontent.com/pypa/pip/master/contrib/get-pip.py'...
get-pip.py SHA256: 'd43dc33a5670d69dd14a9be1f2b2fa27ebf124ec1b212a47425331040f742a9b', ok.
'boot_example.py' written.

After the first call, the requested get-pip.py file will be cached into the default temp and reused from there. So it is fast to generate it again:

/path/to/bootstrap_env/ $ python2 example.py
Generate bootstrap file: 'boot_example.py'...
Reade code from: 'example/extend_parser.py'...
Reade code from: 'example/adjust_options.py'...
Reade code from: 'example/after_install.py'...
Reade code from: '/path/to/bootstrap_env/bootstrap_env/bootstrap_install_pip.py'...
Use '/tmp/get-pip.py'
get-pip.py SHA256: 'd43dc33a5670d69dd14a9be1f2b2fa27ebf124ec1b212a47425331040f742a9b', ok.
'boot_example.py' written.

usage

To create you own bootstrap file, is easy. Just copy the example code and change it for your needs.

Another example are the bootstrap usage in PyLucid django-cms branch.

History

  • v0.3.1 - 14.11.2014 - Bugfix for “error: no such option:” while pip install, if own optional options are used.

  • v0.3.0 - 13.11.2014 - typo: rename all bootstrip to bootstrap ;)

  • v0.2.0 - 09.10.2014 - add prefix and suffix argument to generate_bootstrap()

  • v0.1.0 - 09.10.2014 - initial release

donation

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

bootstrap_env-0.3.1.tar.gz (19.9 kB view hashes)

Uploaded Source

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page