| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -11,7 +11,7 @@ A simple project | |||
| 11 | 11 | ||
| 12 | 12 | This tutorial uses a simple project named ``example_pkg``. If you are unfamiliar | |
| 13 | 13 | 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. | ||
| 15 | 15 | ||
| 16 | 16 | To create this project locally, create the following file structure: | |
| 17 | 17 | ||
@@ -29,7 +29,7 @@ You should also edit :file:`example_pkg/__init__.py` and put the following | |||
| 29 | 29 | code in there: | |
| 30 | 30 | ||
| 31 | 31 | .. code-block:: python | |
| 32 | - | ||
| 32 | + | ||
| 33 | 33 | name = "example_pkg" | |
| 34 | 34 | ||
| 35 | 35 | This is just so that you can verify that it installed correctly later in this | |
@@ -63,8 +63,7 @@ Creating setup.py | |||
| 63 | 63 | about your package (such as the name and version) as well as which code files | |
| 64 | 64 | to include. | |
| 65 | 65 | ||
| 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: | ||
| 68 | 67 | ||
| 69 | 68 | .. code-block:: python | |
| 70 | 69 | ||
@@ -74,7 +73,7 @@ the values if you want: | |||
| 74 | 73 | long_description = fh.read() | |
| 75 | 74 | ||
| 76 | 75 | setuptools.setup( | |
| 77 | - name="example_pkg", | ||
| 76 | + name="example-pkg-your-username", | ||
| 78 | 77 | version="0.0.1", | |
| 79 | 78 | author="Example Author", | |
| 80 | 79 | author_email="author@example.com", | |
@@ -94,9 +93,9 @@ the values if you want: | |||
| 94 | 93 | :func:`setup` takes several arguments. This example package uses a relatively | |
| 95 | 94 | minimal set: | |
| 96 | 95 | ||
| 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 | ||
| 98 | 97 | 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. | ||
| 100 | 99 | - ``version`` is the package version see :pep:`440` for more details on | |
| 101 | 100 | versions. | |
| 102 | 101 | - ``author`` and ``author_email`` are used to identify the author of the | |
@@ -112,7 +111,7 @@ minimal set: | |||
| 112 | 111 | will just be a link to GitHub, GitLab, Bitbucket, or similar code hosting | |
| 113 | 112 | service. | |
| 114 | 113 | - ``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`. | ||
| 116 | 115 | Instead of listing each package manually, we can use :func:`find_packages` | |
| 117 | 116 | to automatically discover all packages and subpackages. In this case, the | |
| 118 | 117 | list of packages will be `example_pkg` as that's the only package present. | |
@@ -207,8 +206,8 @@ files in the :file:`dist` directory: | |||
| 207 | 206 | .. code-block:: text | |
| 208 | 207 | ||
| 209 | 208 | 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 | ||
| 212 | 211 | ||
| 213 | 212 | .. note:: If you run into trouble here, please copy the output and file an issue | |
| 214 | 213 | 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: | |||
| 259 | 258 | Uploading distributions to https://test.pypi.org/legacy/ | |
| 260 | 259 | Enter your username: [your username] | |
| 261 | 260 | 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 | ||
| 263 | 262 | 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 | ||
| 265 | 264 | 100%|█████████████████████| 4.25k/4.25k [00:01<00:00, 3.05kB/s] | |
| 266 | 265 | ||
| 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 | - | ||
| 274 | 266 | ||
| 275 | 267 | 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 | ||
| 277 | 269 | ||
| 278 | 270 | ||
| 279 | 271 | Installing your newly uploaded package | |
@@ -285,20 +277,19 @@ detailed instructions) and install your package from TestPyPI: | |||
| 285 | 277 | ||
| 286 | 278 | .. code-block:: bash | |
| 287 | 279 | ||
| 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 | ||
| 289 | 281 | ||
| 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! | ||
| 292 | 283 | ||
| 293 | 284 | pip should install the package from Test PyPI and the output should look | |
| 294 | 285 | something like this: | |
| 295 | 286 | ||
| 296 | 287 | .. code-block:: text | |
| 297 | 288 | ||
| 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 | ||
| 302 | 293 | ||
| 303 | 294 | You can test that it was installed correctly by importing the module and | |
| 304 | 295 | 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): | |||
| 311 | 302 | ||
| 312 | 303 | And then import the module and print out the ``name`` property. This should be | |
| 313 | 304 | 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``. | ||
| 315 | 306 | ||
| 316 | 307 | .. code-block:: python | |
| 317 | 308 | ||
@@ -327,7 +318,7 @@ Next steps | |||
| 327 | 318 | ✨ 🍰 ✨ | |
| 328 | 319 | ||
| 329 | 320 | 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 | ||
| 331 | 322 | packages and accounts. If you want to upload your package to the real Python | |
| 332 | 323 | Package Index you can do it by registering an account on https://pypi.org and | |
| 333 | 324 | following the same instructions, however, use ``twine upload dist/*`` to upload | |
| Back | FazBrowse Home | New Git URL |
0 commit comments