Best way to share code across several setup.py scripts?

99封情书 提交于 2019-12-01 06:47:40
Martijn Pieters

Normally setup.py is the entry point for distribution of distinct packages. As such, it's hard to then share code between those packages.

If you use setuptools (or it's fork, distribute) in your setup.py, you can specify packages that must be installed when installing your package with the setup_requires entry.

Unfortunately, your setup.py is executed first; as soon as the setup_requires line is parsed, the extra packages listed there will be installed locally, but this may be too late for your needs.

The work-around is to create a separate Distribution object before you call setup which defines the setup_requires entries:

import setuptools

setuptools.dist.Distribution(dict(setup_requires='yoursharedsetuppackage'))
# `setup_requires` is parsed and acted upon immediately; from here on out
# the yoursharedsetuppackage is installed and importable.

import yoursharedsetuppackage

setup(...)
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!