Hello community, here is the log from the commit of package python-click-log for openSUSE:Factory checked in at 2018-07-18 22:56:50 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ Comparing /work/SRC/openSUSE:Factory/python-click-log (Old) and /work/SRC/openSUSE:Factory/.python-click-log.new (New) ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ Package is "python-click-log" Wed Jul 18 22:56:50 2018 rev:2 rq:623575 version:0.3.2 Changes: -------- --- /work/SRC/openSUSE:Factory/python-click-log/python-click-log.changes 2017-08-10 14:11:31.681312145 +0200 +++ /work/SRC/openSUSE:Factory/.python-click-log.new/python-click-log.changes 2018-07-18 22:56:51.894378885 +0200 @@ -1,0 +2,10 @@ +Wed Jul 4 07:04:11 UTC 2018 - dmacvicar@suse.de + +- Update to 0.3.2 + * remove unused import + * use default root logger + * fix docu + * fix formating of logs + * simplify api + +------------------------------------------------------------------- Old: ---- click-log-0.1.8.tar.gz New: ---- click-log-0.3.2.tar.gz ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ Other differences: ------------------ ++++++ python-click-log.spec ++++++ --- /var/tmp/diff_new_pack.7UdQDT/_old 2018-07-18 22:56:52.238377744 +0200 +++ /var/tmp/diff_new_pack.7UdQDT/_new 2018-07-18 22:56:52.242377730 +0200 @@ -1,7 +1,7 @@ # # spec file for package python-click-log # -# Copyright (c) 2017 SUSE LINUX GmbH, Nuernberg, Germany. +# Copyright (c) 2018 SUSE LINUX GmbH, Nuernberg, Germany. # # All modifications and additions to the file contributed by third parties # remain the property of their copyright owners, unless otherwise agreed @@ -18,12 +18,12 @@ %{?!python_module:%define python_module() python-%{**} python3-%{**}} Name: python-click-log -Version: 0.1.8 +Version: 0.3.2 Release: 0 Summary: Logging integration for Click License: MIT Group: Development/Languages/Python -Url: https://github.com/click-contrib/click-log +URL: https://github.com/click-contrib/click-log Source: https://files.pythonhosted.org/packages/source/c/click-log/click-log-%{version}.tar.gz BuildRequires: %{python_module base} BuildRequires: %{python_module click} @@ -31,7 +31,6 @@ BuildRequires: fdupes BuildRequires: python-rpm-macros Requires: python-click -BuildRoot: %{_tmppath}/%{name}-%{version}-build BuildArch: noarch %python_subpackages @@ -51,8 +50,8 @@ %python_expand %fdupes -s %{buildroot}%{$python_sitelib} %files %{python_files} -%defattr(-,root,root,-) -%doc README.rst LICENSE +%doc README.rst +%license LICENSE %{python_sitelib}/* %changelog ++++++ click-log-0.1.8.tar.gz -> click-log-0.3.2.tar.gz ++++++ diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/click-log-0.1.8/PKG-INFO new/click-log-0.3.2/PKG-INFO --- old/click-log-0.1.8/PKG-INFO 2016-12-17 13:03:55.000000000 +0100 +++ new/click-log-0.3.2/PKG-INFO 2018-06-06 10:20:39.000000000 +0200 @@ -1,6 +1,6 @@ -Metadata-Version: 1.0 +Metadata-Version: 1.1 Name: click-log -Version: 0.1.8 +Version: 0.3.2 Summary: Logging integration for Click Home-page: https://github.com/click-contrib/click-log Author: Markus Unterwaditzer @@ -23,3 +23,18 @@ Licensed under the MIT, see ``LICENSE``. Platform: UNKNOWN +Classifier: Development Status :: 4 - Beta +Classifier: Environment :: Console +Classifier: Environment :: Plugins +Classifier: Intended Audience :: Developers +Classifier: License :: OSI Approved :: MIT License +Classifier: Programming Language :: Python +Classifier: Programming Language :: Python :: 2 +Classifier: Programming Language :: Python :: 2.7 +Classifier: Programming Language :: Python :: 3 +Classifier: Programming Language :: Python :: 3.3 +Classifier: Programming Language :: Python :: 3.4 +Classifier: Programming Language :: Python :: 3.5 +Classifier: Programming Language :: Python :: 3.6 +Classifier: Programming Language :: Python :: Implementation :: CPython +Classifier: Topic :: System :: Logging diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/click-log-0.1.8/click_log/__init__.py new/click-log-0.3.2/click_log/__init__.py --- old/click-log-0.1.8/click_log/__init__.py 2016-12-17 13:03:42.000000000 +0100 +++ new/click-log-0.3.2/click_log/__init__.py 2018-06-06 10:20:16.000000000 +0200 @@ -3,7 +3,7 @@ import click -__version__ = '0.1.8' +__version__ = '0.3.2' if not hasattr(click, 'get_current_context'): @@ -13,9 +13,6 @@ ClickHandler, ColorFormatter, basic_config, - get_level, - init, - set_level, ) from .options import simple_verbosity_option diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/click-log-0.1.8/click_log/core.py new/click-log-0.3.2/click_log/core.py --- old/click-log-0.1.8/click_log/core.py 2016-12-17 00:03:53.000000000 +0100 +++ new/click-log-0.3.2/click_log/core.py 2018-06-06 10:12:44.000000000 +0200 @@ -1,9 +1,7 @@ # -*- coding: utf-8 -*- -import sys - -import functools import logging +import sys import click @@ -36,31 +34,24 @@ def format(self, record): if not record.exc_info: level = record.levelname.lower() + msg = record.getMessage() if level in self.colors: prefix = click.style('{}: '.format(level), **self.colors[level]) - - msg = record.msg - if not PY2 and isinstance(msg, bytes): - msg = msg.decode(sys.getfilesystemencoding(), - 'replace') - elif not isinstance(msg, (text_type, bytes)): - msg = str(msg) - record.msg = '\n'.join(prefix + x for x in msg.splitlines()) - + msg = '\n'.join(prefix + x for x in msg.splitlines()) + return msg return logging.Formatter.format(self, record) class ClickHandler(logging.Handler): + _use_stderr = True + def emit(self, record): try: msg = self.format(record) level = record.levelname.lower() - err = level in ('warning', 'error', 'exception', 'critical') - click.echo(msg, err=err) - except (KeyboardInterrupt, SystemExit): - raise - except: + click.echo(msg, err=self._use_stderr) + except Exception: self.handleError(record) @@ -68,52 +59,17 @@ _default_handler.formatter = ColorFormatter() +def _normalize_logger(logger): + if not isinstance(logger, logging.Logger): + logger = logging.getLogger(logger) + return logger + + def basic_config(logger=None): '''Set up the default handler (:py:class:`ClickHandler`) and formatter (:py:class:`ColorFormatter`) on the given logger.''' - if not isinstance(logger, logging.Logger): - logger = logging.getLogger(logger) + logger = _normalize_logger(logger) logger.handlers = [_default_handler] logger.propagate = False return logger - - -def init(logger=None): - '''Set the application's logger and call :py:func:`basic_config` on it.''' - def decorator(f): - @functools.wraps(f) - def wrapper(*args, **kwargs): - m = _meta() - l = basic_config(logger=logger) - l.setLevel(m.get('level', DEFAULT_LEVEL)) - - if m.setdefault('logger', l) is not l: - raise RuntimeError('Only one main logger allowed.') - - return f(*args, **kwargs) - return wrapper - return decorator - - -def get_logger(): - '''Get the application's logger.''' - return _meta().get('logger') - - -def set_level(level): - '''Set the level for the application's logger.''' - - if not isinstance(level, int): - raise ValueError('Must be constant from `logging`.') - - logger = get_logger() - if logger is not None: - logger.setLevel(level) - - _meta()['level'] = level - - -def get_level(): - '''Get the level for the application's logger.''' - return _meta().get('level', DEFAULT_LEVEL) diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/click-log-0.1.8/click_log/options.py new/click-log-0.3.2/click_log/options.py --- old/click-log-0.1.8/click_log/options.py 2016-12-13 18:07:26.000000000 +0100 +++ new/click-log-0.3.2/click_log/options.py 2017-10-16 13:54:23.000000000 +0200 @@ -1,11 +1,10 @@ import logging import click +from .core import _normalize_logger -from .core import set_level - -def simple_verbosity_option(*names, **kwargs): +def simple_verbosity_option(logger=None, *names, **kwargs): '''A decorator that adds a `--verbosity, -v` option to the decorated command. @@ -15,6 +14,9 @@ if not names: names = ['--verbosity', '-v'] + if isinstance(logger, str) and logger.startswith('-'): + raise ValueError('Since click-log 0.2.0, the first argument must now ' + 'be a logger.') kwargs.setdefault('default', 'INFO') kwargs.setdefault('metavar', 'LVL') @@ -22,6 +24,8 @@ kwargs.setdefault('help', 'Either CRITICAL, ERROR, WARNING, INFO or DEBUG') kwargs.setdefault('is_eager', True) + logger = _normalize_logger(logger) + def decorator(f): def _set_level(ctx, param, value): x = getattr(logging, value.upper(), None) @@ -29,7 +33,7 @@ raise click.BadParameter( 'Must be CRITICAL, ERROR, WARNING, INFO or DEBUG, not {}' ) - set_level(x) + logger.setLevel(x) return click.option(*names, callback=_set_level, **kwargs)(f) return decorator diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/click-log-0.1.8/click_log.egg-info/PKG-INFO new/click-log-0.3.2/click_log.egg-info/PKG-INFO --- old/click-log-0.1.8/click_log.egg-info/PKG-INFO 2016-12-17 13:03:55.000000000 +0100 +++ new/click-log-0.3.2/click_log.egg-info/PKG-INFO 2018-06-06 10:20:38.000000000 +0200 @@ -1,6 +1,6 @@ -Metadata-Version: 1.0 +Metadata-Version: 1.1 Name: click-log -Version: 0.1.8 +Version: 0.3.2 Summary: Logging integration for Click Home-page: https://github.com/click-contrib/click-log Author: Markus Unterwaditzer @@ -23,3 +23,18 @@ Licensed under the MIT, see ``LICENSE``. Platform: UNKNOWN +Classifier: Development Status :: 4 - Beta +Classifier: Environment :: Console +Classifier: Environment :: Plugins +Classifier: Intended Audience :: Developers +Classifier: License :: OSI Approved :: MIT License +Classifier: Programming Language :: Python +Classifier: Programming Language :: Python :: 2 +Classifier: Programming Language :: Python :: 2.7 +Classifier: Programming Language :: Python :: 3 +Classifier: Programming Language :: Python :: 3.3 +Classifier: Programming Language :: Python :: 3.4 +Classifier: Programming Language :: Python :: 3.5 +Classifier: Programming Language :: Python :: 3.6 +Classifier: Programming Language :: Python :: Implementation :: CPython +Classifier: Topic :: System :: Logging diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/click-log-0.1.8/docs/index.rst new/click-log-0.3.2/docs/index.rst --- old/click-log-0.1.8/docs/index.rst 2016-12-13 18:07:26.000000000 +0100 +++ new/click-log-0.3.2/docs/index.rst 2018-06-06 10:07:59.000000000 +0200 @@ -65,10 +65,10 @@ import logging logger = logging.getLogger(__name__) + click_log.basic_config(logger) @click.command() - @click_log.simple_verbosity_option() - @click_log.init(__name__) + @click_log.simple_verbosity_option(logger) def cli(): logger.info("Dividing by zero.") @@ -86,27 +86,24 @@ The ``error:``-prefix will be red, unless the output is piped to another command. -Under the hood, click-log will get the logger by the given name, and store it -on the click context object. You can then use :py:func:`get_level` and -:py:func:`set_level`. Those functions will look up the logger from the context -object without you having to pass any logger object or name. - The :py:func:`simple_verbosity_option` decorator adds a ``--verbosity`` option that takes a (case-insensitive) value of ``DEBUG``, ``INFO``, ``WARNING``, -``ERROR``, or ``CRITICAL``, and calls :py:func:`set_level` accordingly. +``ERROR``, or ``CRITICAL``, and calls ``setLevel`` on the given logger +accordingly. + +.. note:: + + Make sure to define the `simple_verbosity_option` as early as possible. + Otherwise logging setup will not be early enough for some of your other + eager options. API === -.. autofunction:: init - -.. autofunction:: simple_verbosity_option .. autofunction:: basic_config -.. autofunction:: get_level - -.. autofunction:: set_level +.. autofunction:: simple_verbosity_option Classes ------- diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/click-log-0.1.8/setup.cfg new/click-log-0.3.2/setup.cfg --- old/click-log-0.1.8/setup.cfg 2016-12-17 13:03:55.000000000 +0100 +++ new/click-log-0.3.2/setup.cfg 2018-06-06 10:20:39.000000000 +0200 @@ -7,5 +7,4 @@ [egg_info] tag_build = tag_date = 0 -tag_svn_revision = 0 diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/click-log-0.1.8/setup.py new/click-log-0.3.2/setup.py --- old/click-log-0.1.8/setup.py 2016-12-13 18:07:26.000000000 +0100 +++ new/click-log-0.3.2/setup.py 2017-07-27 21:33:50.000000000 +0200 @@ -20,6 +20,26 @@ url='https://github.com/click-contrib/click-log', license='MIT', long_description=open('README.rst').read(), + classifiers=[ + # See: https://pypi.python.org/pypi?:action=list_classifiers + 'Development Status :: 4 - Beta', + 'Environment :: Console', + 'Environment :: Plugins', + 'Intended Audience :: Developers', + 'License :: OSI Approved :: MIT License', + # List of python versions and their support status: + # https://en.wikipedia.org/wiki/CPython#Version_history + 'Programming Language :: Python', + 'Programming Language :: Python :: 2', + 'Programming Language :: Python :: 2.7', + 'Programming Language :: Python :: 3', + 'Programming Language :: Python :: 3.3', + 'Programming Language :: Python :: 3.4', + 'Programming Language :: Python :: 3.5', + 'Programming Language :: Python :: 3.6', + 'Programming Language :: Python :: Implementation :: CPython', + 'Topic :: System :: Logging', + ], packages=['click_log'], install_requires=[ 'click', diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/click-log-0.1.8/tests/test_basic.py new/click-log-0.3.2/tests/test_basic.py --- old/click-log-0.1.8/tests/test_basic.py 2016-12-16 23:50:56.000000000 +0100 +++ new/click-log-0.3.2/tests/test_basic.py 2018-06-06 10:19:03.000000000 +0200 @@ -11,6 +11,8 @@ test_logger = logging.getLogger(__name__) +click_log.basic_config(test_logger) +test_logger.level = logging.INFO @pytest.fixture @@ -20,7 +22,6 @@ def test_basic(runner): @click.command() - @click_log.init() def cli(): test_logger.info('hey') test_logger.error('damn') @@ -32,7 +33,6 @@ def test_multilines(runner): @click.command() - @click_log.init() def cli(): test_logger.warning(""" Lorem ipsum dolor sit amet, @@ -50,7 +50,6 @@ def test_unicode(runner): @click.command() - @click_log.init() def cli(): test_logger.error(u""" ❤️ 💔 💌 💕 💞 💓 💗 💖 💘 @@ -66,7 +65,6 @@ def test_weird_types_log(runner): @click.command() - @click_log.init() def cli(): test_logger.error(42) test_logger.error('42') @@ -75,4 +73,33 @@ result = runner.invoke(cli, catch_exceptions=False) assert not result.exception - assert result.output == 'error: 42\n' * 4 + assert set(result.output.splitlines()) <= set(('error: 42', 'error: b\'42\'')) + + +def test_early_logging(runner): + i = None + + def callback(context, param, value): + test_logger.debug('catch me {}!'.format(i)) + + @click.command() + @click_log.simple_verbosity_option(test_logger) + @click.option('--config', is_eager=True, default=None, expose_value=False, + callback=callback) + def cli(): + test_logger.debug('hello') + + for i in range(2): + result = runner.invoke(cli, ['-v', 'debug'], catch_exceptions=False) + assert 'debug: hello' in result.output + assert 'debug: catch me {}!'.format(i) in result.output + + +def test_logging_args(runner): + @click.command() + @click_log.simple_verbosity_option(test_logger) + def cli(): + test_logger.debug('hello %s', 'world') + + result = runner.invoke(cli, ['-v', 'debug']) + assert 'debug: hello world' in result.output