| 1 |
Controlling package uploads |
| 2 |
=========================== |
| 3 |
|
| 4 |
.. program:: flit publish |
| 5 |
|
| 6 |
The command ``flit publish`` will upload your package to a package index server. |
| 7 |
The default settings let you upload to `PyPI <https://pypi.org/>`_, |
| 8 |
the default Python Package Index, with a single user account. |
| 9 |
|
| 10 |
If you want to upload to other servers, or with more than one user account, |
| 11 |
or upload packages from a continuous integration job, |
| 12 |
you can configure Flit in two main ways: |
| 13 |
|
| 14 |
Using .pypirc |
| 15 |
------------- |
| 16 |
|
| 17 |
You can create or edit a config file in your home directory, ``~/.pypirc``, that |
| 18 |
will be used by default, or you can specify a custom location. |
| 19 |
This is also used by other Python tools such as `twine |
| 20 |
<https://pypi.python.org/pypi/twine>`_. |
| 21 |
|
| 22 |
For instance, to upload a package to the `Test PyPI server <https://test.pypi.org/>`_ |
| 23 |
instead of the normal PyPI, use a config file looking like this: |
| 24 |
|
| 25 |
.. code-block:: ini |
| 26 |
|
| 27 |
[distutils] |
| 28 |
index-servers = |
| 29 |
pypi |
| 30 |
testpypi |
| 31 |
|
| 32 |
[pypi] |
| 33 |
repository = https://upload.pypi.org/legacy/ |
| 34 |
username = sirrobin # Replace with your PyPI username |
| 35 |
|
| 36 |
[testpypi] |
| 37 |
repository = https://test.pypi.org/legacy/ |
| 38 |
username = sirrobin # Replace with your TestPyPI username |
| 39 |
|
| 40 |
You can select an index server from this config file with the |
| 41 |
:option:`--repository` option:: |
| 42 |
|
| 43 |
flit publish --repository testpypi |
| 44 |
|
| 45 |
If you don't use this option, |
| 46 |
Flit will use the server called ``pypi`` in the config file. If that doesn't |
| 47 |
exist, it uploads to PyPI at ``https://upload.pypi.org/legacy/`` by default. |
| 48 |
|
| 49 |
If you publish a package and you don't have a ``.pypirc`` file, Flit will create |
| 50 |
it to store your username. |
| 51 |
|
| 52 |
Flit tries to store your password securely using the |
| 53 |
`keyring <https://pypi.python.org/pypi/keyring>`_ library. |
| 54 |
If keyring is not installed, Flit will ask for your password for each upload. |
| 55 |
Alternatively, you can also manually add your password to the ``.pypirc`` file |
| 56 |
(``password = ...``) |
| 57 |
|
| 58 |
.. _upload_envvars: |
| 59 |
|
| 60 |
Using environment variables |
| 61 |
--------------------------- |
| 62 |
|
| 63 |
You can specify a server to upload to with :envvar:`FLIT_INDEX_URL`, and |
| 64 |
pass credentials with :envvar:`FLIT_USERNAME` and :envvar:`FLIT_PASSWORD`. |
| 65 |
Environment variables take precedence over the config file, except if you use |
| 66 |
the :option:`--repository` option to explicitly pick a server from the config file. |
| 67 |
|
| 68 |
This can make it easier to automate uploads, for example to release packages |
| 69 |
from a continuous integration job. |
| 70 |
|
| 71 |
.. warning:: |
| 72 |
|
| 73 |
Storing a password in an environment variable is convenient, but it's |
| 74 |
`easy to accidentally leak it <https://www.diogomonica.com/2017/03/27/why-you-shouldnt-use-env-variables-for-secret-data/>`_. |
| 75 |
Look out for scripts that helpfully print all environment variables for |
| 76 |
debugging, and remember that other scripts and libraries you run in |
| 77 |
that environment have access to your password. |