Python package with pywin32 or pypiwin32 dependency

Viewed 2051

I'm building a python package which requires pywin32.

Adding pywin32 as a dependency doesn't work seamlessly, since it has a postinstall script which the user must run themselves.

Adding pypiwin32 as a dependency doesn't work because my package won't play nice with other packages which do require pywin32

I tried requiring both, but it turns out pywin32 and pypiwin32 can't coexist on the same python installation

Is there a way of specifying either pywin32 or pypiwin32 as a dependency? Or some other solution?

1 Answers

The adding pip install pywin32 as a post-install script works, but removes the install_requires command from setup. To fix this, add do_egg_install(self) rather than run in the classes

from setuptools import setup
from setuptools.command.develop import develop as _develop
from setuptools.command.install import install as _install
from subprocess import check_call

# PostDevelopCommand
class develop(_develop):
    """Post-installation for development mode."""
    def run(self):
        check_call("pip install pywin32")
        develop.do_egg_install(self)

# PostInstallCommand
class install(_install):
    """Post-installation for installation mode."""
    def run(self):
        check_call("pip install pywin32")
        develop.do_egg_install(self)

and insert cmdclass argument to setup() function in setup.py:

 setup(
     ...

    cmdclass={
        'develop': develop,
        'install': install,
    },

    ...
)
Related