I’ve been learning python this summer (more on that later), and one thing that is a challenge for me was packaging my first library and shipping it to PyPi, the online repository for python modules.
First, set up your directories:
mkdir fair_flow/
mkdir fair_flow/fair_flow
cd fair_flow
touch __init__.py
sudo apt-get install python-pip python-setuptools
vi setup.py and put this in it
import setuptools
with open(“README.md”, “r”) as fh:
long_description = fh.read()
setuptools.setup(
name=”fair_flow”,
version=”0.0.1″,
author=”Joe Fair”,
author_email=”joe@fairanswers.com”,
description=”Simple Workflow Library”,
url=”https://fairanswers.com”,
packages=setuptools.find_packages(),
classifiers=[
“Programming Language :: Python :: 2”,
“License :: OSI Approved :: MIT License”,
“Operating System :: OS Independent”,
],
)
In the fair_flow/fair_flow/__init__.py put something simple, for testing ou tthe functionality.
name = "fair_flow" def doit(): return "Did It" Install it locally pip install . Test it from the command line python -c 'import fair_flow; print fair_flow.doit()' Once you're ready, you can upload it to Pypi. First, create your account on PyPi and install twine with pip install twine Build the distribution python setup.py sdist And upload it twine upload python -c 'import fair_flow; print fair_flow.doit()'
Then you can see it on Pypi
https://pypi.org/project/fair-flow/
Thanks for hints and tips from:
- https://python-packaging.readthedocs.io/en/latest/minimal.html
- https://packaging.python.org/tutorials/packaging-projects/