Contents
The Python setuptools package system and its "egg" repository is a easy way of distributing software. Individual packages can list other packages they depend on. At install time these dependencies are resolved, recovered and installed along with your package. All you have to do is create a setuptools friendly "setup.py" and upload into PyPi.
But what if you don't want to make your package public? This is a common case if you are a closed commercial project and don't wish to make the source code available. The answer is to create a private egg repository hosted on your own web server. This has a number of advantages:
- Your packages are only available to a restricted set of people.
- Public packages can still be listed as dependencies and fetched from elsewhere.
- You can copy public eggs into the private repository to cache them locally.
Having local copies of public packages also helps if the public site is temporarily unavailable. The basic set up process is quite straight forward:
1. Create a place on the file system to store eggs.2. Get a web server to share this out with basic authentication.
3. Copy eggs to the location on disk.
To access the private repository you use the EasyInstall find links option (-f).
1 |
easy_install -f http://<username:pass>@<my domain>/<egg basket> <my private package>
|
Create The Egg Store On the File System
I create a directory like "/opt/webdistrib" and change the owner and permissions so that Apache can access it.
1 |
sudo mkdir -p /opt/webdistrib
|
When you copy new egg files into this directory you will need to make sure Apache has permission to access it.
Apache Set Up
I use the Apache web server to host my own repository. Other web servers can be used however I'm not going to go into that here. You can add the following Alias and Directory commands into an existing configuration, modifying it for your needs.
1 |
# Allow the download of apps and other things from a shared web folder (basic auth protected).
|
This will set a URL like "http://<my domain dot com>/basket" for example. When a user goes to this address a basic authentication box will pop up. However before anyone can access it we must create the password file.
1 |
# Use -c only the first time the file is created!
|
Now restart Apache once the configuration passes all checks. You should be able to login an see the contents of the basket.
VirtualHost Example
The following is an example of a complete VirtualHost entry I use on my home server.
1 |
<VirtualHost 192.168.0.1:*>
|
Easy Install
To use easy_install to recover your private package you will need to use the find links (-f) flag. If you have password protected the URL you will also need to pass the username and password in the URL.
1 |
easy_install -f http://<username:pass>@<my domain>/<egg basket> <my private package>
|
Example setup.py
I thought it might be useful to also include a little section on making and developing python eggs. The following is a template setup.py file I use to make a package into an egg.
1 |
"""
|
Build and egg
Building an egg from the example setup.py is a straight forward task. You make the following call from the command line.
1 |
python setup.py bdist_egg
|
Developing your egg
If you wish to work on your egg, without having to build and install it each time, then you can use the following command.
1 |
python setup.py develop -f <auth details and address to your internal dependancies from>
|
This will 'install' your package into the site-packages using a special link file. Any third party or private dependencies will also be installed.