Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot print or log warning message in installation step #2933

Closed
floer32 opened this issue Jun 25, 2015 · 3 comments
Closed

Cannot print or log warning message in installation step #2933

floer32 opened this issue Jun 25, 2015 · 3 comments
Labels
auto-locked Outdated issues that have been locked by automation

Comments

@floer32
Copy link

floer32 commented Jun 25, 2015

I need to (always) show a message to the user upon installation of a package. In pip 6, it seemed OK; I would print to stderr. In pip 7 (7.0.3), I can't figure out any way to do it.

Things I have tried:

(1) Variations on overriding setuptools.command.install or distutils.command.install

For example ...

from __future__ import print_function

from setuptools import setup, find_packages
from setuptools.command.install import install as _install

# ...

notice = \
    "[!!!] NOTICE: mynotice"

def print_notice():
    print(notice, file=sys.stderr)

class install_with_warning(_install):
    def run(self):
        _install.run(self)
        self.execute(print_notice, (), msg=notice)

# ...

setup(
#...
    cmdclass={'install': install_with_warning}, )

That works OK with python setup.py install and IIRC, it worked with pip 6 (as long as you're printing to stderr).

(2) Using the logger from the install command file, and logging at WARNING or ERROR level (source code)

from __future__ import print_function

from setuptools import setup, find_packages
from setuptools.command.install import install as _install

from pip.commands.install import logger

# ...

notice = \
    "[!!!] NOTICE: mynotice"

class install_with_warning(_install):
    def run(self):
        _install.run(self)
        logger.warning(notice)
        logger.error(notice)

logger.error(notice)

setup(
#...
    cmdclass={'install': install_with_warning}, )

And that displays warnings in several ways if run with pip 6, but pip 7 swallows it all.

Is there a supported way to print/log messages to stderr or stdout, during install?

@AbdealiLoKo
Copy link

I need the same thing. Found any way to do it ?

@dstufft
Copy link
Member

dstufft commented Mar 30, 2017

This is not really possible to do without hard failing on install. We purposely remove output because in the 95% case, the output is nothing but confusing to end users. In additional we aggressively try to build wheels once and then reuse those, and in this case those rebuilt wheels won't execute the setup.py file at all to enable some kind of message like this.

@algorys
Copy link

algorys commented Sep 13, 2017

Just FYI, I found a solution who can do that. But user should add -v flag to pip install command:

pip install package -v

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)

See https://stackoverflow.com/questions/38933402/python-setup-py-how-to-show-message-after-install

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
auto-locked Outdated issues that have been locked by automation
Projects
None yet
Development

No branches or pull requests

4 participants