Python packaging pitfalls

Wed 25 June 2014

Note

Use cookiecutter-pylibrary to avoid all the pain.

Just a short list of packaging blunders ...



Forgetting to clean the build dir *
why:

distutils and setuptools will skip things if you have stuff in the build dir, even if you have changed options in your setup.py.

fix:

Integrate a rm -rf build/ in your build pipeline.

Better (clean everything): rm -rf dist build */*.egg-info *.egg-info

Forgetting to specify package data *
why:

Distutils and Setuptools don't include your non-python files by default.

fix:

Create a MANIFEST.in and use include_package_data=True. Don't use package_data as it will override your manifest, and it's a less flexible approach anyway. [4]

Make sure your data files are inside packages (they are called package data after all). An example of how to use data files.

Fine grained MANIFEST.in *

Listing few file types in MANIFEST.in [4], then adding some webfonts or templates - only to find out the release you published on PyPI doesn't include them.

why:You duplicated information you already have in the filesystem [1].
fix:Just recursive-include or graft the whole dir. Separate sources from build and temporary files (e.g.: use different directories).
Using package_data, or worse: fine grained package_data *

Listing few file types in package_data [6], then adding some webfonts - only to find out the release you published on PyPI doesn't include them.

why:You duplicated information you already have in the filesystem [1]. You have better options.
fix:Use MANIFEST.in and include_package_data=True. See forgetting-package-data.
Listing excludes/prunes before includes/grafts *

Your excludes/prunes would get overriden if there are includes/grafts that match the same files later.

why:Last rule wins [4].
fix:Use correct rule ordering. Excludes have more weight, put them last in MANIFEST.in.
Hardcoding packages list in setup.py *
why:You duplicated information you already have in the filesystem [1].
fix:Use setuptools.find_packages. Or, if you want everything to be static, have good testing [3].
Hardcoding py_modules list in setup.py *
why:

You duplicated information you already have in the filesystem [1].

fix:

Discover the modules, e.g.:

py_modules=[splitext(basename(i))[0] for i in glob.glob("src/*.py")]

::...

免责声明:
当前网页内容, 由 大妈 ZoomQuiet 使用工具: ScrapBook :: Firefox Extension 人工从互联网中收集并分享;
内容版权归原作者所有;
本人对内容的有效性/合法性不承担任何强制性责任.
若有不妥, 欢迎评注提醒:

或是邮件反馈可也:
askdama[AT]googlegroups.com


订阅 substack 体验古早写作:


点击注册~> 获得 100$ 体验券: DigitalOcean Referral Badge

关注公众号, 持续获得相关各种嗯哼:
zoomquiet


自怼圈/年度番新

DU22.4
关于 ~ DebugUself with DAMA ;-)
粤ICP备18025058号-1
公安备案号: 44049002000656 ...::