16.01.2014 Views

Beginning Python - From Novice to Professional

Beginning Python - From Novice to Professional

Beginning Python - From Novice to Professional

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

374 CHAPTER 18 ■ PACKAGING YOUR PROGRAMS<br />

■Note The extra values you set here are used for several things. The name and version keywords, for<br />

example, are used for naming archive files, and the author and description keywords end up in a file<br />

called PKG-INFO in any archives you build.<br />

You don’t really have <strong>to</strong> supply all of this information in the setup function (you don’t<br />

actually have <strong>to</strong> supply any arguments at all), and you certainly can supply more (such as<br />

author_email or url). The names should be self-explana<strong>to</strong>ry. In the following sections, you’ll<br />

see what you can use this simple script for.<br />

Basic Installation<br />

Name your script setup.py (this is a universal convention for Distutils setup scripts), and make<br />

sure that you have a simple module called hello.py in the same direc<strong>to</strong>ry.<br />

■Caution The setup script will create new files and subdirec<strong>to</strong>ries in the current direc<strong>to</strong>ry when you run it,<br />

so you should probably experiment with it in a fresh direc<strong>to</strong>ry <strong>to</strong> avoid having old files being overwritten.<br />

Now execute the script, like this:<br />

python setup.py<br />

You should get some output like the following:<br />

usage: setup.py [global_opts] cmd1 [cmd1_opts] [cmd2 [cmd2_opts] ...]<br />

or: setup.py --help [cmd1 cmd2 ...]<br />

or: setup.py --help-commands<br />

or: setup.py cmd --help<br />

error: no commands supplied<br />

As you can see, you can get more information using the --help or --help-commands switches.<br />

Try <strong>to</strong> use the build command, just <strong>to</strong> see Distutils in action:<br />

python setup.py build<br />

You should now see output like the following:

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!