Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

python setup.py - how to show message after install

I am developing a PyQt5 app and making it available via pip install now that pip in python3 can install pyqt5 as dependence. I made an entry point to launch my package, and told setup.py that it's a gui_scripts.

What I would like to do now, is after the person typing pip install package, and the installation is finished, display a message to the person telling that you can now type package in the terminal to load the application. What's the correct way of doing that? Or should I not do this?

like image 752
eri0o Avatar asked Aug 13 '16 13:08

eri0o


People also ask

How do I print from setup py?

Just use the print() function at the end of your setup.py file.

Does pip install invoke setup py?

For installing packages in “editable” mode (pip install --editable), pip will invoke setup.py develop , which will use setuptools' mechanisms to perform an editable/development installation.

How does Python setup py work?

Use of Setup.py It primarily serves two purposes: It includes choices and metadata about the program, such as the package name, version, author, license, minimal dependencies, entry points, data files, and so on. Secondly, it serves as the command line interface via which packaging commands may be executed.


1 Answers

If you can ensure that

  • the package is always installed from a source distribution, not a binary wheel, and
  • the user uses the -v option for pip install,

you can output text in your setup.py script.

The setup.py is almost a regular Python script. Just use the print() function at the end of your setup.py file. In this example the file structure is somedir/setup.py, somedir/test/ and test/__init__.py.

Simple solution

from setuptools import setup

print("Started!")

setup(name='testing',
      version='0.1',
      description='The simplest setup in the world',
      classifiers=[
        'Development Status :: 3 - Alpha',
        'License :: OSI Approved :: MIT License',
        'Programming Language :: Python :: 3.0',
      ],
      keywords='setup',
      author='someone',
      author_email='[email protected]',
      license='MIT',
      packages=['test'],
      entry_points={
      },
      zip_safe=False)

print("Finished!")

Started!
running install
running bdist_egg
running egg_info
writing testing.egg-info/PKG-INFO
...
...
...
Processing dependencies for testing==0.1
Finished processing dependencies for testing==0.1
Finished!

Using setuptools.command.install solution

Also, you can subclass the setuptools.command.install command. Check the difference when you change the order of install.run(self) and os.system("cat testing.egg-info/PKG-INFO") in a clean setup.

from setuptools import setup
from setuptools.command.install import install
import os


class PostInstallCommand(install):
    """Post-installation for installation mode."""
    def run(self):
        install.run(self)
        os.system("cat testing.egg-info/PKG-INFO")


setup(name='testing',
      version='0.1',
      description='The simplest setup in the world',
      classifiers=[
        'Development Status :: 3 - Alpha',
        'License :: OSI Approved :: MIT License',
        'Programming Language :: Python :: 3.0',
      ],
      keywords='setup',
      author='someone',
      author_email='[email protected]',
      license='MIT',
      packages=['test'],
      entry_points={
      },
      cmdclass={
        'install': PostInstallCommand,
      },
      zip_safe=False)
like image 111
Jose Raul Barreras Avatar answered Oct 03 '22 08:10

Jose Raul Barreras