@@ -50,6 +50,7 @@ project's root directory - you will add content to them in the following steps.
5050 ├── example_pkg
5151 │ └── __init__.py
5252 ├── pyproject.toml
53+ ├── setup.cfg
5354 ├── setup.py
5455 └── tests
5556
@@ -93,82 +94,186 @@ always include it. If you were to use a different build system, such as
9394would be completely different than the setuptools configuration described
9495below. See :pep: `517 ` and :pep: `518 ` for background and details.
9596
96- Creating setup.py
97- -----------------
98-
99- :file: `setup.py ` is the build script for :ref: `setuptools `. It tells setuptools
100- about your package (such as the name and version) as well as which code files
101- to include.
102-
103- Open :file: `setup.py ` and enter the following content. Update the package name
104- to include your username (for example, ``example-pkg-theacodes ``), this ensures
105- that you have a unique package name and that your package doesn't conflict with
106- packages uploaded by other people following this tutorial.
107-
108- .. code-block :: python
109-
110- import setuptools
111-
112- with open (" README.md" , " r" , encoding = " utf-8" ) as fh:
113- long_description = fh.read()
114-
115- setuptools.setup(
116- name = " example-pkg-YOUR-USERNAME-HERE" , # Replace with your own username
117- version = " 0.0.1" ,
118- author = " Example Author" ,
119- author_email = " author@example.com" ,
120- description = " A small example package" ,
121- long_description = long_description,
122- long_description_content_type = " text/markdown" ,
123- url = " https://github.com/pypa/sampleproject" ,
124- packages = setuptools.find_packages(),
125- classifiers = [
126- " Programming Language :: Python :: 3" ,
127- " License :: OSI Approved :: MIT License" ,
128- " Operating System :: OS Independent" ,
129- ],
130- python_requires = ' >=3.6' ,
131- )
132-
133-
134- :func: `setup ` takes several arguments. This example package uses a relatively
135- minimal set:
136-
137- - ``name `` is the *distribution name * of your package. This can be any name as
138- long as only contains letters, numbers, ``_ `` , and ``- ``. It also must not
139- already be taken on pypi.org. **Be sure to update this with your username, **
140- as this ensures you won't try to upload a package with the same name as one
141- which already exists when you upload the package.
142- - ``version `` is the package version see :pep: `440 ` for more details on
143- versions.
144- - ``author `` and ``author_email `` are used to identify the author of the
145- package.
146- - ``description `` is a short, one-sentence summary of the package.
147- - ``long_description `` is a detailed description of the package. This is
148- shown on the package detail page on the Python Package Index. In
149- this case, the long description is loaded from :file: `README.md ` which is
150- a common pattern.
151- - ``long_description_content_type `` tells the index what type of markup is
152- used for the long description. In this case, it's Markdown.
153- - ``url `` is the URL for the homepage of the project. For many projects, this
154- will just be a link to GitHub, GitLab, Bitbucket, or similar code hosting
155- service.
156- - ``packages `` is a list of all Python :term: `import packages <Import
157- Package> ` that should be included in the :term: `Distribution Package `.
158- Instead of listing each package manually, we can use :func: `find_packages `
159- to automatically discover all packages and subpackages. In this case, the
160- list of packages will be ``example_pkg `` as that's the only package present.
161- - ``classifiers `` gives the index and :ref: `pip ` some additional metadata
162- about your package. In this case, the package is only compatible with Python
163- 3, is licensed under the MIT license, and is OS-independent. You should
164- always include at least which version(s) of Python your package works on,
165- which license your package is available under, and which operating systems
166- your package will work on. For a complete list of classifiers, see
167- https://pypi.org/classifiers/.
168-
169- There are many more than the ones mentioned here. See
170- :doc: `/guides/distributing-packages-using-setuptools ` for more details.
17197
98+ Configuring metadata
99+ --------------------
100+
101+ There are two types of metadata: static and dynamic.
102+
103+ * Static metadata (:file: `setup.cfg `): guaranteed to be the same every time. This is
104+ simpler, easier to read, and avoids many common errors, like encoding errors.
105+ * Dynamic metadata (:file: `setup.py `): possibly non-deterministic. Any items that are
106+ dynamic or determined at install-time, as well as extension modules or
107+ extensions to setuptools, need to go into :file: `setup.py `.
108+
109+ Static metadata should be preferred and dynamic metadata should be used only as
110+ an escape hatch when absolutely necessary.
111+
112+
113+ .. tab :: setup.cfg (static)
114+
115+ :file: `setup.cfg ` is the configuration file for :ref: `setuptools `. It tells
116+ setuptools about your package (such as the name and version) as well as which
117+ code files to include. Eventually much of this configuration may be able to move
118+ to :file: `pyproject.toml `.
119+
120+ Open :file: `setup.py ` and enter the following content. Update the package name
121+ to include your username (for example, ``example-pkg-theacodes ``), this ensures
122+ that you have a unique package name and that your package doesn't conflict with
123+ packages uploaded by other people following this tutorial.
124+
125+ .. code-block :: python
126+
127+ [metadata]
128+ # replace with your username:
129+ name = example- pkg- YOUR - USERNAME - HERE
130+ version = 0.0 .1
131+ url = https:// github.com/ pypa/ sampleproject
132+ author = Example Author
133+ author_email = author@ example.com
134+ classifiers =
135+ Programming Language :: Python :: 3
136+ License :: OSI Approved :: MIT License
137+ Operating System :: OS Independent
138+ description = A small example package
139+ long_description = file : README .md
140+ long_description_content_type = text/ markdown
141+
142+ [options]
143+ python_requires = >= 3.6
144+
145+
146+ There are a `variety of metadata and options
147+ <https://setuptools.readthedocs.io/en/latest/userguide/declarative_config.html> `_
148+ supported here. This is in configparser format; do not place quotes around values.
149+ This example package uses a relatively minimal set of options:
150+
151+ - ``name `` is the *distribution name * of your package. This can be any name as
152+ long as only contains letters, numbers, ``_ `` , and ``- ``. It also must not
153+ already be taken on pypi.org. **Be sure to update this with your username, **
154+ as this ensures you won't try to upload a package with the same name as one
155+ which already exists when you upload the package.
156+ - ``version `` is the package version see :pep: `440 ` for more details on
157+ versions. You can use ``file: `` or ``attr: `` directives to read from a file or
158+ package attribute (simple attributes do not require import).
159+ - ``author `` and ``author_email `` are used to identify the author of the
160+ package.
161+ - ``description `` is a short, one-sentence summary of the package.
162+ - ``long_description `` is a detailed description of the package. This is
163+ shown on the package detail page on the Python Package Index. In
164+ this case, the long description is loaded from :file: `README.md ` which is
165+ a common pattern, using the ``file: `` directive.
166+ - ``long_description_content_type `` tells the index what type of markup is
167+ used for the long description. In this case, it's Markdown.
168+ - ``url `` is the URL for the homepage of the project. For many projects, this
169+ will just be a link to GitHub, GitLab, Bitbucket, or similar code hosting
170+ service.
171+ - ``packages `` is a list of all Python :term: `import packages <Import
172+ Package> ` that should be included in the :term: `Distribution Package `.
173+ Instead of listing each package manually, we can use the ``find: `` directive
174+ to automatically discover all packages and subpackages. In this case, the
175+ list of packages will be ``example_pkg `` as that's the only package present.
176+ - ``classifiers `` gives the index and :ref: `pip ` some additional metadata
177+ about your package. In this case, the package is only compatible with Python
178+ 3, is licensed under the MIT license, and is OS-independent. You should
179+ always include at least which version(s) of Python your package works on,
180+ which license your package is available under, and which operating systems
181+ your package will work on. For a complete list of classifiers, see
182+ https://pypi.org/classifiers/.
183+
184+ There are many more than the ones mentioned here. See
185+ :doc: `/guides/distributing-packages-using-setuptools ` for more details.
186+
187+
188+ If you create a :file: `setup.py ` file, this will enable direct interaction
189+ with :file: `setup.py ` (which generally should be avoided), and editable
190+ installs. This file used to be required, but can be omitted in modern
191+ setuptools.
192+
193+ Anything you set in :file: `setup.cfg ` can instead be set via keyword argument to
194+ :func: `setup() `; this enables computed values to be used. You will also need
195+ :func: `setup() ` for setting up extension modules for compilation.
196+
197+ .. code-block :: python
198+
199+ import setuptools
200+
201+ setuptools.setup()
202+
203+ .. tab :: setup.py (dynamic)
204+
205+ :file: `setup.py ` is the build script for :ref: `setuptools `. It tells setuptools
206+ about your package (such as the name and version) as well as which code files
207+ to include.
208+
209+ Open :file: `setup.py ` and enter the following content. Update the package name
210+ to include your username (for example, ``example-pkg-theacodes ``), this ensures
211+ that you have a unique package name and that your package doesn't conflict with
212+ packages uploaded by other people following this tutorial.
213+
214+ .. code-block :: python
215+
216+ import setuptools
217+
218+ with open (" README.md" , " r" , encoding = " utf-8" ) as fh:
219+ long_description = fh.read()
220+
221+ setuptools.setup(
222+ name = " example-pkg-YOUR-USERNAME-HERE" , # Replace with your own username
223+ version = " 0.0.1" ,
224+ author = " Example Author" ,
225+ author_email = " author@example.com" ,
226+ description = " A small example package" ,
227+ long_description = long_description,
228+ long_description_content_type = " text/markdown" ,
229+ url = " https://github.com/pypa/sampleproject" ,
230+ packages = setuptools.find_packages(),
231+ classifiers = [
232+ " Programming Language :: Python :: 3" ,
233+ " License :: OSI Approved :: MIT License" ,
234+ " Operating System :: OS Independent" ,
235+ ],
236+ python_requires = ' >=3.6' ,
237+ )
238+
239+
240+ :func: `setup ` takes several arguments. This example package uses a relatively
241+ minimal set:
242+
243+ - ``name `` is the *distribution name * of your package. This can be any name as
244+ long as only contains letters, numbers, ``_ `` , and ``- ``. It also must not
245+ already be taken on pypi.org. **Be sure to update this with your username, **
246+ as this ensures you won't try to upload a package with the same name as one
247+ which already exists when you upload the package.
248+ - ``version `` is the package version see :pep: `440 ` for more details on
249+ versions.
250+ - ``author `` and ``author_email `` are used to identify the author of the
251+ package.
252+ - ``description `` is a short, one-sentence summary of the package.
253+ - ``long_description `` is a detailed description of the package. This is
254+ shown on the package detail page on the Python Package Index. In
255+ this case, the long description is loaded from :file: `README.md ` which is
256+ a common pattern.
257+ - ``long_description_content_type `` tells the index what type of markup is
258+ used for the long description. In this case, it's Markdown.
259+ - ``url `` is the URL for the homepage of the project. For many projects, this
260+ will just be a link to GitHub, GitLab, Bitbucket, or similar code hosting
261+ service.
262+ - ``packages `` is a list of all Python :term: `import packages <Import
263+ Package> ` that should be included in the :term: `Distribution Package `.
264+ Instead of listing each package manually, we can use :func: `find_packages `
265+ to automatically discover all packages and subpackages. In this case, the
266+ list of packages will be ``example_pkg `` as that's the only package present.
267+ - ``classifiers `` gives the index and :ref: `pip ` some additional metadata
268+ about your package. In this case, the package is only compatible with Python
269+ 3, is licensed under the MIT license, and is OS-independent. You should
270+ always include at least which version(s) of Python your package works on,
271+ which license your package is available under, and which operating systems
272+ your package will work on. For a complete list of classifiers, see
273+ https://pypi.org/classifiers/.
274+
275+ There are many more than the ones mentioned here. See
276+ :doc: `/guides/distributing-packages-using-setuptools ` for more details.
172277
173278Creating README.md
174279------------------
0 commit comments