my_python_package
cheatsheet and template for a python package
the result is a python package that can be installed using
pip install mypackage
and conda install mypackage
and has proper documentation and testing. For testing we use Travis CI and for the documentation we use readthedocs.
Pre-Requisites:
- Git and Github
- Python
- Basic command line
Python Package
follow this and this guide. Do not use sdist to upload your script. Use Twine for a secure way. Summary below:
Pypi
-
Install requirements
pip install wheel
pip install twine
-
Create an account on the PyPi website (verify email): https://pypi.org/account/register/
install-requires-vs-requirements
- Fork and clone this repository to your (virtual) machine.
- Rename folders to a newname that is unique to pypi and conda cloud.
- cd to repo (folder with setup.py)
- cp -r pypi_template pypi_template_built
- cp -r conda_template conda_template_built
- cd pypi_template_built/
- Create Source Distribution
python setup.py sdist
- Create the wheel
python setup.py bdist_wheel --universal
- Upload built package to pypi
twine upload dist/*
Conda
follow this guide. Summary below:
-
Install anaconda or miniconda
-
Install anaconda-client
conda install anaconda-client
-
Register at anaconda cloud
-
Login
anaconda login
-
cd to conda_template
-
Create conda skeleton (meta.yaml)
conda skeleton pypi pythonpackagetemplate
-
Build package
conda-build pythonpackagetemplate
anaconda upload /opt/anaconda3/conda-bld/linux-64/pythonpackagetemplate-0.1.5-py36_0.tar.bz2
To have conda build upload to anaconda.org automatically, use
$ conda config --set anaconda_upload yes
- Convert to other platforms
conda convert --platform all /opt/anaconda3/conda-bld/linux-64/pythonpackagetemplate-0.1.5-py36_0.tar.bz2 -o outputdir/