How to extend distutils with a simple post install script?

后端 未结 4 2558
我寻月下人不归
我寻月下人不归 2020-12-01 03:09

I need to run a simple script after the modules and programs have been installed. I\'m having a little trouble finding straight-forward documentation on how to do this. It l

4条回答
  •  时光说笑
    2020-12-01 03:18

    OK, I figured it out. The idea is basically to extend one of the distutils commands and overwrite the run method. To tell distutils to use the new class you can use the cmdclass variable.

    from distutils.core import setup
    from distutils.command.install_data import install_data
    
    class post_install(install_data):
        def run(self):
            # Call parent 
            install_data.run(self)
            # Execute commands
            print "Running"
    
    setup(name="example",
          cmdclass={"install_data": post_install},
          ...
          )
    

    Hope this will help someone else.

提交回复
热议问题