Python Packaging (and why you should care) ========================================== Code Reuse! ----------- * 3rd party libraries * your own libraries Loading Python Modules ---------------------- (The short, short version) * cython looks in ${PYTHONHOME} (please don't use!) * ... in ${PYTHONPATH} * in site-packages loaded from site.py virtualenv ---------- To use:: virtualenv ${DIRECTORY} . ${DIRECTORY}/bin/activate May want --system-site-packages Python Packaging ---------------- * distutils * setuptools Installing Python Packages -------------------------- The setuptools way:: easy_install MyPackage The pip way:: pip install MyPackage PyPI ---- *Where do pip and easy_install get their packages?* The Python Package Index https://pypi.python.org/ ( What is really used behind the scene: https://pypi.python.org/simple/ ) setup.py -------- What goes in a setup.py file? * no one knows! * no one cares! However, it let's you do packaging so you do care a little... setup.py boilerplate -------------------- See http://k0s.org/hg/MakeItSo/file/tip/makeitso/python_package/setup.py Notable keywords: * install_requires : list of dependencies * entry_points : console scripts (and whatever else you want) * zip_safe=False : probably should be the normal case Upload Packages to PyPI ----------------------- Once you have a setup.py, you can distribute to your heart's content:: python setup.py egg_info -RDb "" sdist register upload develop setuptools vs. distutils (vs. setuptools2 vs distribute....) ------------------------------------------------------------ Python packaging is a mess. * distutils is standard, but it doesn't do anything * setuptools (kinda) works, but it does too much * dependencies * python setup.py develop * distribute (etc) fixes, but aren't standard...yet (Long story) install vs. develop ------------------- Making your own PyPI -------------------- Not a difficult directory structure:: ${INDEX_BASE}/${PACKAGE}/${PACKAGE}-${VERSION}.tar.gz We should do this! Then use:: pip install -i ${INDEX_BASE} ${PACKAGE} or:: pip install -i ${INDEX_BASE} ${PACKAGE}=${VERSION} utils.py and monoliths ---------------------- Why not just have everything.py and call it a day? * intent * dependencies