Skip to content

Instantly share code, notes, and snippets.

@NearHuscarl
Last active December 12, 2018 00:59
Show Gist options
  • Save NearHuscarl/90aa951dc970e8a6bd0ceba3d6846c14 to your computer and use it in GitHub Desktop.
Save NearHuscarl/90aa951dc970e8a6bd0ceba3d6846c14 to your computer and use it in GitHub Desktop.
how to upload python package to pypi and host on github

Requirements

  • python
  • detox (pip)
  • pyenv (AUR)
  • virtualenvwrapper (pacman)
  • setuptools (optional)
  • pandoc (pacman)
  • twine (pacman)

Setup

  • Install multiple python version for testing by using pyenv
  • Create ~/.pypirc
[distutils]
index-servers =
  pypi
  pypitest

[pypi]
repository: https://upload.pypi.org/legacy/
username: NearHuscarl
password: <password>

[pypitest]
repository: https://testpypi.python.org/pypi
username: NearHuscarl
password: <password>

Packaging

  • Project structure
+ repo/
  * setup.cfg
  * setup.py
  * tox.ini
  * LICENSE.md
  * README.md
  + package/
    * __init__.py
    * module1.py
    * module2.py
    + test/
      * test_1.py
      ...
  • Use pandoc convert from README.md to README.rst

  • Reread document

  • Create setup.py like this

  • Generate package

$ python setup.py sdist bdist_wheel
  • pip install and check package
$ mktmpenv
$ pip install dist/*.whl
$ # do stuff
$ deactivate
  • Run test on multiple python versions
$ tox
  • Commit
$ git commit
  • Bump version patch minor or major
$ bumpversion patch
  • Upload package
$ twine upload dist/* -r pypitest
$ # check if everything works on test server
$ twine upload dist/*
  • Upload to github
git push --tags

Resources

http://blog.pinaxproject.com/2015/12/08/how-test-against-multiple-python-versions-parallel/

http://python-packaging.readthedocs.io/en/latest/metadata.html

https://www.codementor.io/arpitbhayani/host-your-python-package-using-github-on-pypi-du107t7ku

$ pip install detox

Install all the Pythons you want to test with that are in your tox.ini

$ pyenv install 2.7.10
$ pyenv install 3.2.6
$ pyenv install 3.3
$ pyenv install 3.3.0
$ pyenv install 3.4.0
$ pyenv install 3.5
$ pyenv install 3.6

Set all these to be global versions

$ pyenv global 2.7.10 3.2.6 3.3 3.3.0 3.4.0 3.5 3.6

Check if things work correctly

$ pyenv versions
[bumpversion]
current_version = 1.0.2
commit = True
tag = True
[bumpversion:file:setup.py]
[bumpversion:file:README.rst]
@markolofsen
Copy link

It's really easy if are you using special tool for publications.
It's works in your browser, without any special dependencies.

Try this library for that https://github.com/markolofsen/how_to_upload_package_to_pypi

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment