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

假装没事ソ 提交于 2019-12-19 08:29:17

问题


I've got several packages I'm working on, and I'd like to share code between their setup.py scripts. Is there any good way to do this or is code duplication my only option?


回答1:


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(...)


来源:https://stackoverflow.com/questions/12060925/best-way-to-share-code-across-several-setup-py-scripts

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