Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 26 additions & 16 deletions source/tutorials/packaging-projects.rst
Original file line number Diff line number Diff line change
Expand Up @@ -128,25 +128,26 @@ an escape hatch when absolutely necessary.
# replace with your username:
name = example-pkg-YOUR-USERNAME-HERE
version = 0.0.1
url = https://github.com/pypa/sampleproject
author = Example Author
author_email = author@example.com
description = A small example package
long_description = file: README.md
long_description_content_type = text/markdown
url = https://github.com/pypa/sampleproject

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it may be useful to also mention project_urls demonstrating links to issues/docs/CI/etc

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was trying to exactly replicate the setup.py example with no changes; would be happy to add a follow-on PR that adds anything that would be useful to add to the example.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Personally, I didn't know about / start using project_urls until fairly recently, I don't I've even added it to the scikit-hep dev docs yet. But it is really nicely displayed in PyPI, so I think it's a good idea, even if not really minimal.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I think I've been using it for the last 3-4 years maybe...

classifiers =
Programming Language :: Python :: 3
License :: OSI Approved :: MIT License
Operating System :: OS Independent
description = A small example package
long_description = file: README.md
long_description_content_type = text/markdown

[options]
packages = find:
python_requires = >=3.6


There are a `variety of metadata and options
<https://setuptools.readthedocs.io/en/latest/userguide/declarative_config.html>`_
supported here. This is in configparser format; do not place quotes around values.
This example package uses a relatively minimal set of options:
This example package uses a relatively minimal set of metadata:

- ``name`` is the *distribution name* of your package. This can be any name as
long as only contains letters, numbers, ``_`` , and ``-``. It also must not
Expand All @@ -168,11 +169,6 @@ an escape hatch when absolutely necessary.
- ``url`` is the URL for the homepage of the project. For many projects, this
will just be a link to GitHub, GitLab, Bitbucket, or similar code hosting
service.
- ``packages`` is a list of all Python :term:`import packages <Import
Package>` that should be included in the :term:`Distribution Package`.
Instead of listing each package manually, we can use the ``find:`` directive
to automatically discover all packages and subpackages. In this case, the
list of packages will be ``example_pkg`` as that's the only package present.
- ``classifiers`` gives the index and :ref:`pip` some additional metadata
about your package. In this case, the package is only compatible with Python
3, is licensed under the MIT license, and is OS-independent. You should
Expand All @@ -181,6 +177,17 @@ an escape hatch when absolutely necessary.
your package will work on. For a complete list of classifiers, see
https://pypi.org/classifiers/.

In the options category, we have controls for setuptools itself:

- ``packages`` is a list of all Python :term:`import packages <Import
Package>` that should be included in the :term:`Distribution Package`.
Instead of listing each package manually, we can use the ``find:`` directive
to automatically discover all packages and subpackages. In this case, the
list of packages will be ``example_pkg`` as that's the only package present.
- ``python_requires`` gives the versions of Python supported by your
project. Installers like pip will look back though older versions of
packages until it finds one that has a matching Python version.

There are many more than the ones mentioned here. See
:doc:`/guides/distributing-packages-using-setuptools` for more details.

Expand Down Expand Up @@ -227,12 +234,12 @@ an escape hatch when absolutely necessary.
long_description=long_description,
long_description_content_type="text/markdown",
url="https://github.com/pypa/sampleproject",
packages=setuptools.find_packages(),
classifiers=[
"Programming Language :: Python :: 3",
"License :: OSI Approved :: MIT License",
"Operating System :: OS Independent",
],
packages=setuptools.find_packages(),
python_requires='>=3.6',
)

Expand All @@ -259,18 +266,21 @@ an escape hatch when absolutely necessary.
- ``url`` is the URL for the homepage of the project. For many projects, this
will just be a link to GitHub, GitLab, Bitbucket, or similar code hosting
service.
- ``packages`` is a list of all Python :term:`import packages <Import
Package>` that should be included in the :term:`Distribution Package`.
Instead of listing each package manually, we can use :func:`find_packages`
to automatically discover all packages and subpackages. In this case, the
list of packages will be ``example_pkg`` as that's the only package present.
- ``classifiers`` gives the index and :ref:`pip` some additional metadata
about your package. In this case, the package is only compatible with Python
3, is licensed under the MIT license, and is OS-independent. You should
always include at least which version(s) of Python your package works on,
which license your package is available under, and which operating systems
your package will work on. For a complete list of classifiers, see
https://pypi.org/classifiers/.
- ``packages`` is a list of all Python :term:`import packages <Import
Package>` that should be included in the :term:`Distribution Package`.
Instead of listing each package manually, we can use :func:`find_packages`
to automatically discover all packages and subpackages. In this case, the
list of packages will be ``example_pkg`` as that's the only package present.
- ``python_requires`` gives the versions of Python supported by your
project. Installers like pip will look back though older versions of
packages until it finds one that has a matching Python version.
Comment on lines +276 to +283

@webknjaz webknjaz Feb 6, 2021 •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would it be possible to deduplicate the copy-pasted explanations? Do you think using the .. include:: directive would help here, or maybe replace substitutions?

@henryiii henryiii Feb 6, 2021 •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Only some of them match; the "packages" description right above it, for example, does not match since it has a discussion of the find: directive in one case, and setuptools.find_packages() in the other.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you include from the same file? It might be fragile, though.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you can only "include" from the same file with substitutions. Including with "start+end" of itself with the include directive sounds a bit wild but I don't see why it wouldn't work (at least in cases when you don't include the place with the directive itself) 🤯


There are many more than the ones mentioned here. See
:doc:`/guides/distributing-packages-using-setuptools` for more details.
Expand Down