This is a no nonsense guide to making your Python project installable via pip.
You can check the Github repository for my project little-mallet-wrapper for an example of how to package your project.
Organize your project so that its file structure looks like this:
YOUR_PROJECT/
YOUR_PROJECT/
__init__.py
your_project.py
README.md
LICENSE
setup.py
LICENSE
should contain a copy of the license text you’ve chosen for your project.
README.md
should contain a description of your project and documentation of usage.
__init__.py
should import all of the functions that you want to expose to your users.
For example, here is the __init__.py
file for little-mallet-wrapper:
from .little_mallet_wrapper import (
process_string,
train_topic_model,
load_topic_keys,
load_topic_distributions,
plot_categories_by_topics_heatmap,
plot_categories_by_topic_boxplots,
divide_training_data,
infer_topics,
plot_topics_over_time
)
setup.py
should include all the specifications for your project.
For example, here is the setup.py
file for little-mallet-wrapper:
import setuptools
with open("README.md", "r") as fh:
long_description = fh.read()
setuptools.setup(
name="little-mallet-wrapper",
version="0.0.4",
author="Maria Antoniak",
author_email="maa343@cornell.edu",
description="A little wrapper for the topic modeling functions of MALLET",
long_description=long_description,
long_description_content_type="text/markdown",
url="https://github.com/maria-antoniak/little-mallet-wrapper",
packages=setuptools.find_packages(),
classifiers=[
"Programming Language :: Python :: 3",
"License :: OSI Approved :: GNU General Public License v3 (GPLv3)",
"Operating System :: OS Independent",
],
python_requires='>=3.6',
)
Create an account on PyPI.
Install and/or update setuptools and wheel:
python3 -m pip install --user --upgrade setuptools wheel
Install and/or update twine:
python3 -m pip install --user --upgrade twine
Generate your distribution files:
python3 setup.py sdist bdist_wheel
Upload to PyPI:
python3 -m twine upload --repository-url https://upload.pypi.org/legacy/ dist/*
These resources have much more detailed information.
Marche 25, 2020