9

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?

eri0o
  • 2,285
  • 4
  • 27
  • 43

2 Answers2

6

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='someone@example.com',
      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='someone@example.com',
      license='MIT',
      packages=['test'],
      entry_points={
      },
      cmdclass={
        'install': PostInstallCommand,
      },
      zip_safe=False)
akaihola
  • 26,309
  • 7
  • 59
  • 69
Jose Raul Barreras
  • 849
  • 1
  • 13
  • 19
  • 26
    Annoyingly enough, *pip* gobbles up these custom messages unless you run it with *-v* or such. The tasks work, but you just don't see the messages. – Marakai Feb 02 '17 at 23:24
  • 2
    Also I have not found a way to make this work with pip-installing wheeels. They do not "run" `setup.py` at installation - only when packaging into a `.whl`. – JCGB Mar 04 '19 at 15:19
-3

Another option would be the logging module.

rasterio for example uses an approach like this which you could adapt for your needs:

import logging
import sys

logging.basicConfig(stream=sys.stderr, level=logging.INFO)
log = logging.getLogger()

...

log.info("Your message")

sys.stderr will be printed by pip.

bugmenot123
  • 1,069
  • 1
  • 18
  • 33