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
1 change: 1 addition & 0 deletions MANIFEST.in
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
include *.rst LICENSE requirements.txt
global-include *.pyx *.pxd
global-exclude *.c
exclude Makefile
prune tools
Expand Down
2 changes: 1 addition & 1 deletion build_requirements.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Cython; platform_python_implementation == "CPython"
wheel
wheel<0.32.0
-r CI_REQUIREMENTS.txt
-r requirements.txt
1 change: 1 addition & 0 deletions logwrap/__init__.pxd
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
cdef tuple __all__
6 changes: 3 additions & 3 deletions logwrap/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@
later it has been reworked and extended for support of special cases.
"""

from ._repr_utils import PrettyFormat, PrettyRepr, PrettyStr, pretty_repr, pretty_str
from ._log_wrap import logwrap, LogWrap, BoundParameter, bind_args_kwargs
from .repr_utils import PrettyFormat, PrettyRepr, PrettyStr, pretty_repr, pretty_str
from .log_wrap import logwrap, LogWrap, BoundParameter, bind_args_kwargs

__all__ = (
"LogWrap",
Expand All @@ -37,7 +37,7 @@
"bind_args_kwargs",
)

__version__ = "4.9.2"
__version__ = "4.9.3"
__author__ = "Alexey Stepanov"
__author_email__ = "penguinolog@gmail.com"
__maintainers__ = {
Expand Down
17 changes: 17 additions & 0 deletions logwrap/__init__.pyx
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
from .repr_utils cimport PrettyFormat, PrettyRepr, PrettyStr
from .repr_utils import pretty_repr, pretty_str

from .log_wrap cimport LogWrap
from .log_wrap import logwrap, BoundParameter, bind_args_kwargs

cdef tuple __all__ = (
"LogWrap",
"logwrap",
"PrettyFormat",
"PrettyRepr",
"PrettyStr",
"pretty_repr",
"pretty_str",
"BoundParameter",
"bind_args_kwargs",
)
20 changes: 20 additions & 0 deletions logwrap/class_decorator.pxd
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# Copyright 2017-2018 Alexey Stepanov aka penguinolog
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.

"""Base class for decorators."""


cdef class BaseDecorator:
cdef readonly object _func
cdef dict __dict__
File renamed without changes.
56 changes: 56 additions & 0 deletions logwrap/class_decorator.pyx
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
# Copyright 2017-2018 Alexey Stepanov aka penguinolog
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.

"""Base class for decorators."""

import functools
import typing


cdef class BaseDecorator:
"""Base class for decorators."""

def __init__(self, func: typing.Optional[typing.Callable] = None) -> None:
"""Decorator."""
# 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)
# pylint: enable=assigning-non-slot

def _get_function_wrapper(self, func: typing.Callable) -> typing.Callable:
"""Here should be constructed and returned real decorator."""
raise NotImplementedError() # pragma: no cover

def __call__(self, *args: typing.Union[typing.Callable, typing.Any], **kwargs: typing.Any) -> typing.Any:
"""Main decorator getter."""
cdef list l_args = list(args)

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

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

def __repr__(self) -> str:
"""For debug purposes."""
return "<{cls}({func!r}) at 0x{id:X}>".format(
cls=self.__class__.__name__, func=self._func, id=id(self)
) # pragma: no cover
57 changes: 57 additions & 0 deletions logwrap/log_wrap.pxd
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
# Copyright 2016-2018 Alexey Stepanov aka penguinolog

# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.

"""log_wrap shared code module."""

import inspect
import typing

from logwrap cimport class_decorator


cdef unsigned int indent


cdef str pretty_repr(
src: typing.Any,
unsigned int indent=?,
bint no_indent_start=?,
unsigned int max_indent=?,
unsigned int indent_step=?
)


cdef class LogWrap(class_decorator.BaseDecorator):
"""Base class for LogWrap implementation."""

cdef public unsigned int log_level
cdef public unsigned int exc_level
cdef public unsigned int max_indent

cdef public bint log_call_args
cdef public bint log_call_args_on_exc
cdef public bint log_traceback
cdef public bint log_result_obj

cdef list __blacklisted_names
cdef list __blacklisted_exceptions
cdef object __logger
cdef object __spec

cdef str _get_func_args_repr(
self, sig: inspect.Signature, args: typing.Tuple, kwargs: typing.Dict[str, typing.Any]
)
cdef void _make_done_record(self, str func_name, result: typing.Any)
cdef void _make_calling_record(self, str name, str arguments, str method=?)
cdef void _make_exc_record(self, str name, str arguments)
4 changes: 2 additions & 2 deletions logwrap/_log_wrap.py → logwrap/log_wrap.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
import typing

import logwrap as core
from . import _class_decorator
from . import class_decorator


__all__ = ("LogWrap", "logwrap", "BoundParameter", "bind_args_kwargs")
Expand Down Expand Up @@ -171,7 +171,7 @@ def bind_args_kwargs(

# pylint: disable=assigning-non-slot,abstract-method
# noinspection PyAbstractClass
class LogWrap(_class_decorator.BaseDecorator):
class LogWrap(class_decorator.BaseDecorator):
"""Base class for LogWrap implementation."""

__slots__ = (
Expand Down
Loading