Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit b652897

Browse files
committed
Greatly enhanced the section on creating built distributions; in
particular wrote up creating RPMs in detail. Other scattered improvements.
1 parent 8d5b5ec commit b652897

1 file changed

Lines changed: 169 additions & 26 deletions

File tree

Doc/dist/dist.tex

Lines changed: 169 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
\usepackage{times}
44
\usepackage{distutils}
55

6+
% $Id$
7+
68
\title{Distributing Python Modules}
79

810
\author{Greg Ward}
@@ -714,8 +716,8 @@ \section{Creating a Source Distribution}
714716
\begin{description}
715717
\item[(1)] default on Windows
716718
\item[(2)] default on Unix
717-
\item[(3)] under both Unix and Windows, requires either external
718-
Info-ZIP utility \emph{or} the \module{zipfile} module
719+
\item[(3)] requires either external \program{zip} utility or
720+
\module{zipfile} module (not part of the standard Python library)
719721
\item[(4)] requires external utilities: \program{tar} and possibly one
720722
of \program{gzip}, \program{bzip2}, or \program{compress}
721723
\end{description}
@@ -884,7 +886,7 @@ \section{Creating Built Distributions}
884886
systems, it's a binary RPM; for Windows users, it's an executable
885887
installer; for Debian-based Linux users, it's a Debian package; and so
886888
forth. Obviously, no one person will be able to create built
887-
distributions for every platform under the sun, so the Distutils is
889+
distributions for every platform under the sun, so the Distutils are
888890
designed to enable module developers to concentrate on their
889891
specialty---writing code and creating source distributions---while an
890892
intermediary species of \emph{packager} springs up to turn source
@@ -908,25 +910,28 @@ \section{Creating Built Distributions}
908910
then the Distutils builds my module distribution (the Distutils itself
909911
in this case), does a ``fake'' installation (also in the \file{build}
910912
directory), and creates the default type of built distribution for my
911-
platform. Currently, the default format for built distributions is a
912-
``dumb'' archive---tarball on Unix, ZIP file on Windows. (These are
913-
called ``dumb'' built distributions, because they must be unpacked in a
914-
specific location to work.)
913+
platform. The default format for built distributions is a ``dumb'' tar
914+
file on Unix, and an simple executable installer on Windows. (That tar
915+
file is considered ``dumb'' because it has to be unpacked in a specific
916+
location to work.)
915917

916918
Thus, the above command on a Unix system creates
917919
\file{Distutils-0.9.1.\filevar{plat}.tar.gz}; unpacking this tarball
918-
from the root of the filesystemq installs the Distutils just as though
919-
you had downloaded the source distribution and run \code{python setup.py
920-
install}. (Assuming that the target system has their Python
921-
installation laid out the same as you do---another reason these are
922-
called ``dumb'' distributions.) Obviously, for pure Python
923-
distributions, this isn't a huge win---but for non-pure distributions,
924-
which include extensions that would need to be compiled, it can mean the
925-
difference between someone being able to use your extensions or not.
926-
927-
\XXX{filenames are inaccurate here!}
928-
929-
The \command{bdist} command has a \longprogramopt{format} option,
920+
from the right place installs the Distutils just as though you had
921+
downloaded the source distribution and run \code{python setup.py
922+
install}. (The ``right place'' is either the root of the filesystem or
923+
Python's \filevar{prefix} directory, depending on the options given to
924+
the \command{bdist\_dumb} command; the default is to make dumb
925+
distributions relative to \filevar{prefix}.)
926+
927+
Obviously, for pure Python distributions, this isn't a huge win---but
928+
for non-pure distributions, which include extensions that would need to
929+
be compiled, it can mean the difference between someone being able to
930+
use your extensions or not. And creating ``smart'' built distributions,
931+
such as an RPM package or an executable installer for Windows, is a big
932+
win for users even if your distribution doesn't include any extensions.
933+
934+
The \command{bdist} command has a \longprogramopt{formats} option,
930935
similar to the \command{sdist} command, which you can use to select the
931936
types of built distribution to generate: for example,
932937
\begin{verbatim}
@@ -939,20 +944,27 @@ \section{Creating Built Distributions}
939944
The available formats for built distributions are:
940945
\begin{tableiii}{l|l|c}{code}%
941946
{Format}{Description}{Notes}
942-
\lineiii{zip}{zip file (\file{.zip})}{}
943-
\lineiii{gztar}{gzipped tar file (\file{.tar.gz})}{(1)}
944-
\lineiii{ztar}{compressed tar file (\file{.tar.Z})}{}
945-
\lineiii{tar}{tar file (\file{.tar})}{}
946-
\lineiii{rpm}{RPM}{}
947-
\lineiii{srpm}{source RPM}{\XXX{to do!}}
948-
\lineiii{wininst}{self-extracting ZIP file for Windows}{(2)}
947+
\lineiii{gztar}{gzipped tar file (\file{.tar.gz})}{(1),(3)}
948+
\lineiii{ztar}{compressed tar file (\file{.tar.Z})}{(3)}
949+
\lineiii{tar}{tar file (\file{.tar})}{(3)}
950+
\lineiii{zip}{zip file (\file{.zip})}{(4)}
951+
\lineiii{rpm}{RPM}{(5)}
952+
\lineiii{srpm}{source RPM}{(5) \XXX{to do!}}
953+
\lineiii{wininst}{self-extracting ZIP file for Windows}{(2),(6)}
949954
%\lineiii{wise}{Wise installer for Windows}{(3)}
950955
\end{tableiii}
951956

