diff --git a/doc/source/conf.py b/doc/source/conf.py index 94eeeb3..55514a9 100644 --- a/doc/source/conf.py +++ b/doc/source/conf.py @@ -13,110 +13,10 @@ # All configuration values have a default; values that are commented out # serve to show the default. -import ast -import collections -import os.path -import sys - -PY3 = sys.version_info[:2] > (2, 7) -PY34 = sys.version_info[:2] > (3, 3) - -with open( - os.path.join( - os.path.dirname(__file__), '..', '..', - 'logwrap', '__init__.py' - ) -) as f: - source = f.read() - - -# noinspection PyUnresolvedReferences -def get_simple_vars_from_src(src): - """Get simple (string/number/boolean and None) assigned values from source. - - :param src: Source code - :type src: str - :returns: OrderedDict with keys, values = variable names, values - :rtype: typing.Dict[ - str, - typing.Union[ - str, bytes, - int, float, complex, - list, set, dict, tuple, - None, - ] - ] - - Limitations: Only defined from scratch variables. - Not supported by design: - * Imports - * Executable code, including string formatting and comprehensions. - - Examples: - - >>> string_sample = "a = '1'" - >>> get_simple_vars_from_src(string_sample) - OrderedDict([('a', '1')]) - - >>> int_sample = "b = 1" - >>> get_simple_vars_from_src(int_sample) - OrderedDict([('b', 1)]) - - >>> list_sample = "c = [u'1', b'1', 1, 1.0, 1j, None]" - >>> result = get_simple_vars_from_src(list_sample) - >>> result == collections.OrderedDict( - ... [('c', [u'1', b'1', 1, 1.0, 1j, None])] - ... ) - True - - >>> iterable_sample = "d = ([1], {1: 1}, {1})" - >>> get_simple_vars_from_src(iterable_sample) - OrderedDict([('d', ([1], {1: 1}, {1}))]) - - >>> multiple_assign = "e = f = g = 1" - >>> get_simple_vars_from_src(multiple_assign) - OrderedDict([('e', 1), ('f', 1), ('g', 1)]) - """ - ast_data = ( - ast.Str, ast.Num, - ast.List, ast.Set, ast.Dict, ast.Tuple - ) - if PY3: - ast_data += (ast.Bytes,) - if PY34: - ast_data += (ast.NameConstant,) - - tree = ast.parse(src) - - result = collections.OrderedDict() - - for node in ast.iter_child_nodes(tree): - if not isinstance(node, ast.Assign): # We parse assigns only - continue - try: - if isinstance(node.value, ast_data): - value = ast.literal_eval(node.value) - elif isinstance( # NameConstant in python < 3.4 - node.value, ast.Name - ) and isinstance( - node.value.ctx, ast.Load # Read constant - ): - value = ast.literal_eval(node.value) - else: - continue - except ValueError: - continue - for tgt in node.targets: - if isinstance( - tgt, ast.Name - ) and isinstance( - tgt.ctx, ast.Store - ): - result[tgt.id] = value - return result - - -variables = get_simple_vars_from_src(source) +import pkg_resources + +release = pkg_resources.get_distribution("logwrap").version +version = '.'.join(release.split('.')[:2]) # If extensions (or modules to document with autodoc) are in another directory, # add these directories to sys.path here. If the directory is relative to the @@ -160,7 +60,7 @@ def get_simple_vars_from_src(src): # General information about the project. project = 'logwrap' -copyright = '2016-2017, Alexey Stepanov' +copyright = '2016-2018, Alexey Stepanov' author = 'Alexey Stepanov' # The version info for the project you're documenting, acts as replacement for @@ -168,9 +68,7 @@ def get_simple_vars_from_src(src): # built documents. # # The short X.Y version. -version = variables['__version__'] # The full version, including alpha/beta/rc tags. -release = variables['__version__'] # The language for content autogenerated by Sphinx. Refer to documentation # for a list of supported languages. diff --git a/logwrap/__init__.py b/logwrap/__init__.py index 51f5d08..eff51e8 100644 --- a/logwrap/__init__.py +++ b/logwrap/__init__.py @@ -21,6 +21,7 @@ Original code was made for Mirantis Inc by Alexey Stepanov, later it has been reworked and extended for support of special cases. """ +import pkg_resources from .repr_utils import PrettyFormat, PrettyRepr, PrettyStr, pretty_repr, pretty_str from .log_wrap import logwrap, LogWrap, BoundParameter, bind_args_kwargs @@ -37,7 +38,17 @@ "bind_args_kwargs", ) -__version__ = "4.9.3" +try: + __version__ = pkg_resources.get_distribution(__name__).version +except pkg_resources.DistributionNotFound: + # package is not installed, try to get from SCM + try: + import setuptools_scm # type: ignore + + __version__ = setuptools_scm.get_version() + except ImportError: + pass + __author__ = "Alexey Stepanov" __author_email__ = "penguinolog@gmail.com" __maintainers__ = { diff --git a/logwrap/log_wrap.pxd b/logwrap/log_wrap.pxd index 4fa5029..c7a5ec7 100644 --- a/logwrap/log_wrap.pxd +++ b/logwrap/log_wrap.pxd @@ -48,6 +48,6 @@ cdef: cdef: str _get_func_args_repr(self, sig: inspect.Signature, tuple args, dict kwargs) - void _make_done_record(self, str func_name, result: typing.Any) - void _make_calling_record(self, str name, str arguments, str method=?) - void _make_exc_record(self, str name, str arguments) + void _make_done_record(self, str func_name, result: typing.Any) except * + void _make_calling_record(self, str name, str arguments, str method=?) except * + void _make_exc_record(self, str name, str arguments) except * diff --git a/logwrap/log_wrap.pyx b/logwrap/log_wrap.pyx index 2133266..ba4b2ed 100644 --- a/logwrap/log_wrap.pyx +++ b/logwrap/log_wrap.pyx @@ -364,7 +364,7 @@ cdef class LogWrap(class_decorator.BaseDecorator): param_str += "\n" return param_str - void _make_done_record(self, str func_name, result: typing.Any): + void _make_done_record(self, str func_name, result: typing.Any) except *: """Construct success record. :type func_name: str @@ -385,7 +385,7 @@ cdef class LogWrap(class_decorator.BaseDecorator): ) self._logger.log(level=self.log_level, msg=msg) # type: ignore - void _make_calling_record(self, str name, str arguments, str method="Calling"): + void _make_calling_record(self, str name, str arguments, str method="Calling") except *: """Make log record before execution. :type name: str @@ -399,7 +399,7 @@ cdef class LogWrap(class_decorator.BaseDecorator): ), ) - void _make_exc_record(self, str name, str arguments): + void _make_exc_record(self, str name, str arguments) except *: """Make log record if exception raised. :type name: str diff --git a/setup.py b/setup.py index 1c7d434..cb55849 100644 --- a/setup.py +++ b/setup.py @@ -214,7 +214,6 @@ def get_simple_vars_from_src(src): "{name} <{email}>".format(name=name, email=email) for name, email in variables["__maintainers__"].items() ), url=variables["__url__"], - version=variables["__version__"], license=variables["__license__"], description=variables["__description__"], long_description=long_description, @@ -227,9 +226,13 @@ def get_simple_vars_from_src(src): # situations as progressive releases of projects are done. # Blacklist setuptools 34.0.0-34.3.2 due to https://github.com/pypa/setuptools/issues/951 # Blacklist setuptools 36.2.0 due to https://github.com/pypa/setuptools/issues/1086 - setup_requires="setuptools >= 21.0.0,!=24.0.0," - "!=34.0.0,!=34.0.1,!=34.0.2,!=34.0.3,!=34.1.0,!=34.1.1,!=34.2.0,!=34.3.0,!=34.3.1,!=34.3.2," - "!=36.2.0", + setup_requires=[ + "setuptools >= 21.0.0,!=24.0.0," + "!=34.0.0,!=34.0.1,!=34.0.2,!=34.0.3,!=34.1.0,!=34.1.1,!=34.2.0,!=34.3.0,!=34.3.1,!=34.3.2," + "!=36.2.0", + "setuptools_scm" + ], + use_scm_version=True, install_requires=required, package_data={"logwrap": ["py.typed"]}, ) diff --git a/tools/build-wheels.sh b/tools/build-wheels.sh index 4c357cc..5ca6d94 100755 --- a/tools/build-wheels.sh +++ b/tools/build-wheels.sh @@ -57,6 +57,7 @@ for PYTHON in ${PYTHON_VERSIONS}; do done find /io/dist/ -type f -not -name "*$package_name*" -delete +rm -rf /io/.eggs rm -rf /io/build rm -rf /io/*.egg-info rm -rf /io/.pytest_cache