Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Execute post installation task with pip

My Project Tree Structure

.
├── example.gif
├── funmotd
│   ├── config.json
│   ├── __init__.py
│   └── quotes_db.py
├── LICENSE
├── README.md
└── setup.py

setup.py(Removed some code in order to have less code)

import sys
import os
import setuptools
from setuptools.command.install import install

class PostInstall(install):
    def run(self):
        mode = 0o666
        bashrc_file = os.path.join(os.path.expanduser('~'), ".bashrc")
        install.run(self)
        # Added CLI to .bashrc
        # Change "config.json" file permission


setuptools.setup(
      ...
      entry_points={'console_scripts': ['funmotd = funmotd:main']},
      package_dir={'funmotd': 'funmotd/'},
      package_data={'funmotd': ['config.json'], },
      include_package_data=True,
      python_requires=">=3.4",
      cmdclass={'install': PostInstall, },
      ...      
)

The PostInstall is executing fine when I run python3 setup.py install. So, uploaded to Pypi like below(From this doc)

$ python3 setup.py bdist_wheel
# Created "dist", "funmotd.egg-info" and "build" dirs
$ twine upload dist/*

But when I run pip install funmotd, PostInstall is NOT executing, I see that dist/* is like static compiled stuff. Is there any trick to run post installation tasks when I run pip install funmotd. Or how to make setup.py execute at pip.

I Followed below questions, didn't get solution what I need

  • Post-install script with Python setuptools

  • Run custom task when call `pip install`

PS: I don't want users to clone repo and run python setup.py install. Want to make it simple pip install funmotd

UDPATE1

Seems there is already issue on github which is long thread

like image 650
Veerendra Avatar asked May 01 '26 03:05

Veerendra


1 Answers

pip doesn't run setup.py from a wheel hence you cannot run any post-installation code from setup.py in a wheel.

setup.py is used to build wheels or used during installation of source distribution (sdist). So if you want post-installation script stop uploading wheels to PyPI, only release source distribution (python3 setup.py sdist). Then pip install funmotd will run code from setup.py.

like image 76
phd Avatar answered May 04 '26 00:05

phd



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!