952957
\noindent Notes:
953958
\begin{description}
954959
\item[(1)] default on Unix
955960
\item[(2)] default on Windows \XXX{to-do!}
961+
\item[(3)] requires external utilities: \program{tar} and possibly one
962+
of \program{gzip}, \program{bzip2}, or \program{compress}
963+
\item[(4)] requires either external \program{zip} utility or
964+
\module{zipfile} module (not part of the standard Python library)
965+
\item[(5)] requires external \program{rpm} utility, version 3.0.4 or
966+
better (use \code{rpm --version} to find out which version you have)
967+
\item[(6)] \XXX{requirements for \command{bdist\_wininst}?}
956968
%\item[(3)] not implemented yet
957969
\end{description}
958970

@@ -973,6 +985,135 @@ \section{Creating Built Distributions}
973985
%\lineii{bdist\_wise}{wise}
974986
\end{tableii}
975987

988+
The following sections give details on the individual \command{bdist\_*}
989+
commands.
990+
991+
992+
\subsection{Creating dumb built distributions}
993+
\label{creating-dumb}
994+
995+
\XXX{Need to document absolute vs. prefix-relative packages here, but
996+
first I have to implement it!}
997+
998+
999+
\subsection{Creating RPM packages}
1000+
\label{creating-rpms}
1001+
1002+
The RPM format is used by many of popular Linux distributions, including
1003+
Red Hat, SuSE, and Mandrake. If one of these (or any of the other
1004+
RPM-based Linux distributions) is your usual environment, creating RPM
1005+
packages for other users of that same distribution is trivial.
1006+
Depending on the complexity of your module distribution and differences
1007+
between Linux distributions, you may also be able to create RPMs that
1008+
work on different RPM-based distributions.
1009+
1010+
The usual way to create an RPM of your module distribution is to run the
1011+
\command{bdist\_rpm} command:
1012+
\begin{verbatim}
1013+
python setup.py bdist_rpm
1014+
\end{verbatim}
1015+
or the \command{bdist} command with the \longprogramopt{format} option:
1016+
\begin{verbatim}
1017+
python setup.py bdist --formats=rpm
1018+
\end{verbatim}
1019+
The former allows you to specify RPM-specific options; the latter allows
1020+
you to easily specify multiple formats in one run. If you need to do
1021+
both, you can explicitly specify multiple \command{bdist\_*} commands
1022+
and their options:
1023+
\begin{verbatim}
1024+
python setup.py bdist_rpm --packager="John Doe <[email protected]>" \
1025+
bdist_wininst --target_version="2.0"
1026+
\end{verbatim}
1027+
1028+
Creating RPM packages is driven by a \file{.spec} file, much as using
1029+
the Distutils is driven by the setup script. To make your life easier,
1030+
the \command{bdist\_rpm} command normally creates a \file{.spec} file
1031+
based on the information you supply in the setup script, on the command
1032+
line, and in any Distutils configuration files. Various options and
1033+
section in the \file{.spec} file are derived from options in the setup
1034+
script as follows:
1035+
\begin{tableii}{l|l}{textrm}%
1036+
{RPM \file{.spec} file option or section}{Distutils setup script option}
1037+
\lineii{Name}{\option{name}}
1038+
\lineii{Summary (in preamble)}{\option{description}}
1039+
\lineii{Version}{\option{version}}
1040+
\lineii{Vendor}{\option{author} and \option{author\_email}, or \\&
1041+
\option{maintainer} and \option{maintainer\_email}}
1042+
\lineii{Copyright}{\option{licence}}
1043+
\lineii{Url}{\option{url}}
1044+
\lineii{\%description (section)}{\option{long\_description}}
1045+
\end{tableii}
1046+
1047+
Additionally, there many options in \file{.spec} files that don't have
1048+
corresponding options in the setup script. Most of these are handled
1049+
through options to the \command{bdist\_rpm} command as follows:
1050+
\begin{tableiii}{l|l|l}{textrm}%
1051+
{RPM \file{.spec} file option or section}%
1052+
{\command{bdist\_rpm} option}%
1053+
{default value}
1054+
\lineiii{Release}{\option{release}}{``1''}
1055+
\lineiii{Group}{\option{group}}{``Development/Libraries''}
1056+
\lineiii{Vendor}{\option{vendor}}{(see above)}
1057+
\lineiii{Packager}{packager}{(none)}
1058+
\lineiii{Provides}{provides}{(none)}
1059+
\lineiii{Requires}{requires}{(none)}
1060+
\lineiii{Conflicts}{conflicts}{(none)}
1061+
\lineiii{Obsoletes}{obsoletes}{(none)}
1062+
\lineiii{Distribution}{\option{distribution\_name}}{(none)}
1063+
\lineiii{BuildRequires}{\option{build\_requires}}{(none)}
1064+
\lineiii{Icon}{\option{icon}}{(none)}
1065+
\end{tableiii}
1066+
Obviously, supplying even a few of these options on the command-line
1067+
would be tedious and error-prone, so it's usually best to put them in
1068+
the setup configuration file, \file{setup.cfg}---see
1069+
section~\ref{setup-config}. If you distribute or package many Python
1070+
module distributions, you might want to put options that apply to all of
1071+
them in your personal Distutils configuration file
1072+
(\file{\textasciitilde/.pydistutils.cfg}).
1073+
1074+
There are three steps to building a binary RPM package, all of which are
1075+
handled automatically by the Distutils:
1076+
\begin{enumerate}
1077+
\item create a \file{.spec} file, which describes the package (analogous
1078+
to the Distutils setup script; in fact, much of the information in the
1079+
setup script winds up in the \file{.spec} file)
1080+
\item create the source RPM
1081+
\item create the ``binary'' RPM (which may or may not contain binary
1082+
code, depending on whether your module distribution contains Python
1083+
extensions)
1084+
\end{enumerate}
1085+
Normally, RPM bundles the last two steps together; when you use the
1086+
Distutils, all three steps are typically bundled together.
1087+
1088+
If you wish, you can separate these three steps. You can use the
1089+
\longprogramopt{spec-only} option to make \command{bdist\_rpm} just
1090+
create the \file{.spec} file and exit; in this case, the \file{.spec}
1091+
file will be written to the ``distribution directory''---normally
1092+
\file{dist/}, but customizable with the \longprogramopt{dist-dir}
1093+
option. (Normally, the \file{.spec} file winds up deep in the ``build
1094+
tree,'' in a temporary directory created by \command{bdist\_rpm}.)
1095+
1096+
\XXX{this isn't implemented yet---is it needed?!}
1097+
You can also specify a custom \file{.spec} file with the
1098+
\longprogramopt{spec-file} option; used in conjunctin with
1099+
\longprogramopt{spec-only}, this gives you an opportunity to customize
1100+
the \file{.spec} file manually:
1101+
\begin{verbatim}
1102+
> python setup.py bdist_rpm --spec-only
1103+
# ...edit dist/FooBar-1.0.spec
1104+
> python setup.py bdist_rpm --spec-file=dist/FooBar-1.0.spec
1105+
\end{verbatim}
1106+
(Although a better way to do this is probably to override the standard
1107+
\command{bdist\_rpm} command with one that writes whatever else you want
1108+
to the \file{.spec} file; see section~\ref{extending} for information on
1109+
extending the Distutils.)
1110+
1111+
1112+
\subsection{Creating Windows installers}
1113+
\label{creating-wininst}
1114+
1115+
1116+
9761117
\section{Examples}
9771118
\label{examples}
9781119

@@ -1059,6 +1200,7 @@ \subsection{Creating a source distribution: the \protect\command{sdist} command}
10591200

10601201

10611202
\XXX{fragment moved down from above: needs context!}
1203+
10621204
The manifest template commands are:
10631205
\begin{tableii}{ll}{command}{Command}{Description}
10641206
\lineii{include \var{pat1} \var{pat2} ... }
@@ -1085,6 +1227,7 @@ \subsection{Creating a source distribution: the \protect\command{sdist} command}
10851227
\code{a-f0-9\_.}). The definition of ``regular filename character'' is
10861228
platform-specific: on Unix it is anything except slash; on Windows
10871229
anything except backslash or colon; on Mac OS anything except colon.
1230+
10881231
\XXX{Windows and Mac OS support not there yet}
10891232

10901233

0 commit comments

Comments
 (0)