Download TEAM LinG - LinuxTone.Org

Transcript
Chapter 10
Run the following command to create a Python module distribution:
$ python setup.py sdist
running sdist
warning: sdist: missing required meta-data: url
warning: sdist: missing meta-data: either (author and author_email) or (maintainer
and maintainer_email) must be supplied
warning: sdist: manifest template ‘MANIFEST.in’ does not exist (using default file
list)
warning: sdist: standard file not found: should have one of README, README.txt
writing manifest file ‘MANIFEST’
creating meal-1.0
making hard links in meal-1.0...
hard linking meal.py -> meal-1.0
hard linking setup.py -> meal-1.0
creating dist
tar -cf dist/meal-1.0.tar meal-1.0
gzip -f9 dist/meal-1.0.tar
removing ‘meal-1.0’ (and everything under it)
How It Works
Notice all the complaints. The setup.py script was clearly not complete. It included enough to create
the distribution, but not enough to satisfy the Python conventions. When the setup.py script completes, you should see the following files in the current directory:
$ ls
MANIFEST
dist/
meal.py
setup.py
The setup.py script created the dist directory and the MANIFEST file. The dist directory contains one
file, a compressed version of our module:
$ ls dist
meal-1.0.tar.gz
You now have a one-file distribution of your module, which is kind of silly because the module itself
was just one file. The advantage of distutils is that your module will be properly installed.
You can then take the meal-1.0.tar.gz file to another system and install the module. First, uncompress and expand the bundle. On Linux, Unix, and Mac OS X, use the following commands:
$ gunzip meal-1.0.tar.gz
$ tar xvf meal-1.0.tar
meal-1.0/
meal-1.0/meal.py
meal-1.0/PKG-INFO
meal-1.0/setup.py
On Windows, use a compression program such as WinZip, which can handle the .tar.gz files.
You can install the module after it is expanded with the following command:
python setup.py install
172
TEAM LinG