[Python-modules-commits] [python-click-log] 01/08: Import python-click-log_0.1.4.orig.tar.gz

Filip Pytloun fpytloun-guest at moszumanska.debian.org
Tue Aug 9 10:06:06 UTC 2016


This is an automated email from the git hooks/post-receive script.

fpytloun-guest pushed a commit to branch master
in repository python-click-log.

commit b7bba0cc50184fa9933a022543b19175cf5a1593
Author: Filip Pytloun <filip at pytloun.cz>
Date:   Tue Aug 9 11:25:57 2016 +0200

    Import python-click-log_0.1.4.orig.tar.gz
---
 .gitignore            |  11 ++
 .travis.yml           |  10 ++
 LICENSE               |  19 ++++
 MANIFEST.in           |   8 ++
 Makefile              |   2 +
 README.rst            |  15 +++
 click_log/__init__.py |  21 ++++
 click_log/core.py     | 104 +++++++++++++++++++
 click_log/options.py  |  35 +++++++
 docs/Makefile         | 230 +++++++++++++++++++++++++++++++++++++++++
 docs/conf.py          |  59 +++++++++++
 docs/index.rst        | 126 ++++++++++++++++++++++
 docs/make.bat         | 281 ++++++++++++++++++++++++++++++++++++++++++++++++++
 setup.cfg             |   6 ++
 setup.py              |  27 +++++
 tests/test_basic.py   |  28 +++++
 tox.ini               |   6 ++
 17 files changed, 988 insertions(+)

diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..ce68b0a
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1,11 @@
+.DS_Store
+*.pyc
+*.pyo
+*.egg-ignore
+*.egg-info
+dist
+build/
+docs/_build
+click.egg-info
+.tox
+.cache
diff --git a/.travis.yml b/.travis.yml
new file mode 100644
index 0000000..dfb9017
--- /dev/null
+++ b/.travis.yml
@@ -0,0 +1,10 @@
+language: python
+
+python:
+    - 2.7
+    - pypy
+    - 3.3
+    - 3.4
+
+install: pip install tox
+script: tox
diff --git a/LICENSE b/LICENSE
new file mode 100644
index 0000000..ab35c0e
--- /dev/null
+++ b/LICENSE
@@ -0,0 +1,19 @@
+Copyright (c) 2014-2015 Markus Unterwaditzer & contributors
+
+Permission is hereby granted, free of charge, to any person obtaining a copy of
+this software and associated documentation files (the "Software"), to deal in
+the Software without restriction, including without limitation the rights to
+use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
+of the Software, and to permit persons to whom the Software is furnished to do
+so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in all
+copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+SOFTWARE.
diff --git a/MANIFEST.in b/MANIFEST.in
new file mode 100644
index 0000000..2815065
--- /dev/null
+++ b/MANIFEST.in
@@ -0,0 +1,8 @@
+include LICENSE
+include Makefile
+
+recursive-include docs *
+recursive-include tests *
+prune docs/_build
+
+global-exclude *.py[cdo] __pycache__ *.so *.pyd
diff --git a/Makefile b/Makefile
new file mode 100644
index 0000000..d257e7b
--- /dev/null
+++ b/Makefile
@@ -0,0 +1,2 @@
+release:
+	python setup.py sdist bdist_wheel upload
diff --git a/README.rst b/README.rst
new file mode 100644
index 0000000..ffe30d1
--- /dev/null
+++ b/README.rst
@@ -0,0 +1,15 @@
+click-log
+=========
+
+.. image:: https://travis-ci.org/click-contrib/click-log.svg?branch=master
+    :target: https://travis-ci.org/click-contrib/click-log
+
+Integrates logging with click.
+
+- `Documentation <https://click-log.readthedocs.org/>`_
+- `Source code <https://github.com/click-contrib/click-log>`_
+
+License
+=======
+
+Licensed under the MIT, see ``LICENSE``.
diff --git a/click_log/__init__.py b/click_log/__init__.py
new file mode 100644
index 0000000..51ac26a
--- /dev/null
+++ b/click_log/__init__.py
@@ -0,0 +1,21 @@
+# -*- coding: utf-8 -*-
+# flake8: noqa
+
+import click
+
+__version__ = '0.1.4'
+
+
+if not hasattr(click, 'get_current_context'):
+    raise RuntimeError('You need Click 5.0.')
+
+from .core import (
+    ClickHandler,
+    ColorFormatter,
+    basic_config,
+    get_level,
+    init,
+    set_level,
+)
+
+from .options import simple_verbosity_option
diff --git a/click_log/core.py b/click_log/core.py
new file mode 100644
index 0000000..12efa6b
--- /dev/null
+++ b/click_log/core.py
@@ -0,0 +1,104 @@
+# -*- coding: utf-8 -*-
+
+import functools
+import logging
+
+import click
+
+_ctx = click.get_current_context
+
+LOGGER_KEY = __name__ + '.logger'
+DEFAULT_LEVEL = logging.INFO
+
+
+def _meta():
+    return _ctx().meta.setdefault(LOGGER_KEY, {})
+
+
+class ColorFormatter(logging.Formatter):
+    colors = {
+        'error': dict(fg='red'),
+        'exception': dict(fg='red'),
+        'critical': dict(fg='red'),
+        'debug': dict(fg='blue'),
+        'warning': dict(fg='yellow')
+    }
+
+    def format(self, record):
+        if not record.exc_info:
+            level = record.levelname.lower()
+            if level in self.colors:
+                prefix = click.style('{}: '.format(level),
+                                     **self.colors[level])
+                record.msg = '\n'.join(prefix + x
+                                       for x in str(record.msg).splitlines())
+
+        return logging.Formatter.format(self, record)
+
+
+class ClickHandler(logging.Handler):
+    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:
+            self.handleError(record)
+
+
+_default_handler = ClickHandler()
+_default_handler.formatter = ColorFormatter()
+
+
+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.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 --git a/click_log/options.py b/click_log/options.py
new file mode 100644
index 0000000..5af92f3
--- /dev/null
+++ b/click_log/options.py
@@ -0,0 +1,35 @@
+import logging
+
+import click
+
+from .core import set_level
+
+
+def simple_verbosity_option(*names, **kwargs):
+    '''A decorator that adds a `--verbosity, -v` option to the decorated
+    command.
+
+    Name can be configured through ``*names``. Keyword arguments are passed to
+    the underlying ``click.option`` decorator.
+    '''
+
+    if not names:
+        names = ['--verbosity', '-v']
+
+    kwargs.setdefault('default', 'INFO')
+    kwargs.setdefault('metavar', 'LVL')
+    kwargs.setdefault('expose_value', False)
+    kwargs.setdefault('help', 'Either CRITICAL, ERROR, WARNING, INFO or DEBUG')
+    kwargs.setdefault('is_eager', True)
+
+    def decorator(f):
+        def _set_level(ctx, param, value):
+            x = getattr(logging, value.upper(), None)
+            if x is None:
+                raise click.BadParameter(
+                    'Must be CRITICAL, ERROR, WARNING, INFO or DEBUG, not {}'
+                )
+            set_level(x)
+
+        return click.option(*names, callback=_set_level, **kwargs)(f)
+    return decorator
diff --git a/docs/Makefile b/docs/Makefile
new file mode 100644
index 0000000..134e5db
--- /dev/null
+++ b/docs/Makefile
@@ -0,0 +1,230 @@
+# Makefile for Sphinx documentation
+#
+
+# You can set these variables from the command line.
+SPHINXOPTS    =
+SPHINXBUILD   = sphinx-build
+PAPER         =
+BUILDDIR      = _build
+
+# User-friendly check for sphinx-build
+ifeq ($(shell which $(SPHINXBUILD) >/dev/null 2>&1; echo $$?), 1)
+	$(error The '$(SPHINXBUILD)' command was not found. Make sure you have Sphinx installed, then set the SPHINXBUILD environment variable to point to the full path of the '$(SPHINXBUILD)' executable. Alternatively you can add the directory with the executable to your PATH. If you don\'t have Sphinx installed, grab it from http://sphinx-doc.org/)
+endif
+
+# Internal variables.
+PAPEROPT_a4     = -D latex_paper_size=a4
+PAPEROPT_letter = -D latex_paper_size=letter
+ALLSPHINXOPTS   = -d $(BUILDDIR)/doctrees $(PAPEROPT_$(PAPER)) $(SPHINXOPTS) .
+# the i18n builder cannot share the environment and doctrees with the others
+I18NSPHINXOPTS  = $(PAPEROPT_$(PAPER)) $(SPHINXOPTS) .
+
+.PHONY: help
+help:
+	@echo "Please use \`make <target>' where <target> is one of"
+	@echo "  html       to make standalone HTML files"
+	@echo "  dirhtml    to make HTML files named index.html in directories"
+	@echo "  singlehtml to make a single large HTML file"
+	@echo "  pickle     to make pickle files"
+	@echo "  json       to make JSON files"
+	@echo "  htmlhelp   to make HTML files and a HTML help project"
+	@echo "  qthelp     to make HTML files and a qthelp project"
+	@echo "  applehelp  to make an Apple Help Book"
+	@echo "  devhelp    to make HTML files and a Devhelp project"
+	@echo "  epub       to make an epub"
+	@echo "  epub3      to make an epub3"
+	@echo "  latex      to make LaTeX files, you can set PAPER=a4 or PAPER=letter"
+	@echo "  latexpdf   to make LaTeX files and run them through pdflatex"
+	@echo "  latexpdfja to make LaTeX files and run them through platex/dvipdfmx"
+	@echo "  text       to make text files"
+	@echo "  man        to make manual pages"
+	@echo "  texinfo    to make Texinfo files"
+	@echo "  info       to make Texinfo files and run them through makeinfo"
+	@echo "  gettext    to make PO message catalogs"
+	@echo "  changes    to make an overview of all changed/added/deprecated items"
+	@echo "  xml        to make Docutils-native XML files"
+	@echo "  pseudoxml  to make pseudoxml-XML files for display purposes"
+	@echo "  linkcheck  to check all external links for integrity"
+	@echo "  doctest    to run all doctests embedded in the documentation (if enabled)"
+	@echo "  coverage   to run coverage check of the documentation (if enabled)"
+	@echo "  dummy      to check syntax errors of document sources"
+
+.PHONY: clean
+clean:
+	rm -rf $(BUILDDIR)/*
+
+.PHONY: html
+html:
+	$(SPHINXBUILD) -b html $(ALLSPHINXOPTS) $(BUILDDIR)/html
+	@echo
+	@echo "Build finished. The HTML pages are in $(BUILDDIR)/html."
+
+.PHONY: dirhtml
+dirhtml:
+	$(SPHINXBUILD) -b dirhtml $(ALLSPHINXOPTS) $(BUILDDIR)/dirhtml
+	@echo
+	@echo "Build finished. The HTML pages are in $(BUILDDIR)/dirhtml."
+
+.PHONY: singlehtml
+singlehtml:
+	$(SPHINXBUILD) -b singlehtml $(ALLSPHINXOPTS) $(BUILDDIR)/singlehtml
+	@echo
+	@echo "Build finished. The HTML page is in $(BUILDDIR)/singlehtml."
+
+.PHONY: pickle
+pickle:
+	$(SPHINXBUILD) -b pickle $(ALLSPHINXOPTS) $(BUILDDIR)/pickle
+	@echo
+	@echo "Build finished; now you can process the pickle files."
+
+.PHONY: json
+json:
+	$(SPHINXBUILD) -b json $(ALLSPHINXOPTS) $(BUILDDIR)/json
+	@echo
+	@echo "Build finished; now you can process the JSON files."
+
+.PHONY: htmlhelp
+htmlhelp:
+	$(SPHINXBUILD) -b htmlhelp $(ALLSPHINXOPTS) $(BUILDDIR)/htmlhelp
+	@echo
+	@echo "Build finished; now you can run HTML Help Workshop with the" \
+	      ".hhp project file in $(BUILDDIR)/htmlhelp."
+
+.PHONY: qthelp
+qthelp:
+	$(SPHINXBUILD) -b qthelp $(ALLSPHINXOPTS) $(BUILDDIR)/qthelp
+	@echo
+	@echo "Build finished; now you can run "qcollectiongenerator" with the" \
+	      ".qhcp project file in $(BUILDDIR)/qthelp, like this:"
+	@echo "# qcollectiongenerator $(BUILDDIR)/qthelp/click-log.qhcp"
+	@echo "To view the help file:"
+	@echo "# assistant -collectionFile $(BUILDDIR)/qthelp/click-log.qhc"
+
+.PHONY: applehelp
+applehelp:
+	$(SPHINXBUILD) -b applehelp $(ALLSPHINXOPTS) $(BUILDDIR)/applehelp
+	@echo
+	@echo "Build finished. The help book is in $(BUILDDIR)/applehelp."
+	@echo "N.B. You won't be able to view it unless you put it in" \
+	      "~/Library/Documentation/Help or install it in your application" \
+	      "bundle."
+
+.PHONY: devhelp
+devhelp:
+	$(SPHINXBUILD) -b devhelp $(ALLSPHINXOPTS) $(BUILDDIR)/devhelp
+	@echo
+	@echo "Build finished."
+	@echo "To view the help file:"
+	@echo "# mkdir -p $$HOME/.local/share/devhelp/click-log"
+	@echo "# ln -s $(BUILDDIR)/devhelp $$HOME/.local/share/devhelp/click-log"
+	@echo "# devhelp"
+
+.PHONY: epub
+epub:
+	$(SPHINXBUILD) -b epub $(ALLSPHINXOPTS) $(BUILDDIR)/epub
+	@echo
+	@echo "Build finished. The epub file is in $(BUILDDIR)/epub."
+
+.PHONY: epub3
+epub3:
+	$(SPHINXBUILD) -b epub3 $(ALLSPHINXOPTS) $(BUILDDIR)/epub3
+	@echo
+	@echo "Build finished. The epub3 file is in $(BUILDDIR)/epub3."
+
+.PHONY: latex
+latex:
+	$(SPHINXBUILD) -b latex $(ALLSPHINXOPTS) $(BUILDDIR)/latex
+	@echo
+	@echo "Build finished; the LaTeX files are in $(BUILDDIR)/latex."
+	@echo "Run \`make' in that directory to run these through (pdf)latex" \
+	      "(use \`make latexpdf' here to do that automatically)."
+
+.PHONY: latexpdf
+latexpdf:
+	$(SPHINXBUILD) -b latex $(ALLSPHINXOPTS) $(BUILDDIR)/latex
+	@echo "Running LaTeX files through pdflatex..."
+	$(MAKE) -C $(BUILDDIR)/latex all-pdf
+	@echo "pdflatex finished; the PDF files are in $(BUILDDIR)/latex."
+
+.PHONY: latexpdfja
+latexpdfja:
+	$(SPHINXBUILD) -b latex $(ALLSPHINXOPTS) $(BUILDDIR)/latex
+	@echo "Running LaTeX files through platex and dvipdfmx..."
+	$(MAKE) -C $(BUILDDIR)/latex all-pdf-ja
+	@echo "pdflatex finished; the PDF files are in $(BUILDDIR)/latex."
+
+.PHONY: text
+text:
+	$(SPHINXBUILD) -b text $(ALLSPHINXOPTS) $(BUILDDIR)/text
+	@echo
+	@echo "Build finished. The text files are in $(BUILDDIR)/text."
+
+.PHONY: man
+man:
+	$(SPHINXBUILD) -b man $(ALLSPHINXOPTS) $(BUILDDIR)/man
+	@echo
+	@echo "Build finished. The manual pages are in $(BUILDDIR)/man."
+
+.PHONY: texinfo
+texinfo:
+	$(SPHINXBUILD) -b texinfo $(ALLSPHINXOPTS) $(BUILDDIR)/texinfo
+	@echo
+	@echo "Build finished. The Texinfo files are in $(BUILDDIR)/texinfo."
+	@echo "Run \`make' in that directory to run these through makeinfo" \
+	      "(use \`make info' here to do that automatically)."
+
+.PHONY: info
+info:
+	$(SPHINXBUILD) -b texinfo $(ALLSPHINXOPTS) $(BUILDDIR)/texinfo
+	@echo "Running Texinfo files through makeinfo..."
+	make -C $(BUILDDIR)/texinfo info
+	@echo "makeinfo finished; the Info files are in $(BUILDDIR)/texinfo."
+
+.PHONY: gettext
+gettext:
+	$(SPHINXBUILD) -b gettext $(I18NSPHINXOPTS) $(BUILDDIR)/locale
+	@echo
+	@echo "Build finished. The message catalogs are in $(BUILDDIR)/locale."
+
+.PHONY: changes
+changes:
+	$(SPHINXBUILD) -b changes $(ALLSPHINXOPTS) $(BUILDDIR)/changes
+	@echo
+	@echo "The overview file is in $(BUILDDIR)/changes."
+
+.PHONY: linkcheck
+linkcheck:
+	$(SPHINXBUILD) -b linkcheck $(ALLSPHINXOPTS) $(BUILDDIR)/linkcheck
+	@echo
+	@echo "Link check complete; look for any errors in the above output " \
+	      "or in $(BUILDDIR)/linkcheck/output.txt."
+
+.PHONY: doctest
+doctest:
+	$(SPHINXBUILD) -b doctest $(ALLSPHINXOPTS) $(BUILDDIR)/doctest
+	@echo "Testing of doctests in the sources finished, look at the " \
+	      "results in $(BUILDDIR)/doctest/output.txt."
+
+.PHONY: coverage
+coverage:
+	$(SPHINXBUILD) -b coverage $(ALLSPHINXOPTS) $(BUILDDIR)/coverage
+	@echo "Testing of coverage in the sources finished, look at the " \
+	      "results in $(BUILDDIR)/coverage/python.txt."
+
+.PHONY: xml
+xml:
+	$(SPHINXBUILD) -b xml $(ALLSPHINXOPTS) $(BUILDDIR)/xml
+	@echo
+	@echo "Build finished. The XML files are in $(BUILDDIR)/xml."
+
+.PHONY: pseudoxml
+pseudoxml:
+	$(SPHINXBUILD) -b pseudoxml $(ALLSPHINXOPTS) $(BUILDDIR)/pseudoxml
+	@echo
+	@echo "Build finished. The pseudo-XML files are in $(BUILDDIR)/pseudoxml."
+
+.PHONY: dummy
+dummy:
+	$(SPHINXBUILD) -b dummy $(ALLSPHINXOPTS) $(BUILDDIR)/dummy
+	@echo
+	@echo "Build finished. Dummy builder generates no files."
diff --git a/docs/conf.py b/docs/conf.py
new file mode 100644
index 0000000..b8085bc
--- /dev/null
+++ b/docs/conf.py
@@ -0,0 +1,59 @@
+# -*- coding: utf-8 -*-
+
+import sys
+import os
+
+import click_log
+
+extensions = ['sphinx.ext.autodoc']
+
+templates_path = ['_templates']
+
+source_suffix = '.rst'
+master_doc = 'index'
+
+project = 'click-log'
+copyright = '2016, Markus Unterwaditzer & contributors'
+author = 'Markus Unterwaditzer & contributors'
+
+release = click_log.__version__
+version = '.'.join(release.split('.')[:2])  # The short X.Y version.
+
+exclude_patterns = ['_build']
+
+pygments_style = 'sphinx'
+
+on_rtd = os.environ.get('READTHEDOCS', None) == 'True'
+
+try:
+    import sphinx_rtd_theme
+    html_theme = 'sphinx_rtd_theme'
+    html_theme_path = [sphinx_rtd_theme.get_html_theme_path()]
+except ImportError:
+    html_theme = 'default'
+    if not on_rtd:
+        print('-' * 74)
+        print('Warning: sphinx-rtd-theme not installed, building with default '
+              'theme.')
+        print('-' * 74)
+
+html_static_path = ['_static']
+htmlhelp_basename = 'click-logdoc'
+
+latex_elements = {}
+
+latex_documents = [
+    (master_doc, 'click-log.tex', 'click-log Documentation',
+     'Markus Unterwaditzer \\& contributors', 'manual'),
+]
+
+man_pages = [
+    (master_doc, 'click-log', 'click-log Documentation',
+     [author], 1)
+]
+
+texinfo_documents = [
+    (master_doc, 'click-log', 'click-log Documentation',
+     author, 'click-log', 'One line description of project.',
+     'Miscellaneous'),
+]
diff --git a/docs/index.rst b/docs/index.rst
new file mode 100644
index 0000000..a6a22da
--- /dev/null
+++ b/docs/index.rst
@@ -0,0 +1,126 @@
+==============================================================
+Click-log: Simple and beautiful logging for click applications
+==============================================================
+
+.. include:: ../README.rst
+
+.. toctree::
+   :maxdepth: 2
+
+.. module:: click_log
+
+Getting started
+===============
+
+Assuming you have this Click application::
+
+    @click.command()
+    def cli():
+        click.echo("Dividing by zero.")
+
+        try:
+            1 / 0
+        except:
+            click.echo("ERROR: Failed to divide by zero.")
+
+
+Ignore the application's core functionality for a moment. The much more
+pressing question here is: How do we add an option to not print anything on
+success? We could try this::
+
+    @click.command()
+    @click.option('--quiet', default=False, is_flag=True)
+    def cli(quiet):
+        if not quiet:
+            click.echo("Dividing by zero.")
+
+        try:
+            1 / 0
+        except:
+            click.echo("ERROR: Failed to divide by zero.")
+
+Wrapping if-statements around each ``echo``-call is cumbersome though. And with
+that, we discover logging::
+
+    import logging
+    logger = logging.getLogger(__name__)
+    # More setup for logging handlers here
+
+    @click.command()
+    @click.option('--quiet', default=False, is_flag=True)
+    def cli(quiet):
+        if quiet:
+            logger.setLevel(logging.ERROR)
+        else:
+            logger.setLevel(logging.INFO)
+
+        ...
+
+Logging is a better solution, but partly because Python's logging module aims
+to be so generic, it doesn't come with sensible defaults for CLI applications.
+At some point you might also want to expose more logging levels through more
+options, at which point the boilerplate code grows even more.
+
+This is where click-log comes in::
+
+    import logging
+    logger = logging.getLogger(__name__)
+
+    @click.command()
+    @click_log.simple_verbosity_option()
+    @click_log.init(__name__)
+    def cli():
+        logger.info("Dividing by zero.")
+
+        try:
+            1 / 0
+        except:
+            logger.error("Failed to divide by zero.")
+
+The output will look like this::
+
+    Dividing by zero.
+    error: Failed to divide by zero.
+
+
+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.
+
+API
+===
+
+.. autofunction:: init
+
+.. autofunction:: simple_verbosity_option
+
+.. autofunction:: basic_config
+
+.. autofunction:: get_level
+
+.. autofunction:: set_level
+
+Classes
+-------
+
+.. autoclass:: ClickHandler
+
+.. autoclass:: ColorFormatter
+
+
+
+Indices and tables
+==================
+
+* :ref:`genindex`
+* :ref:`modindex`
+* :ref:`search`
+
diff --git a/docs/make.bat b/docs/make.bat
new file mode 100644
index 0000000..ec5102e
--- /dev/null
+++ b/docs/make.bat
@@ -0,0 +1,281 @@
+ at ECHO OFF
+
+REM Command file for Sphinx documentation
+
+if "%SPHINXBUILD%" == "" (
+	set SPHINXBUILD=sphinx-build
+)
+set BUILDDIR=_build
+set ALLSPHINXOPTS=-d %BUILDDIR%/doctrees %SPHINXOPTS% .
+set I18NSPHINXOPTS=%SPHINXOPTS% .
+if NOT "%PAPER%" == "" (
+	set ALLSPHINXOPTS=-D latex_paper_size=%PAPER% %ALLSPHINXOPTS%
+	set I18NSPHINXOPTS=-D latex_paper_size=%PAPER% %I18NSPHINXOPTS%
+)
+
+if "%1" == "" goto help
+
+if "%1" == "help" (
+	:help
+	echo.Please use `make ^<target^>` where ^<target^> is one of
+	echo.  html       to make standalone HTML files
+	echo.  dirhtml    to make HTML files named index.html in directories
+	echo.  singlehtml to make a single large HTML file
+	echo.  pickle     to make pickle files
+	echo.  json       to make JSON files
+	echo.  htmlhelp   to make HTML files and a HTML help project
+	echo.  qthelp     to make HTML files and a qthelp project
+	echo.  devhelp    to make HTML files and a Devhelp project
+	echo.  epub       to make an epub
+	echo.  epub3      to make an epub3
+	echo.  latex      to make LaTeX files, you can set PAPER=a4 or PAPER=letter
+	echo.  text       to make text files
+	echo.  man        to make manual pages
+	echo.  texinfo    to make Texinfo files
+	echo.  gettext    to make PO message catalogs
+	echo.  changes    to make an overview over all changed/added/deprecated items
+	echo.  xml        to make Docutils-native XML files
+	echo.  pseudoxml  to make pseudoxml-XML files for display purposes
+	echo.  linkcheck  to check all external links for integrity
+	echo.  doctest    to run all doctests embedded in the documentation if enabled
+	echo.  coverage   to run coverage check of the documentation if enabled
+	echo.  dummy      to check syntax errors of document sources
+	goto end
+)
+
+if "%1" == "clean" (
+	for /d %%i in (%BUILDDIR%\*) do rmdir /q /s %%i
+	del /q /s %BUILDDIR%\*
+	goto end
+)
+
+
+REM Check if sphinx-build is available and fallback to Python version if any
+%SPHINXBUILD% 1>NUL 2>NUL
+if errorlevel 9009 goto sphinx_python
+goto sphinx_ok
+
+:sphinx_python
+
+set SPHINXBUILD=python -m sphinx.__init__
+%SPHINXBUILD% 2> nul
+if errorlevel 9009 (
+	echo.
+	echo.The 'sphinx-build' command was not found. Make sure you have Sphinx
+	echo.installed, then set the SPHINXBUILD environment variable to point
+	echo.to the full path of the 'sphinx-build' executable. Alternatively you
+	echo.may add the Sphinx directory to PATH.
+	echo.
+	echo.If you don't have Sphinx installed, grab it from
+	echo.http://sphinx-doc.org/
+	exit /b 1
+)
+
+:sphinx_ok
+
+
+if "%1" == "html" (
+	%SPHINXBUILD% -b html %ALLSPHINXOPTS% %BUILDDIR%/html
+	if errorlevel 1 exit /b 1
+	echo.
+	echo.Build finished. The HTML pages are in %BUILDDIR%/html.
+	goto end
+)
+
+if "%1" == "dirhtml" (
+	%SPHINXBUILD% -b dirhtml %ALLSPHINXOPTS% %BUILDDIR%/dirhtml
+	if errorlevel 1 exit /b 1
+	echo.
+	echo.Build finished. The HTML pages are in %BUILDDIR%/dirhtml.
+	goto end
+)
+
+if "%1" == "singlehtml" (
+	%SPHINXBUILD% -b singlehtml %ALLSPHINXOPTS% %BUILDDIR%/singlehtml
+	if errorlevel 1 exit /b 1
+	echo.
+	echo.Build finished. The HTML pages are in %BUILDDIR%/singlehtml.
+	goto end
+)
+
+if "%1" == "pickle" (
+	%SPHINXBUILD% -b pickle %ALLSPHINXOPTS% %BUILDDIR%/pickle
+	if errorlevel 1 exit /b 1
+	echo.
+	echo.Build finished; now you can process the pickle files.
+	goto end
+)
+
+if "%1" == "json" (
+	%SPHINXBUILD% -b json %ALLSPHINXOPTS% %BUILDDIR%/json
+	if errorlevel 1 exit /b 1
+	echo.
+	echo.Build finished; now you can process the JSON files.
+	goto end
+)
+
+if "%1" == "htmlhelp" (
+	%SPHINXBUILD% -b htmlhelp %ALLSPHINXOPTS% %BUILDDIR%/htmlhelp
+	if errorlevel 1 exit /b 1
+	echo.
+	echo.Build finished; now you can run HTML Help Workshop with the ^
+.hhp project file in %BUILDDIR%/htmlhelp.
+	goto end
+)
+
+if "%1" == "qthelp" (
+	%SPHINXBUILD% -b qthelp %ALLSPHINXOPTS% %BUILDDIR%/qthelp
+	if errorlevel 1 exit /b 1
+	echo.
+	echo.Build finished; now you can run "qcollectiongenerator" with the ^
+.qhcp project file in %BUILDDIR%/qthelp, like this:
+	echo.^> qcollectiongenerator %BUILDDIR%\qthelp\click-log.qhcp
+	echo.To view the help file:
+	echo.^> assistant -collectionFile %BUILDDIR%\qthelp\click-log.ghc
+	goto end
+)
+
+if "%1" == "devhelp" (
+	%SPHINXBUILD% -b devhelp %ALLSPHINXOPTS% %BUILDDIR%/devhelp
+	if errorlevel 1 exit /b 1
+	echo.
+	echo.Build finished.
+	goto end
+)
+
+if "%1" == "epub" (
+	%SPHINXBUILD% -b epub %ALLSPHINXOPTS% %BUILDDIR%/epub
+	if errorlevel 1 exit /b 1
+	echo.
+	echo.Build finished. The epub file is in %BUILDDIR%/epub.
+	goto end
+)
+
+if "%1" == "epub3" (
+	%SPHINXBUILD% -b epub3 %ALLSPHINXOPTS% %BUILDDIR%/epub3
+	if errorlevel 1 exit /b 1
+	echo.
+	echo.Build finished. The epub3 file is in %BUILDDIR%/epub3.
+	goto end
+)
+
+if "%1" == "latex" (
+	%SPHINXBUILD% -b latex %ALLSPHINXOPTS% %BUILDDIR%/latex
+	if errorlevel 1 exit /b 1
+	echo.
+	echo.Build finished; the LaTeX files are in %BUILDDIR%/latex.
+	goto end
+)
+
+if "%1" == "latexpdf" (
+	%SPHINXBUILD% -b latex %ALLSPHINXOPTS% %BUILDDIR%/latex
+	cd %BUILDDIR%/latex
+	make all-pdf
+	cd %~dp0
+	echo.
+	echo.Build finished; the PDF files are in %BUILDDIR%/latex.
+	goto end
+)
+
+if "%1" == "latexpdfja" (
+	%SPHINXBUILD% -b latex %ALLSPHINXOPTS% %BUILDDIR%/latex
+	cd %BUILDDIR%/latex
+	make all-pdf-ja
+	cd %~dp0
+	echo.
+	echo.Build finished; the PDF files are in %BUILDDIR%/latex.
+	goto end
+)
+
+if "%1" == "text" (
+	%SPHINXBUILD% -b text %ALLSPHINXOPTS% %BUILDDIR%/text
+	if errorlevel 1 exit /b 1
+	echo.
+	echo.Build finished. The text files are in %BUILDDIR%/text.
+	goto end
+)
+
+if "%1" == "man" (
+	%SPHINXBUILD% -b man %ALLSPHINXOPTS% %BUILDDIR%/man
+	if errorlevel 1 exit /b 1
+	echo.
+	echo.Build finished. The manual pages are in %BUILDDIR%/man.
+	goto end
+)
+
+if "%1" == "texinfo" (
+	%SPHINXBUILD% -b texinfo %ALLSPHINXOPTS% %BUILDDIR%/texinfo
+	if errorlevel 1 exit /b 1
+	echo.
+	echo.Build finished. The Texinfo files are in %BUILDDIR%/texinfo.
+	goto end
+)
+
+if "%1" == "gettext" (
+	%SPHINXBUILD% -b gettext %I18NSPHINXOPTS% %BUILDDIR%/locale
+	if errorlevel 1 exit /b 1
+	echo.
+	echo.Build finished. The message catalogs are in %BUILDDIR%/locale.
+	goto end
+)
+
+if "%1" == "changes" (
+	%SPHINXBUILD% -b changes %ALLSPHINXOPTS% %BUILDDIR%/changes
+	if errorlevel 1 exit /b 1
+	echo.
+	echo.The overview file is in %BUILDDIR%/changes.
+	goto end
+)
+
+if "%1" == "linkcheck" (
+	%SPHINXBUILD% -b linkcheck %ALLSPHINXOPTS% %BUILDDIR%/linkcheck
+	if errorlevel 1 exit /b 1
+	echo.
+	echo.Link check complete; look for any errors in the above output ^
+or in %BUILDDIR%/linkcheck/output.txt.
+	goto end
+)
+
+if "%1" == "doctest" (
+	%SPHINXBUILD% -b doctest %ALLSPHINXOPTS% %BUILDDIR%/doctest
+	if errorlevel 1 exit /b 1
+	echo.
+	echo.Testing of doctests in the sources finished, look at the ^
+results in %BUILDDIR%/doctest/output.txt.
+	goto end
+)
+
+if "%1" == "coverage" (
+	%SPHINXBUILD% -b coverage %ALLSPHINXOPTS% %BUILDDIR%/coverage
+	if errorlevel 1 exit /b 1
+	echo.
+	echo.Testing of coverage in the sources finished, look at the ^
+results in %BUILDDIR%/coverage/python.txt.
+	goto end
+)
+
+if "%1" == "xml" (
... 115 lines suppressed ...

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/python-modules/packages/python-click-log.git



More information about the Python-modules-commits mailing list