Figure 1: Data Flow within Distutils/Setuptools Usage
Slides:
Four-Part In-Depth Presentation Sequence (not presented in class)
- An Introduction to the Virtualenv Sandbox (.pdf, .txt)
- Distutils: Packaging, Metadata and Pushups (.pdf, .txt)
- SetupTools: Python Eggs, Dependencies and Plugins (.pdf, .txt)
- Buildout: Precision Assembly, Repeatability, Islands (.pdf, .txt)
Condensed Slide Set Used in Actual Tutorial
Exercises from Tutorial:
Installing Tools for the Class
$ cd /tmp
$ sudo python ez_setup.py
$ sudo easy_install virtualenv
$ sudo easy_install zc.buildout
Instantiating a Sandbox or Two
$ virtualenv pycon -or-
$ virtualenv --no-site-packages pycon
$ cd pycon
$ bin/python
$ source bin/activate -or- activate.bat
$ deactivate
- explore:
- directory tree
- sys.path
- for each kind of sandbox
Processing Distributions
Grab a source distribution
$ /sandbox/bin/easy_install --editable --build-directory . SQLObject==0.9.5
$ /sandbox/bin/easy_install --editable --build-directory . SQLObject==dev
Examine its directory structure and common files.
Query the list of available distribution formats.
$ cd sqlobject
$ /sandbox/bin/python setup.py sdist --help-formats
$ /sandbox/bin/python setup.py bdist --help-formats
Build and package it as a binary distribution.
$ /sandbox/bin/python setup.py build
$ /sandbox/bin/python setup.py install
$ /sandbox/bin/python setup.py bdist --formats=tar,egg,rpm
Examine the run output and the table-of-contents of the distribution archive afterward. Note the way that metadata is stored.
Repackage it as a source distribution
$ /sandbox/bin/python setup.py sdist --formats=zip
Examine the run output and the table-of-contents of the source archive. Note the different way that metadata is stored.
Try to import it, then run the "develop" cmd and try again.
$ cd /sandbox
$ /sandbox/bin/python
$ import sqlobject
$ cd /sandbox/sqlobject
$ /sandbox/bin/python setup.py develop
Generating Scripts that Invokes Entrypoints
Create a sandbox in which to work.
$ virtualenv --no-site-packages pycon
$ cd pycon
Create a distribution for a new egg that has two scripts.
# File: pycon/setup.py
from setuptools import setup
setup(name="myscript",
version="1.0.0",
py_module = ['myscript'],
entry_points={
"console_scripts": [
"alpha = myscript:alpha_cmd",
"beta = myscript:beta_cmd"]
},
)
# File: pycon/myscript.py
def alpha_cmd():
print "Hello from Alpha Centauri"
class beta_cmd(object):
def __init__(self):
print "Hello from Beta Centauri"
Mark it a develop-egg and then add the egg as a 'myscript' part.
# File: pycon/buildout.cfg
[buildout]
develop = .
parts = myscript
[myscript]
recipe = zc.recipe.egg
eggs = myscript
- Run buildout and look in the bin/ directory for scripts.
Create a simple buildout around an egg and experiment with it.
Create an empty buildout area.
$ virtualenv --no-site-packages pycon
$ cd pycon
$ buildout init
Put into it a simple egg by creating a "buildout.cfg" file:
[buildout]
parts = mypython
prefer-final = true
[mypython]
recipe = zc.recipe.egg
interpreter = dbpython
eggs = SQLObject
Invoke "bin/buildout" and examine the output messages, the directory structure and the dbpython script.
Test for what version got installed and where it came from.
$ bin/dbpython
>>> import sqlobject
>>> sqlobject.__file__
'/var/tmp/buildout/eggs/SQLObject-0.10.0-py2.5.egg/sqlobject/__init__.py'
Force it to use a specific version of SQLObject.
Test for what version got installed and where it came from.
$ bin/dbpython
>>> import sqlobject
>>> sqlobject.__file__
'/var/tmp/buildout/eggs/SQLObject-0.9.0-py2.5.egg/sqlobject/__init__.py'
Remove that constraint and grab its source distribution.
$ bin/easy_install --editable -b . SQLObject
Alter "buildout.cfg" file to make it a development egg:
Test for what version got installed and where it came from.
$ bin/dbpython
>>> import sqlobject
>>> sqlobject.__file__
'/tmp/kkk/sqlobject/sqlobject/__init__.py'
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4