| 1 | <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> |
| 2 | <html> |
| 3 | <head> |
| 4 | <link rel="STYLESHEET" href="dist.css" type='text/css' /> |
| 5 | <link rel="SHORTCUT ICON" href="../icons/pyfav.png" type="image/png" /> |
| 6 | <link rel='start' href='../index.html' title='Python Documentation Index' /> |
| 7 | <link rel="first" href="dist.html" title='Distributing Python Modules' /> |
| 8 | <link rel='index' href='genindex.html' title='Index' /> |
| 9 | <link rel='last' href='about.html' title='About this document...' /> |
| 10 | <link rel='help' href='about.html' title='About this document...' /> |
| 11 | <link rel="prev" href="extending.html" /> |
| 12 | <link rel="parent" href="extending.html" /> |
| 13 | <link rel="next" href="reference.html" /> |
| 14 | <meta name='aesop' content='information' /> |
| 15 | <title>8.1 Integrating new commands</title> |
| 16 | </head> |
| 17 | <body> |
| 18 | <DIV CLASS="navigation"> |
| 19 | <div id='top-navigation-panel' xml:id='top-navigation-panel'> |
| 20 | <table align="center" width="100%" cellpadding="0" cellspacing="2"> |
| 21 | <tr> |
| 22 | <td class='online-navigation'><a rel="prev" title="8. Extending Distutils" |
| 23 | href="extending.html"><img src='../icons/previous.png' |
| 24 | border='0' height='32' alt='Previous Page' width='32' /></A></td> |
| 25 | <td class='online-navigation'><a rel="parent" title="8. Extending Distutils" |
| 26 | href="extending.html"><img src='../icons/up.png' |
| 27 | border='0' height='32' alt='Up One Level' width='32' /></A></td> |
| 28 | <td class='online-navigation'><a rel="next" title="9. Command Reference" |
| 29 | href="reference.html"><img src='../icons/next.png' |
| 30 | border='0' height='32' alt='Next Page' width='32' /></A></td> |
| 31 | <td align="center" width="100%">Distributing Python Modules</td> |
| 32 | <td class='online-navigation'><img src='../icons/blank.png' |
| 33 | border='0' height='32' alt='' width='32' /></td> |
| 34 | <td class='online-navigation'><a href="modindex.html" title="Module Index"><img src='../icons/modules.png' |
| 35 | border='0' height='32' alt='Module Index' width='32' /></a></td> |
| 36 | <td class='online-navigation'><a rel="index" title="Index" |
| 37 | href="genindex.html"><img src='../icons/index.png' |
| 38 | border='0' height='32' alt='Index' width='32' /></A></td> |
| 39 | </tr></table> |
| 40 | <div class='online-navigation'> |
| 41 | <b class="navlabel">Previous:</b> |
| 42 | <a class="sectref" rel="prev" href="extending.html">8. Extending Distutils</A> |
| 43 | <b class="navlabel">Up:</b> |
| 44 | <a class="sectref" rel="parent" href="extending.html">8. Extending Distutils</A> |
| 45 | <b class="navlabel">Next:</b> |
| 46 | <a class="sectref" rel="next" href="reference.html">9. Command Reference</A> |
| 47 | </div> |
| 48 | <hr /></div> |
| 49 | </DIV> |
| 50 | <!--End of Navigation Panel--> |
| 51 | |
| 52 | <H1><A NAME="SECTION008100000000000000000"> |
| 53 | 8.1 Integrating new commands</A> |
| 54 | </H1> |
| 55 | |
| 56 | <P> |
| 57 | There are different ways to integrate new command implementations into |
| 58 | distutils. The most difficult is to lobby for the inclusion of the |
| 59 | new features in distutils itself, and wait for (and require) a version |
| 60 | of Python that provides that support. This is really hard for many |
| 61 | reasons. |
| 62 | |
| 63 | <P> |
| 64 | The most common, and possibly the most reasonable for most needs, is |
| 65 | to include the new implementations with your <span class="file">setup.py</span> script, |
| 66 | and cause the <tt class="function">distutils.core.setup()</tt> function use them: |
| 67 | |
| 68 | <P> |
| 69 | <div class="verbatim"><pre> |
| 70 | from distutils.command.build_py import build_py as _build_py |
| 71 | from distutils.core import setup |
| 72 | |
| 73 | class build_py(_build_py): |
| 74 | """Specialized Python source builder.""" |
| 75 | |
| 76 | # implement whatever needs to be different... |
| 77 | |
| 78 | setup(cmdclass={'build_py': build_py}, |
| 79 | ...) |
| 80 | </pre></div> |
| 81 | |
| 82 | <P> |
| 83 | This approach is most valuable if the new implementations must be used |
| 84 | to use a particular package, as everyone interested in the package |
| 85 | will need to have the new command implementation. |
| 86 | |
| 87 | <P> |
| 88 | Beginning with Python 2.4, a third option is available, intended to |
| 89 | allow new commands to be added which can support existing |
| 90 | <span class="file">setup.py</span> scripts without requiring modifications to the Python |
| 91 | installation. This is expected to allow third-party extensions to |
| 92 | provide support for additional packaging systems, but the commands can |
| 93 | be used for anything distutils commands can be used for. A new |
| 94 | configuration option, <span class="du-option">command_packages</span> (command-line option |
| 95 | <b class="programopt">--command-packages</b>), can be used to specify additional |
| 96 | packages to be searched for modules implementing commands. Like all |
| 97 | distutils options, this can be specified on the command line or in a |
| 98 | configuration file. This option can only be set in the |
| 99 | <code>[global]</code> section of a configuration file, or before any |
| 100 | commands on the command line. If set in a configuration file, it can |
| 101 | be overridden from the command line; setting it to an empty string on |
| 102 | the command line causes the default to be used. This should never be |
| 103 | set in a configuration file provided with a package. |
| 104 | |
| 105 | <P> |
| 106 | This new option can be used to add any number of packages to the list |
| 107 | of packages searched for command implementations; multiple package |
| 108 | names should be separated by commas. When not specified, the search |
| 109 | is only performed in the <tt class="module">distutils.command</tt> package. When |
| 110 | <span class="file">setup.py</span> is run with the option |
| 111 | <b class="programopt">--command-packages</b> <b class="programopt">distcmds,buildcmds</b>, |
| 112 | however, the packages <tt class="module">distutils.command</tt>, <tt class="module">distcmds</tt>, |
| 113 | and <tt class="module">buildcmds</tt> will be searched in that order. New commands |
| 114 | are expected to be implemented in modules of the same name as the |
| 115 | command by classes sharing the same name. Given the example command |
| 116 | line option above, the command <code class="du-command">bdist_openpkg</code> could be |
| 117 | implemented by the class <tt class="class">distcmds.bdist_openpkg.bdist_openpkg</tt> |
| 118 | or <tt class="class">buildcmds.bdist_openpkg.bdist_openpkg</tt>. |
| 119 | |
| 120 | <P> |
| 121 | |
| 122 | <DIV CLASS="navigation"> |
| 123 | <div class='online-navigation'> |
| 124 | <p></p><hr /> |
| 125 | <table align="center" width="100%" cellpadding="0" cellspacing="2"> |
| 126 | <tr> |
| 127 | <td class='online-navigation'><a rel="prev" title="8. Extending Distutils" |
| 128 | href="extending.html"><img src='../icons/previous.png' |
| 129 | border='0' height='32' alt='Previous Page' width='32' /></A></td> |
| 130 | <td class='online-navigation'><a rel="parent" title="8. Extending Distutils" |
| 131 | href="extending.html"><img src='../icons/up.png' |
| 132 | border='0' height='32' alt='Up One Level' width='32' /></A></td> |
| 133 | <td class='online-navigation'><a rel="next" title="9. Command Reference" |
| 134 | href="reference.html"><img src='../icons/next.png' |
| 135 | border='0' height='32' alt='Next Page' width='32' /></A></td> |
| 136 | <td align="center" width="100%">Distributing Python Modules</td> |
| 137 | <td class='online-navigation'><img src='../icons/blank.png' |
| 138 | border='0' height='32' alt='' width='32' /></td> |
| 139 | <td class='online-navigation'><a href="modindex.html" title="Module Index"><img src='../icons/modules.png' |
| 140 | border='0' height='32' alt='Module Index' width='32' /></a></td> |
| 141 | <td class='online-navigation'><a rel="index" title="Index" |
| 142 | href="genindex.html"><img src='../icons/index.png' |
| 143 | border='0' height='32' alt='Index' width='32' /></A></td> |
| 144 | </tr></table> |
| 145 | <div class='online-navigation'> |
| 146 | <b class="navlabel">Previous:</b> |
| 147 | <a class="sectref" rel="prev" href="extending.html">8. Extending Distutils</A> |
| 148 | <b class="navlabel">Up:</b> |
| 149 | <a class="sectref" rel="parent" href="extending.html">8. Extending Distutils</A> |
| 150 | <b class="navlabel">Next:</b> |
| 151 | <a class="sectref" rel="next" href="reference.html">9. Command Reference</A> |
| 152 | </div> |
| 153 | </div> |
| 154 | <hr /> |
| 155 | <span class="release-info">Release 2.4.2, documentation updated on 28 September 2005.</span> |
| 156 | </DIV> |
| 157 | <!--End of Navigation Panel--> |
| 158 | <ADDRESS> |
| 159 | See <i><a href="about.html">About this document...</a></i> for information on suggesting changes. |
| 160 | </ADDRESS> |
| 161 | </BODY> |
| 162 | </HTML> |