4

I'm very new to python packaging, and trying to make a pip compatible setup and post-install script for my package for colleagues. The goal of the post-install script is to create a configuration file that will be customized to the end-user and their system, and while I guess I could just have them run a secondary setup script post installation, it seems to make more sense to me to just have the setup.py script and associated post-install handle things.

The issue is that while using either easy-install or un-tarballing the package and running python setup.py install work fine, pip will not. I think it may be that pip is inhibiting interaction with stdout and stdin based on this discussion from 2015, but I'm not sure if that's the case or I'm just not doing it correctly. Even if I use -vvv with pip install I still don't get output or interactivity from my post-install.py script.

Does anyone know a good workaround to get a post installation script to run interactively with pip? The post install script is a bit long, so I won't post it here, but here is my setup.py script in case I need to handle it from here:

import sys, os
from setuptools import setup
from setuptools.command.install import install as _install
from subprocess import call

import my_package

def _post_install(dir):
    call([sys.executable, 'postinstall.py'])


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

def readme():
    with open('README.rst') as fh:
        return fh.read()

config = {
    'name'                   : 'my_package',
    'description'            : ('My Package'),
    'long_description'       : readme(),
    'version'                : my_package.__version__,
    'author'                 : 'My Name',
    'author_email'           : 'my.email@email.com',
    'download_url'           : 'https://download.link.com',
    'test_suite'             : 'nose.collector',
    'tests_require'          : ['nose'],
    'packages'               : ['my_package'],
    'install_requires'       : ['requests'],
    'scripts'                : ['bin/script1.py',
                                'bin/script2.py',
                               ],
    'include_package_data'   : True,
    'zip_safe'               : False,
    'license'                : 'MIT',
    'cmdclass'               : {'install' : install}
}

setup(**config)
drmrgd
  • 733
  • 5
  • 17

0 Answers0