Skip to content

Commit

Permalink
Merge pull request #13 from jantman/suppress-pip-subprocess
Browse files Browse the repository at this point in the history
Suppress pip.subprocessor logging - fixes jantman/awslimitchecker#465
  • Loading branch information
jantman committed Sep 18, 2020
2 parents 5721f35 + 5dab425 commit 3c71b22
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 6 deletions.
5 changes: 5 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
Changelog
=========

1.1.1 (2020-09-18)
------------------

* Unless :py:class:`~.VersionFinder` is constructed with the ``log=True`` option, completely disable the ``pip.subprocessor`` logger. This will suppress annoying critical-level log messages generated on systems which do not have ``git`` in the PATH.

1.1.0 (2020-09-18)
------------------

Expand Down
14 changes: 11 additions & 3 deletions versionfinder/tests/test_versionfinder.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,11 +93,18 @@ class TestInit(object):

def test_init(self):
m_pip_logger = Mock()
m_pip_s_logger = Mock()

def se_get_logger(lname):
if lname == 'pip':
return m_pip_logger
if lname == 'pip.subprocessor':
return m_pip_s_logger
with patch('%s.inspect.stack' % pbm, autospec=True) as m_stack:
with patch('%s.logger' % pbm, autospec=True) as m_logger:
with patch('%s.logging.getLogger' % pbm,
autospec=True) as m_log_pip:
m_log_pip.return_value = m_pip_logger
autospec=True) as m_get_log:
m_get_log.side_effect = se_get_logger
cls = VersionFinder('foobar',
package_file='/foo/bar/baz.py')
assert m_stack.mock_calls == []
Expand All @@ -110,8 +117,9 @@ def test_init(self):
call.debug('Explicit package file: %s', '/foo/bar/baz.py'),
call.debug('package_dir: /foo/bar')
]
assert m_log_pip.mock_calls == [call('pip')]
assert m_get_log.mock_calls == [call('pip'), call('pip.subprocessor')]
assert m_pip_logger.mock_calls == [call.setLevel(logging.CRITICAL)]
assert m_pip_s_logger.mock_calls == []

def test_init_log_true(self):
m_pip_logger = Mock()
Expand Down
2 changes: 1 addition & 1 deletion versionfinder/version.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,5 +35,5 @@
##################################################################################
"""

VERSION = '1.1.0'
VERSION = '1.1.1'
PROJECT_URL = 'https://github.com/jantman/versionfinder'
7 changes: 5 additions & 2 deletions versionfinder/versionfinder.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,8 +118,9 @@ def __init__(self, package_name, package_file=None, log=False,
:type package_file: str
:param log: If not set to True, the "versionfinder" and "pip" loggers
will be set to a level of :py:const:`logging.CRITICAL` to suppress
log output. If set to True, you will see a LOT of debug-level log
output, for debugging the internals of versionfinder.
log output. The "pip.subprocessor" logger will be completely disabled.
If set to True, you will see a LOT of debug-level log output, for
debugging the internals of versionfinder.
:type log: bool
:param caller_frame: If the call to this method is wrapped by something
else, this should be the stack frame representing the original caller.
Expand All @@ -132,6 +133,8 @@ def __init__(self, package_name, package_file=None, log=False,
pip_log = logging.getLogger("pip")
pip_log.setLevel(logging.CRITICAL)
pip_log.propagate = True
pip_s_log = logging.getLogger('pip.subprocessor')
pip_s_log.disabled = True
logger.debug("Finding package version for: %s", package_name)
self.package_name = package_name
if package_file is not None:
Expand Down

0 comments on commit 3c71b22

Please sign in to comment.