|
4 | 4 | Packaging and distributing projects |
5 | 5 | =================================== |
6 | 6 |
|
| 7 | +:Page Status: Outdated |
| 8 | +:Last Reviewed: 2023-12-14 |
| 9 | + |
7 | 10 | This section covers some additional details on configuring, packaging and |
8 | 11 | distributing Python projects with ``setuptools`` that aren't covered by the |
9 | 12 | introductory tutorial in :doc:`/tutorials/packaging-projects`. It still assumes |
@@ -153,206 +156,21 @@ As mentioned above, the primary feature of :file:`setup.py` is that it contains |
153 | 156 | a global ``setup()`` function. The keyword arguments to this function are how |
154 | 157 | specific details of your project are defined. |
155 | 158 |
|
156 | | -The most relevant arguments are explained below. Most of the snippets given are |
| 159 | +Some are temporarily explained below until their information is moved elsewhere. |
| 160 | +The full list can be found :doc:`in the setuptools documentation |
| 161 | +<setuptools:references/keywords>`. |
| 162 | + |
| 163 | +Most of the snippets given are |
157 | 164 | taken from the `setup.py |
158 | 165 | <https://github.com/pypa/sampleproject/blob/db5806e0a3204034c51b1c00dde7d5eb3fa2532e/setup.py>`_ contained in the |
159 | 166 | `PyPA sample project <https://github.com/pypa/sampleproject>`_. |
160 | 167 |
|
161 | 168 |
|
162 | | -.. _`setup() name`: |
163 | | - |
164 | | -``name`` |
165 | | -~~~~~~~~ |
166 | | - |
167 | | -:: |
168 | | - |
169 | | - name='sample', |
170 | | - |
171 | | -This is the name of your project, determining how your project is listed on |
172 | | -:term:`PyPI <Python Package Index (PyPI)>`. Per :pep:`508`, valid project |
173 | | -names must: |
174 | | - |
175 | | -- Consist only of ASCII letters, digits, underscores (``_``), hyphens (``-``), |
176 | | - and/or periods (``.``), and |
177 | | -- Start & end with an ASCII letter or digit. |
178 | | - |
179 | | -Comparison of project names is case insensitive and treats arbitrarily-long |
180 | | -runs of underscores, hyphens, and/or periods as equal. For example, if you |
181 | | -register a project named ``cool-stuff``, users will be able to download it or |
182 | | -declare a dependency on it using any of the following spellings:: |
183 | | - |
184 | | - Cool-Stuff |
185 | | - cool.stuff |
186 | | - COOL_STUFF |
187 | | - CoOl__-.-__sTuFF |
188 | | - |
189 | | - |
190 | | -``version`` |
191 | | -~~~~~~~~~~~ |
192 | | - |
193 | | -:: |
194 | | - |
195 | | - version='1.2.0', |
196 | | - |
197 | | -This is the current version of your project, allowing your users to determine whether or not |
198 | | -they have the latest version, and to indicate which specific versions they've tested their own |
199 | | -software against. |
200 | | - |
201 | | -Versions are displayed on :term:`PyPI <Python Package Index (PyPI)>` for each release if you |
202 | | -publish your project. |
203 | 169 |
|
204 | 170 | See :ref:`Choosing a versioning scheme` for more information on ways to use versions to convey |
205 | 171 | compatibility information to your users. |
206 | 172 |
|
207 | | -If the project code itself needs run-time access to the version, the simplest |
208 | | -way is to keep the version in both :file:`setup.py` and your code. If you'd |
209 | | -rather not duplicate the value, there are a few ways to manage this. See the |
210 | | -":ref:`Single sourcing the version`" Advanced Topics section. |
211 | | - |
212 | | -.. _`description`: |
213 | | - |
214 | | -``description`` |
215 | | -~~~~~~~~~~~~~~~ |
216 | | - |
217 | | -:: |
218 | | - |
219 | | - description='A sample Python project', |
220 | | - long_description=long_description, |
221 | | - long_description_content_type='text/x-rst', |
222 | | - |
223 | | -Give a short and long description for your project. |
224 | | - |
225 | | -These values will be displayed on :term:`PyPI <Python Package Index (PyPI)>` |
226 | | -if you publish your project. On ``pypi.org``, the user interface displays |
227 | | -``description`` in the grey banner and ``long_description`` in the section |
228 | | -named "Project Description". |
229 | | - |
230 | | -``description`` is also displayed in lists of projects. For example, it's |
231 | | -visible in the search results pages such as https://pypi.org/search/?q=jupyter, |
232 | | -the front-page lists of trending projects and new releases, and the list of |
233 | | -projects you maintain within your account profile (such as |
234 | | -https://pypi.org/user/jaraco/). |
235 | | - |
236 | | -A :ref:`content type <core-metadata-description-content-type>` |
237 | | -can be specified with the ``long_description_content_type`` argument, which can |
238 | | -be one of ``text/plain``, ``text/x-rst``, or ``text/markdown``, corresponding |
239 | | -to no formatting, `reStructuredText (reST) |
240 | | -<https://docutils.sourceforge.io/docs/ref/rst/restructuredtext.html#reference-names>`_, |
241 | | -and the GitHub-flavored Markdown dialect of `Markdown |
242 | | -<https://daringfireball.net/projects/markdown/>`_ respectively. |
243 | | - |
244 | | -``url`` |
245 | | -~~~~~~~ |
246 | | - |
247 | | -:: |
248 | | - |
249 | | - url='https://github.com/pypa/sampleproject', |
250 | | - |
251 | | - |
252 | | -Give a homepage URL for your project. |
253 | | - |
254 | | - |
255 | | -``author`` |
256 | | -~~~~~~~~~~ |
257 | | - |
258 | | -:: |
259 | | - |
260 | | - author='A. Random Developer', |
261 | | - author_email='author@example.com', |
262 | | - |
263 | | -Provide details about the author. |
264 | | - |
265 | | - |
266 | | -``license`` |
267 | | -~~~~~~~~~~~ |
268 | | - |
269 | | -:: |
270 | | - |
271 | | - license='MIT', |
272 | | - |
273 | | -The ``license`` argument doesn't have to indicate the license under |
274 | | -which your package is being released, although you may optionally do |
275 | | -so if you want. If you're using a standard, well-known license, then |
276 | | -your main indication can and should be via the ``classifiers`` |
277 | | -argument. Classifiers exist for all major open-source licenses. |
278 | | - |
279 | | -The ``license`` argument is more typically used to indicate differences |
280 | | -from well-known licenses, or to include your own, unique license. As a |
281 | | -general rule, it's a good idea to use a standard, well-known license, |
282 | | -both to avoid confusion and because some organizations avoid software |
283 | | -whose license is unapproved. |
284 | | - |
285 | | - |
286 | | -``classifiers`` |
287 | | -~~~~~~~~~~~~~~~ |
288 | | - |
289 | | -:: |
290 | | - |
291 | | - classifiers=[ |
292 | | - # How mature is this project? Common values are |
293 | | - # 3 - Alpha |
294 | | - # 4 - Beta |
295 | | - # 5 - Production/Stable |
296 | | - 'Development Status :: 3 - Alpha', |
297 | | - |
298 | | - # Indicate who your project is intended for |
299 | | - 'Intended Audience :: Developers', |
300 | | - 'Topic :: Software Development :: Build Tools', |
301 | | - |
302 | | - # Pick your license as you wish (should match "license" above) |
303 | | - 'License :: OSI Approved :: MIT License', |
304 | | - |
305 | | - # Specify the Python versions you support here. In particular, ensure |
306 | | - # that you indicate whether you support Python 2, Python 3 or both. |
307 | | - 'Programming Language :: Python :: 2', |
308 | | - 'Programming Language :: Python :: 2.7', |
309 | | - 'Programming Language :: Python :: 3', |
310 | | - 'Programming Language :: Python :: 3.6', |
311 | | - 'Programming Language :: Python :: 3.7', |
312 | | - 'Programming Language :: Python :: 3.8', |
313 | | - 'Programming Language :: Python :: 3.9', |
314 | | - ], |
315 | | - |
316 | | -Provide a list of classifiers that categorize your project. For a full listing, |
317 | | -see https://pypi.org/classifiers/. |
318 | | - |
319 | | -Although the list of classifiers is often used to declare what Python versions |
320 | | -a project supports, this information is only used for searching & browsing |
321 | | -projects on PyPI, not for installing projects. To actually restrict what |
322 | | -Python versions a project can be installed on, use the :ref:`python_requires` |
323 | | -argument. |
324 | | - |
325 | | -To prevent a package from being uploaded to PyPI, use the special |
326 | | -``'Private :: Do Not Upload'`` classifier. PyPI will always reject packages with |
327 | | -classifiers beginning with ``"Private ::'``. |
328 | | - |
329 | | - |
330 | | -``keywords`` |
331 | | -~~~~~~~~~~~~ |
332 | | - |
333 | | -:: |
334 | 173 |
|
335 | | - keywords='sample setuptools development', |
336 | | - |
337 | | -List keywords that describe your project. |
338 | | - |
339 | | - |
340 | | -``project_urls`` |
341 | | -~~~~~~~~~~~~~~~~ |
342 | | - |
343 | | -:: |
344 | | - |
345 | | - project_urls={ |
346 | | - 'Documentation': 'https://packaging.python.org/tutorials/distributing-packages/', |
347 | | - 'Funding': 'https://donate.pypi.org', |
348 | | - 'Say Thanks!': 'http://saythanks.io/to/example', |
349 | | - 'Source': 'https://github.com/pypa/sampleproject/', |
350 | | - 'Tracker': 'https://github.com/pypa/sampleproject/issues', |
351 | | - }, |
352 | | - |
353 | | -List additional relevant URLs about your project. This is the place to link to |
354 | | -bug trackers, source repositories, or where to support package development. |
355 | | -The string of the key is the exact text that will be displayed on PyPI. |
356 | 174 |
|
357 | 175 |
|
358 | 176 | ``packages`` |
@@ -396,38 +214,6 @@ specification that is used to install its dependencies. |
396 | 214 | For more on using "install_requires" see :ref:`install_requires vs Requirements files`. |
397 | 215 |
|
398 | 216 |
|
399 | | -.. _python_requires: |
400 | | - |
401 | | -``python_requires`` |
402 | | -~~~~~~~~~~~~~~~~~~~ |
403 | | - |
404 | | -If your project only runs on certain Python versions, setting the |
405 | | -``python_requires`` argument to the appropriate :pep:`440` version specifier |
406 | | -string will prevent :ref:`pip` from installing the project on other Python |
407 | | -versions. For example, if your package is for Python 3+ only, write:: |
408 | | - |
409 | | - python_requires='>=3', |
410 | | - |
411 | | -If your package is for Python 2.6, 2.7, and all versions of Python 3 starting |
412 | | -with 3.3, write:: |
413 | | - |
414 | | - python_requires='>=2.6, !=3.0.*, !=3.1.*, !=3.2.*', |
415 | | - |
416 | | -And so on. |
417 | | - |
418 | | -.. note:: |
419 | | - |
420 | | - Support for this feature is relatively recent. Your project's source |
421 | | - distributions and wheels (see :ref:`Packaging Your Project`) must be built |
422 | | - using at least version 24.2.0 of :ref:`setuptools` in order for the |
423 | | - ``python_requires`` argument to be recognized and the appropriate metadata |
424 | | - generated. |
425 | | - |
426 | | - In addition, only versions 9.0.0 and higher of :ref:`pip` recognize the |
427 | | - ``python_requires`` metadata. Users with earlier versions of pip will be |
428 | | - able to download & install projects on any Python version regardless of the |
429 | | - projects' ``python_requires`` values. |
430 | | - |
431 | 217 |
|
432 | 218 | .. _`Package Data`: |
433 | 219 |
|
@@ -500,47 +286,8 @@ keyword for pointing to pre-made scripts to install, the recommended approach to |
500 | 286 | achieve cross-platform compatibility is to use :ref:`console_scripts` entry |
501 | 287 | points (see below). |
502 | 288 |
|
503 | | -``entry_points`` |
504 | | -~~~~~~~~~~~~~~~~ |
505 | | - |
506 | | -:: |
507 | | - |
508 | | - entry_points={ |
509 | | - ... |
510 | | - }, |
511 | 289 |
|
512 | 290 |
|
513 | | -Use this keyword to specify any plugins that your project provides for any named |
514 | | -entry points that may be defined by your project or others that you depend on. |
515 | | - |
516 | | -For more information, see the section on |
517 | | -:ref:`Advertising Behavior <setuptools:dynamic discovery of services and plugins>` |
518 | | -from the :ref:`setuptools` docs. |
519 | | - |
520 | | -The most commonly used entry point is "console_scripts" (see below). |
521 | | - |
522 | | -.. _`console_scripts`: |
523 | | - |
524 | | -``console_scripts`` |
525 | | -******************* |
526 | | - |
527 | | -:: |
528 | | - |
529 | | - entry_points={ |
530 | | - 'console_scripts': [ |
531 | | - 'sample=sample:main', |
532 | | - ], |
533 | | - }, |
534 | | - |
535 | | -Use ``console_script`` |
536 | | -:ref:`entry points <setuptools:dynamic discovery of services and plugins>` |
537 | | -to register your script interfaces. You can then let the toolchain handle the |
538 | | -work of turning these interfaces into actual scripts [2]_. The scripts will be |
539 | | -generated during the install of your :term:`distribution <Distribution |
540 | | -Package>`. |
541 | | - |
542 | | -For more information, see :doc:`Entry Points <setuptools:userguide/entry_point>` |
543 | | -from the :doc:`setuptools docs <setuptools:index>`. |
544 | 291 |
|
545 | 292 | .. _`Choosing a versioning scheme`: |
546 | 293 |
|
@@ -956,10 +703,3 @@ your project to appear on the site. |
956 | 703 | access. :ref:`pip` is currently considering changing this by `making user |
957 | 704 | installs the default behavior |
958 | 705 | <https://github.com/pypa/pip/issues/1668>`_. |
959 | | -
|
960 | | -
|
961 | | -.. [2] Specifically, the "console_script" approach generates ``.exe`` files on |
962 | | - Windows, which are necessary because the OS special-cases ``.exe`` files. |
963 | | - Script-execution features like ``PATHEXT`` and the :pep:`Python Launcher for |
964 | | - Windows <397>` allow scripts to |
965 | | - be used in many cases, but not all. |
0 commit comments