Skip to content

Commit 33a1782

Browse files
authored
Add username suffix to example package name in the packging tutorial (pypa#592)
Closes pypa#584
1 parent 4cda63d commit 33a1782

1 file changed

Lines changed: 20 additions & 29 deletions

File tree

source/tutorials/packaging-projects.rst

Lines changed: 20 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ A simple project
1111

1212
This tutorial uses a simple project named ``example_pkg``. If you are unfamiliar
1313
with Python's modules and :term:`import packages <import package>`, take a few
14-
minutes to read over the `Python documentation for packages and modules`_.
14+
minutes to read over the `Python documentation for packages and modules`_. Even if you already have a project that you want to package up, we recommend following this tutorial as-is using this example package and then trying with your own package.
1515

1616
To create this project locally, create the following file structure:
1717

@@ -29,7 +29,7 @@ You should also edit :file:`example_pkg/__init__.py` and put the following
2929
code in there:
3030

3131
.. code-block:: python
32-
32+
3333
name = "example_pkg"
3434
3535
This is just so that you can verify that it installed correctly later in this
@@ -63,8 +63,7 @@ Creating setup.py
6363
about your package (such as the name and version) as well as which code files
6464
to include.
6565

66-
Open :file:`setup.py` and enter the following content, you can personalize
67-
the values if you want:
66+
Open :file:`setup.py` and enter the following content. You **should** update the package name to include your username (for example, ``example-pkg-theacodes``. You can personalize the other values if you'd like:
6867

6968
.. code-block:: python
7069
@@ -74,7 +73,7 @@ the values if you want:
7473
long_description = fh.read()
7574
7675
setuptools.setup(
77-
name="example_pkg",
76+
name="example-pkg-your-username",
7877
version="0.0.1",
7978
author="Example Author",
8079
author_email="author@example.com",
@@ -94,9 +93,9 @@ the values if you want:
9493
:func:`setup` takes several arguments. This example package uses a relatively
9594
minimal set:
9695

97-
- ``name`` is the name of your package. This can be any name as long as only
96+
- ``name`` is the *distribution name* of your package. This can be any name as long as only
9897
contains letters, numbers, ``_`` , and ``-``. It also must not already
99-
taken on pypi.org.
98+
taken on pypi.org. **Be sure to update this with your username,** as this ensures you won't run into any name collisions when you upload the package.
10099
- ``version`` is the package version see :pep:`440` for more details on
101100
versions.
102101
- ``author`` and ``author_email`` are used to identify the author of the
@@ -112,7 +111,7 @@ minimal set:
112111
will just be a link to GitHub, GitLab, Bitbucket, or similar code hosting
113112
service.
114113
- ``packages`` is a list of all Python :term:`import packages <Import
115-
Package>` that should be included in the :term:`distribution package`.
114+
Package>` that should be included in the :term:`distribution package`.
116115
Instead of listing each package manually, we can use :func:`find_packages`
117116
to automatically discover all packages and subpackages. In this case, the
118117
list of packages will be `example_pkg` as that's the only package present.
@@ -207,8 +206,8 @@ files in the :file:`dist` directory:
207206
.. code-block:: text
208207
209208
dist/
210-
example_pkg-0.0.1-py3-none-any.whl
211-
example_pkg-0.0.1.tar.gz
209+
example_pkg_your_username-0.0.1-py3-none-any.whl
210+
example_pkg_your_username-0.0.1.tar.gz
212211
213212
.. note:: If you run into trouble here, please copy the output and file an issue
214213
over on `packaging problems`_ and we'll do our best to help you!
@@ -259,21 +258,14 @@ PyPI. After the command completes, you should see output similar to this:
259258
Uploading distributions to https://test.pypi.org/legacy/
260259
Enter your username: [your username]
261260
Enter your password:
262-
Uploading example_pkg-0.0.1-py3-none-any.whl
261+
Uploading example_pkg_your_username-0.0.1-py3-none-any.whl
263262
100%|█████████████████████| 4.65k/4.65k [00:01<00:00, 2.88kB/s]
264-
Uploading example_pkg-0.0.1.tar.gz
263+
Uploading example_pkg_your_username-0.0.1.tar.gz
265264
100%|█████████████████████| 4.25k/4.25k [00:01<00:00, 3.05kB/s]
266265
267-
.. note:: If you get an error that says ``The user '[your username]' isn't
268-
allowed to upload to project 'example-pkg'``, you'll need to go and pick
269-
a unique name for your package. A good choice is
270-
``example_pkg_your_username``. Update the ``name`` argument in
271-
:file:`setup.py`, remove the :file:`dist` folder, and
272-
:ref:`regenerate the archives <generating archives>`.
273-
274266
275267
Once uploaded your package should be viewable on TestPyPI, for example,
276-
https://test.pypi.org/project/example-pkg
268+
https://test.pypi.org/project/example-pkg-your-username
277269

278270

279271
Installing your newly uploaded package
@@ -285,20 +277,19 @@ detailed instructions) and install your package from TestPyPI:
285277

286278
.. code-block:: bash
287279
288-
python3 -m pip install --index-url https://test.pypi.org/simple/ example_pkg
280+
python3 -m pip install --index-url https://test.pypi.org/simple/ example-pkg-your-username
289281
290-
.. note:: If you used a different package name in the previous step, replace
291-
``example_pkg`` in the command above with your package name.
282+
Make sure to specify your username in the package name!
292283

293284
pip should install the package from Test PyPI and the output should look
294285
something like this:
295286

296287
.. code-block:: text
297288
298-
Collecting example_pkg
299-
Downloading https://test-files.pythonhosted.org/packages/.../example_pkg-0.0.1-py3-none-any.whl
300-
Installing collected packages: example-pkg
301-
Successfully installed example-pkg-0.0.1
289+
Collecting example-pkg-your-username
290+
Downloading https://test-files.pythonhosted.org/packages/.../example-pkg-your-username-0.0.1-py3-none-any.whl
291+
Installing collected packages: example-pkg-your-username
292+
Successfully installed example-pkg-your-username-0.0.1
302293
303294
You can test that it was installed correctly by importing the module and
304295
referencing the ``name`` property you put in :file:`__init__.py` earlier.
@@ -311,7 +302,7 @@ Run the Python interpreter (make sure you're still in your virtualenv):
311302
312303
And then import the module and print out the ``name`` property. This should be
313304
the same regardless of what you name you gave your :term:`distribution package`
314-
in :file:`setup.py` because your :term:`import package` is ``example_pkg``.
305+
in :file:`setup.py` (in this case, ``example-pkg-your-username``) because your :term:`import package` is ``example_pkg``.
315306

316307
.. code-block:: python
317308
@@ -327,7 +318,7 @@ Next steps
327318
✨ 🍰 ✨
328319

329320
Keep in mind that this tutorial showed you how to upload your package to Test
330-
PyPI, which isn't a permanent storage. The Test system occasionally deletes
321+
PyPI, which isn't a permanent storage. The Test system occasionally deletes
331322
packages and accounts. If you want to upload your package to the real Python
332323
Package Index you can do it by registering an account on https://pypi.org and
333324
following the same instructions, however, use ``twine upload dist/*`` to upload

0 commit comments

Comments
 (0)