Execute a Python script post install using distutils / setuptools

前端 未结 2 2021
攒了一身酷
攒了一身酷 2020-11-27 14:57

I\'m trying to add a post-install task to Python distutils as described in How to extend distutils with a simple post install script?. The task is supposed to execute a Pyth

2条回答
  •  借酒劲吻你
    2020-11-27 15:23

    I think the easiest way to perform the post-install, and keep the requirements, is to decorate the call to setup(...):

    from setup tools import setup
    
    
    def _post_install(setup):
        def _post_actions():
            do_things()
        _post_actions()
        return setup
    
    setup = _post_install(
        setup(
            name='NAME',
            install_requires=['...
        )
    )
    

    This will run setup() when declaring setup. Once done with the requirements installation, it will run the _post_install() function, which will run the inner function _post_actions().

提交回复
热议问题