Providing a custom command class to setup.py in a separately installed package

余生颓废 提交于 2019-12-23 01:54:11

问题


I am trying to create a python package that implements a custom command class for setuptools.setup() for use in other, unrelated packages' setup.py scripts. Ideally, I would like to be able to include this package in the setup_requires argument to setup(), and have the custom command class take effect before the remainder of the setup activities are performed. Does setup() provide a hook of some sort to support this use case? If not, how can I minimize the amount of boilerplate that has to appear in the setup.py script when using my package while still guaranteeing that my package will be available during setup? This is for an automation framework I am building, so minimizing the impact on the client packages' code and any dependence on end-user actions is a must.

Here is some example code...

In my_custom_setup_package:

from setuptools.command.install import install as _install

class install(_install):

    def run(self):
        result = super().run()

        # If the installed package has the required hooks:
            # Perform some custom post-installation actions

In the setup.py for client_package:

from setuptools import setup

# No cmdclass argument is given, because I can't count on
# my_custom_setup_package to be installed yet.
setup(
    ...
    setup_requires=['my_custom_setup_package'],
    ...
)

When running python setup.py install for client_package, the custom installation actions defined in my_custom_setup_package should get executed immediately after installation, even if my_custom_setup_package was not installed before the command was executed.

Any help is appreciated, even if it is to point me in a new direction altogether.

来源:https://stackoverflow.com/questions/37551598/providing-a-custom-command-class-to-setup-py-in-a-separately-installed-package

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