Resources for publishing your own PyPi package

1 minute read

Published:

Resources for publishing your own PyPi package

I used this article to prepare my code for packaging

src tree vs not src tree

Placing your code inside a directory called ‘src’ is optional

Write your pyproject.toml file so that dependencies are automatically installed when user installs your package

here is an example of my pyproject.toml file

[build-system]
requires = ["setuptools>=61.0"]
build-backend = "setuptools.build_meta"


[project]
name = "Signature-SNVs"
version = "0.0.1"
authors = [
  { name="Leah Briscoe, Eran Halperin, Nandita Garud", email="leahpbriscoe@gmail.com" },
]
description = "A package to produce signature SNVs for source tracking with methods like FEAST. Given a set of samples representing the sink and source of interest, and a species for which you have snps MIDAS output, you can run this method."
readme = "README.md"
requires-python = ">=3.0"
classifiers = [
    "Programming Language :: Python :: 3",
    "License :: OSI Approved :: MIT License",
    "Operating System :: OS Independent",
]

dependencies = ['numpy>=1.20.3','scipy>=1.7.1','pyyaml>=6.0','pandas>=1.3.4','bz2file>=0.98']

[project.urls]
"Homepage" = "https://github.com/garudlab/Signature-SNVs"
"Bug Tracker" = "https://github.com/garudlab/Signature-SNVs/issues"

Commands to upload to test server Test PyPi

python3 -m pip install --upgrade build
python3 -m build
python3 -m pip install --upgrade twine
python3 -m twine upload --repository testpypi dist/*

Commands to upload to PyPi server

Read to post to PyPi officially?

python3 -m pip install --upgrade build
python3 -m build
python3 -m pip install --upgrade twine
python3 -m twine upload dist/*

Test installation of your own package with a virtual environment

python3 -m pip install --user virtualenv"
python3 -m virtualenv signature_snvs_env
source ./signature_snvs_env/bin/activate

Then test installation

python3 -m pip install Signature-SNVs==0.0.1