Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to include post install script in python setuptools

import os
from setuptools import setup
from distutils.command.install import install as _install
def _post_install(dir):
    from subprocess import call
    call([sys.executable, 'post_script.py'],
    cwd=os.path.join(dir, 'script_folder'))


class install(_install):
    def run(self):
        _install.run(self)
        self.execute(_post_install, (self.install_lib,),
                     msg="Running post install task")


VERSION = '123'
setup(name='XXXX',
      description='hello',
      url='http://giturl.com',
      packages=['package_folder'],
      cmdclass={'install': install},
      package_data={
              'package_folder': [
              '*.py',
              'se/*pp'
          ],
      },
)

# Basically the postscript should execute once I install the rpm that is being built. Its not working. Any other method as this is not working?

like image 898
Minion-kunfu Avatar asked Mar 10 '16 02:03

Minion-kunfu


People also ask

How do I install packages on setuptools?

To install setuptools visit http://pypi.python.org/pypi/setuptools and follow the instructions for your operating system. Also, check out http://peak.telecommunity.com/DevCenter/EasyInstall for more instructions on how to install setup tools.

Does pip install setuptools?

Type “ pip install setuptools ” (without quotes) in the command line and hit Enter again. This installs setuptools for your default Python installation. The previous command may not work if you have both Python versions 2 and 3 on your computer.

How do I install a Python script?

To install a package that includes a setup.py file, open a command or terminal window and: cd into the root directory where setup.py is located. Enter: python setup.py install.

How do I add data to setup py?

Place the files that you want to include in the package directory (in our case, the data has to reside in the roman/ directory). Add the field include_package_data=True in setup.py. Add the field package_data={'': [... patterns for files you want to include, relative to package dir...]} in setup.py .


1 Answers

You can run python setup.py bdist_rpm --post-install=<script name> This will create an rpm which will run the contents of the script you provide after the normal rpm installation is completed.

If you want to do it in your setup.py you can pass along

setup( 
    ... 
    options={'bdist_rpm': {'post_install': '<post_install script name>'}},
    ... 
)

This will only affect bdist_rpm, and thus only the rpm you create with python setup.py bdist_rpm

like image 170
Jens Timmerman Avatar answered Oct 04 '22 03:10

Jens Timmerman