min-pypi-hello
A minimalist example of PyPI packaging. ( view on pypi; view on GitHub )
- A package called
minpypihello, which contains a module calledmodhello. You can import usingfrom minpypihello import modhello. - A script that can be executed directly to print a helloworld message.
1. Check the Project and Study Files
Run ./myhello and see if it works as expected.
Navigate under this repo and see those files for an example layout.
min-pypi-hello/
├── MANIFEST.in
├── README.md
├── README.txt
├── minpypihello
│ ├── __init__.py
│ └── modhello.py
├── myhello
└── setup.py
2. Package
Build source archive: python setup.py sdist.
Test:
- Find your package in
dist/minpypihello-x.tar.gz, wherexis the version number. - Uncompress the archive and go to its root.
- Install
python setup.py install. You can add--userto install under your home. - Try
myhello(not./myhello). If you$PATHis set properly and the install is successful, you should see the printed hello message. - Try to import
minpypihello.modhellofrom a Python script (see code ofmyhellofor an example).
3. Distribute to PyPI
Register: Use python setup.py register and go through the procedure as prompt.
Upload: python setup.py sdist upload.
Reference
- distutils: http://docs.python.org/2/distutils/
- A list of package metadata: http://docs.python.org/2/distutils/setupscript.html#additional-meta-data