2

I'm working on distributing a Python package. It depends on the library lupa. I want to run a post-install script that depends on lupa that initializes some data within the package after it's been installed. After looking at some answers around StackOverflow, my stripped setup.py essentially looks like this:

# setup.py
from distutils.core import setup
from setuptools.command.install import install

class PostInstallCommand(install):
    def run(self):
        # Do normal setup
        install.run(self)
        # Now do my setup
        from mymodule.script import init
        init()

setup(
    # ...
    install_requires = [
        # ...
        "lupa >= 1.10",
        # ...
    ],
    cmdclass = {
        'install': PostInstallCommand
    }
)

However, when emulating a fresh install/setup with tox on Python 3.10, I get this error:

File "C:\My\Computer\Temp\pip-req-build-pl0jria3\setup.py", line 26, in run
      from mymodule.script import init
    File "C:\My\Computer\Temp\pip-req-build-pl0jria3\mymodule\script.py", line 28, in <module>
      import lupa
  ModuleNotFoundError: No module named 'lupa'

I was under the impression that anything put into install_requires would be installed by the time setup() finished, but that appears not to be the case (also corroborated by this answer). Is there anything I can do to ensure that lupa is installed prior to mymodule.script.init(), or is that stage of the setup process entirely out of the user's hands?

RedRuin
  • 122
  • 7

1 Answers1

0

After doing a good bit of research, it seems this kind of post-install script is somewhat against the core philosophy of setuptools, which means that a request like this is unlikely to be added, or at least added anytime soon.

Fortunately, this is somewhat of a blessing in disguise; my post-install script is actually an "update" console entry point that the user calls anytime they've added mods or updated any of the packages data. This script can be (and is supposed to be) called many times by the user, so by having it as part of the install process it helps introduce the purpose of the script to the user right from the start. This makes the slight annoyance on install tolerable, at least in my circumstance.

RedRuin
  • 122
  • 7