Skip to content

Commit

Permalink
Merge branch 'master' of github.com:nicfit/nicfit.py into devel
Browse files Browse the repository at this point in the history
* 'master' of github.com:nicfit/nicfit.py:
  Update tox from 2.8.2 to 2.9.0 (#152)
  Update pip-tools from 1.9.0 to 1.10.1 (#151)
  Update sphinx from 1.6.3 to 1.6.4 (#149)
  new: :class:`nicfit.logger.FileConfig` supports instance creation and better utilities for updating config.
  new: The companion to ``getlist`` :meth:`Config.setlist`
  chg:  pdb_opt (i.e. --pdb)a addded by default.
  chg: Python versin defaults and Trav-CI job ordering
  Update pytest-asyncio from 0.7.0 to 0.8.0 (#148)
  pep8.  !wip
  Release prep.  !wip
  fix: typo for nicfiut CC.
  chg: :meth:`nicfit.util.debugger` or set_trace/post_mortem {ipdb|pdb}
  Pin sphinx_rtd_theme to latest version 0.2.4 (#147)
  Release prep. !wip
  chg: Added README to dock title.
  new: sphinx_rtd_theme
  Update babel to 2.5.1 (#144)
  • Loading branch information
nicfit committed Oct 1, 2017
2 parents f0b0689 + b114ab3 commit 0e85bfa
Show file tree
Hide file tree
Showing 18 changed files with 157 additions and 53 deletions.
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ python:
- "3.5"
- "3.6"
- "3.7-dev"
- "pypy3"

cache:
pip: true
Expand Down
39 changes: 39 additions & 0 deletions HISTORY.rst
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,45 @@ Release History

.. :changelog:
v0.6.5 (2017-09-21)
------------------------

Fix
~~~
- Typo for nicfit.py[cookiecutter] dev.txt requirement.



v0.6.4 (2017-09-18)
-------------------

New
~~~
- Added :func:`nicfit.command.register` decorator as class member to
:class:`nicfit.command.Command`; less to import for convenience.
- Added ``nicfit[cookiecutter]`` to dev requirements.
- Docs use Sphinx_rtd_theme.

Changes
~~~~~~~
- Added README to dock title.
- Removed servedocs Makefile target.
- Use nicfit.py's ArgumentParser for subparsers and commands.
- Use ``print`` instead of logging for uncaught exceptions.

Other
~~~~~
- Update babel to 2.5.1 (#144) <[email protected]>
- Update tox from 2.8.1 to 2.8.2 (#141) <[email protected]>
- Update pytest-asyncio from 0.6.0 to 0.7.0 (#140) <[email protected]>
- Update wheel from 0.29.0 to 0.30.0 (#142) <[email protected]>
- Update pytest-runner from 2.12 to 2.12.1 (#138) <[email protected]>
- Update pytest from 3.2.1 to 3.2.2 (#139) <[email protected]>
- Update tox from 2.8.0 to 2.8.1 (#137) <[email protected]>
- Pin deprecation to latest version 1.0.1 (#136) <[email protected]>
- Pin pss to latest version 1.41 (#135) <[email protected]>


v0.6.3 (2017-09-03)
--------------------

Expand Down
6 changes: 3 additions & 3 deletions README.rst
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
==========
nicfit.py
==========
=================
nicfit.py README
=================

Common Python utils (App, logging, config, etc.)

Expand Down
2 changes: 1 addition & 1 deletion cookiecutter/cookiecutter.json
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@
"pypy": ["no", "yes"],
"py33": ["no", "yes"],
"py34": ["no", "yes"],
"py35": ["yes", "no"],
"py35": ["no", "no"],
"py36": ["yes", "no"],
"py37": ["yes", "no"],
"pypy3": ["yes", "no"],
Expand Down
24 changes: 15 additions & 9 deletions cookiecutter/{{cookiecutter.project_name}}/.travis.yml
Original file line number Diff line number Diff line change
@@ -1,27 +1,33 @@
language: python

python:
{%- if cookiecutter.py26 == "yes" %}
- "2.6"
{%- if cookiecutter.py36 == "yes" %}
- "3.6"
{%- endif %}
{%- if cookiecutter.py27 == "yes" %}
- "2.7"
{%- endif %}
{%- if cookiecutter.py33 == "yes" %}
- "3.3"
{%- if cookiecutter.py35 == "yes" %}
- "3.5"
{%- endif %}
{%- if cookiecutter.py34 == "yes" %}
- "3.4"
{%- endif %}
{%- if cookiecutter.py35 == "yes" %}
- "3.5"
{%- endif %}
{%- if cookiecutter.py36 == "yes" %}
- "3.6"
{%- if cookiecutter.py33 == "yes" %}
- "3.3"
{%- endif %}
{%- if cookiecutter.py37 == "yes" %}
- "3.7-dev"
{%- endif %}
{%- if cookiecutter.py26 == "yes" %}
- "2.6"
{%- endif %}
{%- if cookiecutter.pypy3 == "yes" %}
- "pypy3"
{%- endif %}
{%- if cookiecutter.pypy == "yes" %}
- "pypy"
{%- endif %}

cache:
pip: true
Expand Down
2 changes: 1 addition & 1 deletion cookiecutter/{{cookiecutter.project_name}}/README.rst
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
===============================
{{ cookiecutter.project_name }}
{{ cookiecutter.project_name }} README
===============================

{{ cookiecutter.project_short_description}}
Expand Down
4 changes: 1 addition & 3 deletions cookiecutter/{{cookiecutter.project_name}}/docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,9 +112,7 @@

# -- Options for HTML output -------------------------------------------

# The theme to use for HTML and HTML Help pages. See the documentation for
# a list of builtin themes.
html_theme = 'alabaster'
html_theme = 'sphinx_rtd_theme'

# Theme options are theme-specific and customize the look and feel of a
# theme further. For a list of options available for each theme, see the
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,9 @@ test:
{%- endif %}

dev:
- nicfit[cookiecutter]
- nicfit.py[cookiecutter]
- Sphinx
- sphinx_rtd_theme
{%- if cookiecutter.gettext_domain != "None" %}
- babel
{%- endif %}
Expand Down
4 changes: 1 addition & 3 deletions docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,9 +112,7 @@

# -- Options for HTML output -------------------------------------------

# The theme to use for HTML and HTML Help pages. See the documentation for
# a list of builtin themes.
html_theme = 'alabaster'
html_theme = 'sphinx_rtd_theme'

# Theme options are theme-specific and customize the look and feel of a
# theme further. For a list of options available for each theme, see the
Expand Down
3 changes: 3 additions & 0 deletions nicfit/_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,9 @@ def getlist(self, section, option, *, raw=False, vars=None,
values += [s.strip() for s in line.split(",")]
return values

def setlist(self, section, option, value, *, delim=", "):
self.set(section, option, delim.join(value))

def read(self, filenames=None, encoding=None, touch=False):
super().read(filenames or [], encoding=encoding)

Expand Down
13 changes: 2 additions & 11 deletions nicfit/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,7 @@

from .logger import getLogger
from ._argparse import ArgumentParser
from .util import initGetText

try:
import ipdb as _debugger
except ImportError: # pragma: nocover
import pdb as _debugger
def _pdb(): # noqa: E302
e, m, tb = sys.exc_info()
_debugger.post_mortem(tb)

from .util import initGetText, debugger

log = getLogger(__name__)

Expand Down Expand Up @@ -96,7 +87,7 @@ def run(self, args_list=None):
print("Uncaught exception", file=sys.stderr)
traceback.print_exc()
if "debug_pdb" in self.args and self.args.debug_pdb:
_pdb()
debugger()
retval = Application.UNCAUGHT_EXCEPTION_EXIT
raise
finally:
Expand Down
74 changes: 62 additions & 12 deletions nicfit/logger.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,11 @@
import logging
import logging.config
from io import StringIO
from textwrap import dedent

from deprecation import deprecated
from .__about__ import __version__
from ._config import Config

__all__ = ["stdout", "stderr", "FileConfig", "DictConfig"]

Expand Down Expand Up @@ -56,7 +58,10 @@ def _initConsoleLogger(name, level, handler=None):
except ImportError:
progress = None

LOG_FORMAT = "[%(asctime)s] %(name)-25s [%(levelname)-8s]: %(message)s"
DEFAULT_LEVEL = "WARN"
DEFAULT_FORMAT = "[%(asctime)s] %(name)-25s [%(levelname)-8s]: %(message)s"
LOG_FORMAT = DEFAULT_FORMAT
"""XXX: prefer DEFAULT_FORMAT over LOG_FORMAT"""

logging.VERBOSE = logging.DEBUG + ((logging.INFO - logging.DEBUG) // 2)
logging.addLevelName(logging.VERBOSE, "VERBOSE")
Expand Down Expand Up @@ -230,9 +235,11 @@ def PKG_LOGGING_CONFIG(pkg_logger, propagate=True,
}


class FileConfig:
class FileConfig(Config):

@staticmethod
def DEFAULT_LOGGING_CONFIG(level="WARN", format=LOG_FORMAT):
def DEFAULT_LOGGING_CONFIG(level=DEFAULT_LEVEL,
format=DEFAULT_FORMAT):
"""Returns a default logging config in file (ini) format.
Compatible with logging.config.fileConfig(), this default set the root
Expand Down Expand Up @@ -268,15 +275,58 @@ class = StreamHandler

@staticmethod
def PKG_LOGGING_CONFIG(pkg_logger, propagate=True, pkg_level="NOTSET"):
return """
[logger_{pkg_logger}]
level = {pkg_level}
qualname = {pkg_logger}
; When adding more specific handlers than what exists on the root you'll
; likely want to set propagate to false.
propagate = {propagate}
handlers =
""".format(**locals())
return dedent(f"""
[logger_{pkg_logger}]
level = {pkg_level}
qualname = {pkg_logger}
propagate = {1 if propagate else 0}
handlers =
""")

@staticmethod
def HANDLER_LOGGING_CONFIG(name, class_=True, args=tuple([]),
level="NOTSET", formatter="generic"):
return dedent(f"""
[handler_{name}]
class = {class_}
args = {args}
level = {level}
formatter = {formatter}
""")

def __init__(self, level=DEFAULT_LEVEL, format=DEFAULT_FORMAT):
super().__init__(None)

self.read_string(self.DEFAULT_LOGGING_CONFIG(level=level,
format=format))

def addPackageLogger(self, pkg_logger, propagate=True, pkg_level="NOTSET"):
self.read_string(self.PKG_LOGGING_CONFIG(pkg_logger=pkg_logger,
propagate=propagate,
pkg_level=pkg_level))
loggers = self.getlist("loggers", "keys")
if pkg_logger not in loggers:
loggers.append(pkg_logger)
self.setlist("loggers", "keys", loggers)

return self

def addHandler(self, name, class_=True, args=tuple([]), level="NOTSET",
formatter="generic"):
self.read_string(self.HANDLER_LOGGING_CONFIG(name, class_, args,
level, formatter))
handlers = self.getlist("handlers", "keys")
if name not in handlers:
handlers.append(name)
self.setlist("handlers", "keys", handlers)

return self

def __str__(self):
out = StringIO()
self.write(out)
out.seek(0)
return out.read()


@deprecated(details="Use FileConfig.DEFAULT_LOGGING_CONFIG",
Expand Down
17 changes: 16 additions & 1 deletion nicfit/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,11 @@
import gettext
import contextlib
from pathlib import Path

from .logger import getLogger
try:
import ipdb as _debugger
except ImportError: # pragma: nocover
import pdb as _debugger

log = getLogger(__name__)

Expand Down Expand Up @@ -87,3 +90,15 @@ def initGetText(domain, install=False, fallback=True):
gettext.install(domain, str(locale_dir), names=["ngettext"])

return translation


def debugger():
"""If called in the context of an exception, calls post_mortem; otherwise
set_trace.
``ipdb`` is preferred over ``pdb`` if installed.
"""
e, m, tb = sys.exc_info()
if tb is not None:
_debugger.post_mortem(tb)
else:
_debugger.set_trace()
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,5 @@ jinja2==2.9.6 # via cookiecutter, jinja2-time
markupsafe==1.0 # via jinja2
poyo==0.4.1 # via cookiecutter
python-dateutil==2.6.1 # via arrow
six==1.10.0 # via python-dateutil
six==1.11.0 # via python-dateutil
whichcraft==0.4.1 # via cookiecutter
9 changes: 5 additions & 4 deletions requirements/dev.txt
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
Sphinx==1.6.3
babel==2.5.0
Sphinx==1.6.4
babel==2.5.1
check-manifest==0.35
flake8==3.4.1
git+https://github.com/nicfit/gitchangelog.git
ipdb==0.10.3
pip-tools==1.9.0
pip-tools==1.10.1
pss==1.41
pyaml==17.8.0
tox==2.8.2
sphinx_rtd_theme==0.2.4
tox==2.9.0
twine==1.9.1
wheel==0.30.0
1 change: 1 addition & 0 deletions requirements/requirements.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ test:

dev:
- Sphinx
- sphinx_rtd_theme
- babel
- check-manifest
- flake8
Expand Down
4 changes: 2 additions & 2 deletions requirements/test.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
babel==2.5.0
babel==2.5.1
pytest==3.2.2
pytest-asyncio==0.7.0
pytest-asyncio==0.8.0
pytest-cov==2.5.1
pytest-curio==0.1.0
pytest-runner==2.12.1
2 changes: 1 addition & 1 deletion tests/test_application.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ def test_pdb():
app = Application(pdb_opt=True)
app._main = Mock(side_effect=ValueError)

with patch.object(nicfit.app._debugger, "post_mortem") as mock_pm:
with patch.object(nicfit.util._debugger, "post_mortem") as mock_pm:
try:
app.run(["--pdb"])
except SystemExit:
Expand Down

0 comments on commit 0e85bfa

Please sign in to comment.