Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 1 addition & 4 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,10 @@ sudo: false
language: python
os: linux
python:
- 2.7
- 3.4
- 3.5
- 3.6
- &mainstream_python 3.7-dev
- &pypy pypy
- pypy3.5
- &pypy pypy3.5
install:
- &upgrade_python_toolset pip install --upgrade pip setuptools wheel
- pip install tox-travis
Expand Down
2 changes: 0 additions & 2 deletions CI_REQUIREMENTS.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1 @@
funcsigs >= 1.0
mock; python_version == "2.7"
-r requirements.txt
8 changes: 2 additions & 6 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -39,14 +39,13 @@ Pros:

::

Python 2.7
Python 3.4
Python 3.5
Python 3.6
Python 3.7
PyPy
PyPy3 3.5+

.. note:: Python 3.4 and 2.7 is supported in versions < 5.0.0

This package includes helpers:

* `logwrap` - main helper. The same is `LogWrap`.
Expand Down Expand Up @@ -207,7 +206,6 @@ Signature is self-documenting:
no_indent_start=False, # do not indent the first level
max_indent=20, # maximum allowed indent level
indent_step=4, # step between indents
py2_str=False, # use bytes for python 2 __repr__ and __str__
)

Limitation: Dict like objects is always marked inside `{}` for readability, even if it is `collections.OrderedDict` (standard repr as list of tuples).
Expand All @@ -225,7 +223,6 @@ Signature is self-documenting:
no_indent_start=False, # do not indent the first level
max_indent=20, # maximum allowed indent level
indent_step=4, # step between indents
py2_str=False, # use bytes for python 2 __repr__ and __str__
)

Limitations:
Expand All @@ -248,7 +245,6 @@ Object signature:
self,
max_indent=20, # maximum allowed indent level
indent_step=4, # step between indents
py2_str=False, # use bytes for python 2 __repr__ and __str__
)

Callable object (`PrettyFormat` instance) signature:
Expand Down
14 changes: 1 addition & 13 deletions appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,6 @@ environment:
secure: TCKGf77kkVeo2Pbd+lQY5Q==

matrix:
- PYTHON: "C:\\Python27-x64"
PYTHON_VERSION: "2.7.x" # currently 2.7.11
PYTHON_ARCH: "64"

- PYTHON: "C:\\Python34"
PYTHON_VERSION: "3.4.x" # currently 3.4.3
PYTHON_ARCH: "32"

- PYTHON: "C:\\Python34-x64"
PYTHON_VERSION: "3.4.x" # currently 3.4.3
PYTHON_ARCH: "64"

- PYTHON: "C:\\Python35"
PYTHON_VERSION: "3.5.x" # currently 3.5.1
PYTHON_ARCH: "32"
Expand Down Expand Up @@ -54,7 +42,7 @@ install:
- pip install pytest pytest-sugar
- pip install -r build_requirements.txt

build: false
build: off
cache:
- '%LOCALAPPDATA%\pip\Cache'

Expand Down
36 changes: 9 additions & 27 deletions doc/source/PrettyFormat.rst
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,12 @@ API: Helpers: `pretty_repr`, `pretty_str` and base class `PrettyFormat`.
.. py:module:: logwrap
.. py:currentmodule:: logwrap

.. py:function:: pretty_repr(src, indent=0, no_indent_start=False, max_indent=20, indent_step=4, py2_str=False, )
.. py:function:: pretty_repr(src, indent=0, no_indent_start=False, max_indent=20, indent_step=4, )

Make human readable repr of object.

:param src: object to process
:type src: typing.Union[
typing.AnyStr, int, typing.Iterable, object
]
:type src: typing.Any
:param indent: start indentation, all next levels is +indent_step
:type indent: int
:param no_indent_start: do not indent open bracket and simple parameters
Expand All @@ -22,22 +20,18 @@ API: Helpers: `pretty_repr`, `pretty_str` and base class `PrettyFormat`.
:type max_indent: int
:param indent_step: step for the next indentation level
:type indent_step: int
:param py2_str: use Python 2.x compatible strings instead of unicode
:type py2_str: bool
:return: formatted string
:rtype: str


.. py:function:: pretty_str(src, indent=0, no_indent_start=False, max_indent=20, indent_step=4, py2_str=False, )
.. py:function:: pretty_str(src, indent=0, no_indent_start=False, max_indent=20, indent_step=4, )

Make human readable str of object.

.. versionadded:: 1.1.0

:param src: object to process
:type src: typing.Union[
typing.AnyStr, int, typing.Iterable, object
]
:type src: typing.Any
:param indent: start indentation, all next levels is +indent_step
:type indent: int
:param no_indent_start: do not indent open bracket and simple parameters
Expand All @@ -46,8 +40,6 @@ API: Helpers: `pretty_repr`, `pretty_str` and base class `PrettyFormat`.
:type max_indent: int
:param indent_step: step for the next indentation level
:type indent_step: int
:param py2_str: use Python 2.x compatible strings instead of unicode
:type py2_str: bool
:return: formatted string
:rtype: str

Expand All @@ -59,14 +51,12 @@ API: Helpers: `pretty_repr`, `pretty_str` and base class `PrettyFormat`.
.. versionadded:: 1.0.2
.. versionchanged:: 3.0.1

.. py:method:: __init__(max_indent=20, indent_step=4, py2_str=False, )
.. py:method:: __init__(max_indent=20, indent_step=4, )

:param max_indent: maximal indent before classic repr() call
:type max_indent: int
:param indent_step: step for the next indentation level
:type indent_step: int
:param py2_str: use Python 2.x compatible strings instead of unicode
:type py2_str: bool

.. note:: Attributes is read-only

Expand All @@ -89,9 +79,7 @@ API: Helpers: `pretty_repr`, `pretty_str` and base class `PrettyFormat`.
Make human readable representation of object.

:param src: object to process
:type src: typing.Union[
typing.AnyStr, int, typing.Iterable, object
]
:type src: typing.Any
:param indent: start indentation
:type indent: int
:param no_indent_start:
Expand All @@ -105,9 +93,7 @@ API: Helpers: `pretty_repr`, `pretty_str` and base class `PrettyFormat`.
Make human readable representation of object. The main entry point.

:param src: object to process
:type src: typing.Union[
typing.AnyStr, int, typing.Iterable, object
]
:type src: typing.Any
:param indent: start indentation
:type indent: int
:param no_indent_start:
Expand All @@ -124,14 +110,12 @@ API: Helpers: `pretty_repr`, `pretty_str` and base class `PrettyFormat`.
.. versionadded:: 3.0.0
.. versionchanged:: 3.0.1

.. py:method:: __init__(max_indent=20, indent_step=4, py2_str=False, )
.. py:method:: __init__(max_indent=20, indent_step=4, )

:param max_indent: maximal indent before classic repr() call
:type max_indent: int
:param indent_step: step for the next indentation level
:type indent_step: int
:param py2_str: use Python 2.x compatible strings instead of unicode
:type py2_str: bool


.. py:class:: PrettyStr(PrettyFormat)
Expand All @@ -141,11 +125,9 @@ API: Helpers: `pretty_repr`, `pretty_str` and base class `PrettyFormat`.
.. versionadded:: 3.0.0
.. versionchanged:: 3.0.1

.. py:method:: __init__(max_indent=20, indent_step=4, py2_str=False, )
.. py:method:: __init__(max_indent=20, indent_step=4, )

:param max_indent: maximal indent before classic repr() call
:type max_indent: int
:param indent_step: step for the next indentation level
:type indent_step: int
:param py2_str: use Python 2.x compatible strings instead of unicode
:type py2_str: bool
17 changes: 2 additions & 15 deletions logwrap/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,27 +22,14 @@
later it has been reworked and extended for support of special cases.
"""

from __future__ import absolute_import

import sys

from ._repr_utils import (
PrettyFormat,
PrettyRepr,
PrettyStr,
pretty_repr,
pretty_str
)
from ._log_wrap_shared import BoundParameter, bind_args_kwargs

PY3 = sys.version_info[:2] > (3, 0) # type: bool

# pylint: disable=no-name-in-module
if PY3: # pragma: no cover
from ._log_wrap3 import logwrap, LogWrap
else: # pragma: no cover
from ._log_wrap2 import logwrap, LogWrap
# pylint: enable=no-name-in-module
from ._log_wrap import logwrap, LogWrap, BoundParameter, bind_args_kwargs

__all__ = (
'LogWrap',
Expand All @@ -56,7 +43,7 @@
'bind_args_kwargs'
)

__version__ = '4.0.1'
__version__ = '5.0.0'
__author__ = "Alexey Stepanov"
__author_email__ = 'penguinolog@gmail.com'
__maintainers__ = {
Expand Down
44 changes: 21 additions & 23 deletions logwrap/_class_decorator.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,12 @@

"""Base class for decorators."""

from __future__ import absolute_import
from __future__ import print_function

import abc
import functools
import typing # noqa # pylint: disable=unused-import

import six
import typing


class BaseDecorator(six.with_metaclass(abc.ABCMeta, object)):
class BaseDecorator(metaclass=abc.ABCMeta):
"""Base class for decorators.

Implements wrapping and __call__, wrapper getter is abstract.
Expand Down Expand Up @@ -69,27 +64,25 @@ class BaseDecorator(six.with_metaclass(abc.ABCMeta, object)):

def __init__(
self,
func=None # type: typing.Optional[typing.Callable]
): # type: (...) -> None
func: typing.Optional[typing.Callable] = None
) -> None:
"""Decorator.

:param func: function to wrap
:type func: typing.Optional[typing.Callable]
"""
# noinspection PyArgumentList
super(BaseDecorator, self).__init__()
# pylint: disable=assigning-non-slot
self.__func = func # type: typing.Optional[typing.Callable]
if self.__func is not None:
functools.update_wrapper(self, self.__func)
if not six.PY3: # pragma: no cover
self.__wrapped__ = self.__func # type: typing.Callable
# pylint: enable=assigning-non-slot
# noinspection PyArgumentList
super(BaseDecorator, self).__init__()

@property
def _func(
self
): # type: () -> typing.Optional[typing.Callable]
) -> typing.Optional[typing.Callable]:
"""Get wrapped function.

:rtype: typing.Optional[typing.Callable]
Expand All @@ -99,8 +92,8 @@ def _func(
@abc.abstractmethod
def _get_function_wrapper(
self,
func # type: typing.Callable
): # type: (...) -> typing.Callable
func: typing.Callable
) -> typing.Callable:
"""Here should be constructed and returned real decorator.

:param func: Wrapped function
Expand All @@ -111,18 +104,23 @@ def _get_function_wrapper(

def __call__(
self,
*args, # type: typing.Any
**kwargs # type: typing.Any
): # type: (...) -> typing.Any
*args: typing.Union[typing.Tuple, typing.Callable],
**kwargs: typing.Dict
) -> typing.Any:
"""Main decorator getter."""
args = list(args)
wrapped = self.__func or args.pop(0)
l_args = list(args)

if self._func:
wrapped = self._func # type: typing.Callable
else:
wrapped = l_args.pop(0) # type: ignore

wrapper = self._get_function_wrapper(wrapped)
if self.__func:
return wrapper(*args, **kwargs)
return wrapper(*l_args, **kwargs)
return wrapper

def __repr__(self):
def __repr__(self) -> str:
"""For debug purposes."""
return "<{cls}({func!r}) at 0x{id:X}>".format(
cls=self.__class__.__name__,
Expand Down
14 changes: 0 additions & 14 deletions logwrap/_class_decorator.pyi

This file was deleted.

Loading