Skip to content

Commit eb5be9c

Browse files
author
Jon Wayne Parrott
committed
Remove more references to setuptools, fix some notes, strongly recommend twine
1 parent c4c8214 commit eb5be9c

File tree

1 file changed

+32
-74
lines changed

1 file changed

+32
-74
lines changed

source/distributing.rst

Lines changed: 32 additions & 74 deletions
Original file line numberDiff line numberDiff line change
@@ -722,112 +722,70 @@ on. For details on the naming of wheel files, see :pep:`425`
722722
Uploading your Project to PyPI
723723
==============================
724724

725-
.. note::
725+
When you ran the command to create your distribution, a new directory ``dist/``
726+
was created under your project's root directory. That's where you'll find your
727+
distribution file(s) to upload.
726728

727-
Before releasing on main PyPI repo, you might prefer training with
729+
.. note:: Before releasing on main PyPI repo, you might prefer training with
728730
`PyPI test site <https://testpypi.python.org/pypi>`_
729731
which is cleaned on a semi regular basis. See
730732
`these instructions <https://wiki.python.org/moin/TestPyPI>`_ on how
731733
to setup your configuration in order to use it.
732734

733-
When you ran the command to create your distribution, a new directory dist/ was created under your project's root directory. That's where you'll find your distribution file(s) to upload.
735+
.. warning:: In other resources you may encounter references to using
736+
``python setup.py register`` and ``python setup.py upload``. These methods
737+
of registering and uploading a package are **strongly discouraged** as it may
738+
use a plaintext HTTP or unverified HTTPS connection on some Python versions,
739+
allowing your username and password to be intercepted during transmission.
734740

735741
Create an account
736742
-----------------
737743

738-
First, you need a :term:`PyPI <Python Package Index (PyPI)>` user
739-
account. There are two options:
740-
741-
1. Create an account manually `using the form on the PyPI website
742-
<https://pypi.python.org/pypi?%3Aaction=register_form>`_.
744+
First, you need a :term:`PyPI <Python Package Index (PyPI)>` user account. You
745+
can create an account
746+
`using the form on the PyPI website <https://pypi.python.org/pypi?%3Aaction=register_form>`_.
743747

744-
2. **(Not recommended):** Have an account created as part of
745-
registering your first project (not recommended due to the
746-
related security concerns, see option #3 below).
748+
.. Note:: If you want to avoid entering your username and password when
749+
uploading, you can create a ``~/.pypirc`` file with your username and
750+
password:
747751

748-
If you created your account using option #1 (the form), you'll need to manually
749-
write a ``~/.pypirc`` file like so.
750-
751-
::
752-
753-
[distutils]
754-
index-servers=pypi
752+
.. code-block:: text
755753
756754
[pypi]
757-
repository = https://upload.pypi.org/legacy/
758755
username = <username>
759756
password = <password>
760757
761-
You can leave out the password line if you use twine with its
762-
``-p PASSWORD`` argument or prefer to simply enter your password
763-
when prompted.
764-
765-
766-
Register your project
767-
---------------------
768-
769-
Next, if this is the first release, **unless you use twine**, you
770-
need to explicitly register your project prior to uploading. If you intend to
771-
upload your project using twine (see :ref:`Upload your distributions` below),
772-
you can skip this step, as twine will register and upload your project in one
773-
step.
774-
775-
There are two ways to do register manually:
776-
777-
1. Use `the form on the PyPI website
778-
<https://pypi.python.org/pypi?%3Aaction=submit_form>`_, to upload your
779-
``PKG-INFO`` info located in your local project tree at
780-
``myproject.egg-info/PKG-INFO``. If you don't have that file or directory,
781-
then run ``python setup.py egg_info`` to have it generated.
782-
2. **(Not recommended):** Run ``python setup.py register``. If you don't have
783-
a user account already, a wizard will create one for you. This approach is
784-
covered here due to it being mentioned in other guides, but it is not
785-
recommended as it may use a plaintext HTTP or unverified HTTPS connection
786-
on some Python versions, allowing your username and password to be intercepted
787-
during transmission.
788-
758+
**Be aware that this stores your password in plaintext.**
789759

790760
Upload your distributions
791761
-------------------------
792762

793-
Finally, you can upload your distributions to :term:`PyPI <Python Package Index
794-
(PyPI)>`.
763+
Once you have an account you can upload your distributions to
764+
:term:`PyPI <Python Package Index (PyPI)>` using :ref:`twine`. If this is
765+
your first time uploading a distribution for a new project, twine will handle
766+
registering the project.
795767

796-
There are two options:
768+
.. code-block:: text
797769
798-
1. Use :ref:`twine`
770+
twine upload dist/*
799771
800-
::
801-
802-
twine upload dist/*
803772
804-
The biggest reason to use twine is that ``python setup.py upload`` (option #2
805-
below) uploads files over plaintext. This means anytime you use it you expose
806-
your username and password to a MITM attack. Twine uses only verified TLS to
807-
upload to PyPI in order to protect your credentials from theft.
773+
.. note:: Twine allows you to pre-sign your distribution files using gpg:
808774

809-
Secondly it allows you to precreate your distribution files. ``python
810-
setup.py upload`` only allows you to upload something that you've created in
811-
the same command invocation. This means that you cannot test the exact file
812-
you're going to upload to PyPI to ensure that it works before uploading it.
775+
.. code-block:: text
813776
814-
Finally it allows you to pre-sign your files and pass the .asc files into the
815-
command line invocation (``twine upload twine-1.0.1.tar.gz
816-
twine-1.0.1.tar.gz.asc``). This enables you to be assured that you're typing
817-
your gpg passphrase into gpg itself and not anything else since *you* will be
818-
the one directly executing ``gpg --detach-sign -a <filename>``.
777+
gpg --detach-sign -a dist/package-1.0.1.tar.gz
819778
779+
and pass the gpg-created .asc files into the command line invocation:
820780

821-
2. **(Not recommended):** Use :ref:`setuptools`:
781+
.. code-block:: text
822782
823-
::
783+
twine upload dist/package-1.0.1.tar.gz package-1.0.1.tar.gz.asc
824784
825-
python setup.py bdist_wheel sdist upload
785+
This enables you to be assured that you're only ever typing your gpg
786+
passphrase into gpg itself and not anything else since *you* will be
787+
the one directly executing the ``gpg`` command.
826788

827-
This approach is covered here due to it being mentioned in other guides, but it
828-
is not recommended as it may use a plaintext HTTP or unverified HTTPS connection
829-
on some Python versions, allowing your username and password to be intercepted
830-
during transmission.
831789

832790
----
833791

0 commit comments

Comments
 (0)