📄 index.lxp@lxpwrap=x8418_252ehtm.htm
字号:
<table border="0" cellspacing="0" cellpadding="3" width="100%"><tr><td> <div align="center" id="bldcontent"> <a href="../default.htm"><img src="../images/opendocs.png" width="63" height="76" border="0"></a> <br> <div class="symbol">Your OpenSource Publisher™</div> </div> </td></tr></table> <div align="center" class="author"> <a href="../products.lxp">Products</a> | <a href="../wheretobuy.lxp">Where to buy</a> | <a href="../bookstore.lxp">Retailers</a> | <a href="../faq.lxp">FAQ</a> | <a href="../writeforus.lxp">Write for Us.</a> | <a href="#contact">Contact Us.</a> </div> <table border="0" cellspacing="3" cellpadding="0" width="100%"><tr><td width="100%"> <div class="content"> <table border="0" cellspacing="2" cellpadding="0" width="100%"><tr><td width="100%"> <div align="center"><H4 CLASS="AUTHOR"><A NAME="AEN5">Boudewijn Rempt</A><br><a href="../../https@secure.linuxports.com/opendocs/default.htm"><img src=odpyqt125.png></a><br>ISBN: 0-97003300-4-4<br><a href="../../https@secure.linuxports.com/opendocs/default.htm">Available from bookstores everywhere or you can order it here.</a><p>You can download the source files for the book <a href="pyqtsrc.tgz">(code / eps) here.</a><hr></div> <HTML><HEAD><TITLE>Starting with distutils.</TITLE><METANAME="GENERATOR"CONTENT="Modular DocBook HTML Stylesheet Version 1.72"><LINKREL="HOME"TITLE="GUI Programming with Python: QT Edition"HREF="book1.htm"><LINKREL="UP"TITLE="Delivering your Application"HREF="c8349.htm"><LINKREL="PREVIOUS"TITLE="Packaging source"HREF="x8401.htm"><LINKREL="NEXT"TITLE="Creating Unix RPM packages"HREF="x8580.htm"></HEAD><BODYCLASS="SECT1"BGCOLOR="#FFFFFF"TEXT="#000000"LINK="#0000FF"VLINK="#840084"ALINK="#0000FF"><DIVCLASS="NAVHEADER"><TABLESUMMARY="Header navigation table"WIDTH="100%"BORDER="0"CELLPADDING="0"CELLSPACING="0"><TR><THCOLSPAN="3"ALIGN="center">GUI Programming with Python: QT Edition</TH></TR><TR><TDWIDTH="10%"ALIGN="left"VALIGN="bottom"><A accesskey="P" href="index.lxp@lxpwrap=x8401_252ehtm.htm">Prev</A></TD><TDWIDTH="80%"ALIGN="center"VALIGN="bottom">Chapter 26. Delivering your Application</TD><TDWIDTH="10%"ALIGN="right"VALIGN="bottom"><A accesskey="N" href="index.lxp@lxpwrap=x8580_252ehtm.htm">Next</A></TD></TR></TABLE><HRALIGN="LEFT"WIDTH="100%"></DIV><DIVCLASS="SECT1"><H1CLASS="SECT1">Starting with distutils.</A></H1><P>Once you've collected all the bits and bobs for your application, you start using distutils by writing a special Python script, customarily named <TTCLASS="FILENAME">setup.py</TT>. You can make your <TTCLASS="FILENAME">setup.py</TT> script as complex as you want, but typically it is quite simple.</P><P>The <TTCLASS="FILENAME">setup.py</TT> script will then call <TTCLASS="FUNCTION">setup</TT> from <TTCLASS="FILENAME">distutils.core</TT> with lots of arguments, including meta-data about the application or module to install, and a list of stuff to install.</P><P>The developer uses the <TTCLASS="FILENAME">setup.py</TT> script to create the package, and the user uses it to install the package.</P><DIVCLASS="SECT2"><H2CLASS="SECT2">setup.py</A></H2><DIVCLASS="EXAMPLE"></A><P><B>Example 26-2. setup.py - a sample setup script</B></P><PRECLASS="PROGRAMLISTING">#!/usr/bin/env pythonfrom distutils.core import setupsetup(name = "kalam", version = "1.0", description = "Kalam - the extensible Python editor", author = "Boudewijn Rempt", author_email = "boud@rempt.xs4all.nl", url = "http://www.valdyas.org", packages = ["charmap", "kalamlib", "typometer", "workspace", ""], data_files = [("kalam/data", ["data/Blocks.txt"]), ("kalam/pixmaps", ["pixmaps/listspace.png", "pixmaps/splitspace.png", "pixmaps/stackspace.png", "pixmaps/tabmanager.png", "pixmaps/workspace.png"])], scripts = ["kalam","kalam.bat"], long_description = """Kalam is a plain-text editor. It is written in Python usingthe PyQt GUI toolkit as an example and tutorial for the bookGUI programming with Python and Qt, published by Opendocs.""" ) </PRE></DIV><P>The <TTCLASS="FILENAME">setup.py</TT> is the place to specify all executable parts of your application, and some metadata. Let's examine all parts:</P><P></P><UL><LI><P><TTCLASS="VARNAME">name</TT>: the name of the application</P></LI><LI><P><TTCLASS="VARNAME">version</TT>: the version number (major, minor, wee number)</P></LI><LI><P><TTCLASS="VARNAME">description</TT>: a short description of the application</P></LI><LI><P><TTCLASS="VARNAME">author</TT>: the person responsible for the application</P></LI><LI><P><TTCLASS="VARNAME">author_email</TT>: his email address</P></LI><LI><P><TTCLASS="VARNAME">url</TT>: website where the application is hosted</P></LI><LI><P><TTCLASS="VARNAME">packages</TT>: a list of Python modules (directories that contain a set of Python files listed in a <TTCLASS="FILENAME">__init__.py</TT> file). In the case of <SPANCLASS="APPLICATION">Kalam</SPAN> these are the modules for the character map, the type-o-meter and the set of workspace options. The additional module, kalamlib, contains all the real <SPANCLASS="APPLICATION">Kalam</SPAN> code.</P></LI><LI><P><TTCLASS="VARNAME">py_modules</TT>: a list of Python files. Note that if you include both the <TTCLASS="VARNAME">packages</TT> and the<TTCLASS="VARNAME">py_modules</TT> keyword only the latter will be used.</P></LI><LI><P><TTCLASS="VARNAME">data_files</TT>: this is a list of files that are not executable code. These files will be installed in a default place, like <TTCLASS="FILENAME">/usr/share</TT> on Linux. You must also include all these files in <TTCLASS="VARNAME">MANIFEST.in</TT>, otherwise they won't be packaged.</P></LI><LI><P><TTCLASS="VARNAME">scripts</TT>: this is a list of python script files. If you use #!/usr/bin/python as the first line of a script to make it executable on Unix, Distutils will change that to the location of Python on the user's machine.</P></LI><LI><P><TTCLASS="VARNAME">long_description</TT>: a longer description of the application. This is used when you create an rpm package.</P></LI></UL><P>There are other options more concerned with distributing C or C++ extension modules you have created. I don't cover them here.</P><P>Finally, a word of warning: if you are experimenting with <TTCLASS="FILENAME">setup.py</TT>, you will notice that a file called <TTCLASS="FILENAME">MANIFEST</TT> has been created. Always remove this file after creating a distribution. It is a kind of cache that lists the set of files that should be included; if you change this set, distutils will still read <TTCLASS="FILENAME">MANIFEST</TT> instead of your changes in <TTCLASS="FILENAME"
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -