14

I'm trying to package a build of PyQt (installers aren't provided for the configuration I need), but I can't find any packaging configuration that works. The issue is not specific to PyQt though.

The problem: In order for the module to work, it needs a file in python's PREFIX directory. I understand that this may be bad form, but in my case there needs to be a qt.conf file there, and there isn't anything much I can do about it other than make the file available. I need to be able to run a post-install script to create the file with the installed PyQt path included. Or at least that seems like the best solution.

Options I looked at:

  • I can use python setup.py install and override the setuptools.command.install class. However, this works when setup.py is run manually, and requires unzipping the bdist and having a cmd prompt in the package folder. It doesn't work for bdist_wininst, bdist_msi, or bdist_wheel, which are much more convenient to install (the point of packaging). So possible, but not a great solution.

  • bdist_wheel seems like a good option, but it won't run anything post-install, and only puts files in specific folders, not including PREFIX.

  • bdist_wininst supports a post-install script (via --install-script switch when creating the package), but doesn't play nice with virtualenv. There is a stackoverflow answer that suggests running easy_install or wheel convert, but those options only unpack, they won't run the install script. Otherwise you have to change the registry, which is not an acceptable solution.

What am I missing? Is there a viable option?

Community
  • 1
  • 1
Brett Stottlemyer
  • 2,734
  • 4
  • 26
  • 38
  • Possible duplicate of [How can I add post-install scripts to easy\_install / setuptools / distutils?](https://stackoverflow.com/questions/250038/how-can-i-add-post-install-scripts-to-easy-install-setuptools-distutils) – hoefling May 29 '18 at 19:00

2 Answers2

2

As kynan explains, to gain control one must define "class install" to override run().

EDIT

To quote the code he supplied:

import os, sys
from distutils.core import setup
from distutils.command.install import install as _install


def _post_install(dir):
    from subprocess import call
    call([sys.executable, 'scriptname.py'],
         cwd=os.path.join(dir, 'packagename'))


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


setup(
    ...
    cmdclass={'install': install},
)
J_H
  • 17,926
  • 4
  • 24
  • 44
0

As you've already mentioned, you can edit python setup.py install and override the setuptools.command.install class to run a post-installation script.
However, this works when you run setup.py manually.
If you want this to work with pip install, you need to force pip to install your package from source.
For example:

pip install --no-binary <my_package_name> <my_package_name>
J.M.
  • 472
  • 1
  • 6
  • 15