Skip to content

Commit

Permalink
Join all cythonized code (speed optimizations) (#62)
Browse files Browse the repository at this point in the history
Tested on windows and linux. About 30% faster.
  • Loading branch information
penguinolog committed Nov 16, 2018
1 parent 8ee2f7e commit 6345fce
Show file tree
Hide file tree
Showing 4 changed files with 60 additions and 25 deletions.
15 changes: 8 additions & 7 deletions appveyor.yml
@@ -1,8 +1,4 @@
environment:
TWINE_USERNAME: penguinolog
TWINE_PASSWORD:
secure: TCKGf77kkVeo2Pbd+lQY5Q==

matrix:
- PYTHON: "C:\\Python35"
PYTHON_VERSION: "3.5.x" # currently 3.5.1
Expand All @@ -20,6 +16,14 @@ environment:
PYTHON_VERSION: "3.6.x" # currently 3.6.0
PYTHON_ARCH: "64"

- PYTHON: "C:\\Python37"
PYTHON_VERSION: "3.7.x" # currently 3.6.0
PYTHON_ARCH: "32"

- PYTHON: "C:\\Python37-x64"
PYTHON_VERSION: "3.7.x" # currently 3.6.0
PYTHON_ARCH: "64"

install:
- cmd: echo "Using cmd"

Expand Down Expand Up @@ -56,6 +60,3 @@ test_script:
artifacts:
- path: dist\*
name: Python built code

on_success:
- if "%APPVEYOR_REPO_TAG%"=="true" ( pip install -U twine && twine upload dist/*.whl )
8 changes: 8 additions & 0 deletions logwrap/__init__.pxd
@@ -1 +1,9 @@
cpdef tuple __all__

cpdef str __version__
cpdef str __author__
cpdef str __author_email__
cpdef dict __maintainers__
cpdef str __url__
cpdef str __description__
cpdef str __license__
40 changes: 40 additions & 0 deletions logwrap/__init__.pyx
@@ -1,3 +1,19 @@
# 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.

import pkg_resources

from .repr_utils cimport PrettyFormat, PrettyRepr, PrettyStr, pretty_repr, pretty_str

from .log_wrap cimport LogWrap
Expand All @@ -14,3 +30,27 @@ cpdef tuple __all__ = (
"BoundParameter",
"bind_args_kwargs",
)

cpdef str __version__

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

cpdef str __author__ = "Alexey Stepanov"
cpdef str __author_email__ = "penguinolog@gmail.com"
cpdef dict __maintainers__ = {
"Alexey Stepanov": "penguinolog@gmail.com",
"Antonio Esposito": "esposito.cloud@gmail.com",
"Dennis Dmitriev": "dis-xcom@gmail.com",
}
cpdef str __url__ = "https://github.com/python-useful-helpers/logwrap"
cpdef str __description__ = "Decorator for logging function arguments and return value by human-readable way"
cpdef str __license__ = "Apache License, Version 2.0"
22 changes: 4 additions & 18 deletions setup.py
Expand Up @@ -22,9 +22,9 @@
import collections
from distutils.command import build_ext
import distutils.errors
import glob
import os.path
import shutil
import sys

try:
# noinspection PyPackageRequirements
Expand All @@ -44,19 +44,7 @@
long_description = f.read()


def _extension(modpath):
"""Make setuptools.Extension."""
return setuptools.Extension(modpath, [modpath.replace(".", "/") + ".py"])


requires_optimization = [
setuptools.Extension("logwrap.class_decorator", ["logwrap/class_decorator.pyx"]),
setuptools.Extension("logwrap.log_wrap", ["logwrap/log_wrap.pyx"]),
setuptools.Extension("logwrap.repr_utils", ["logwrap/repr_utils.pyx"]),
]

if "win32" != sys.platform:
requires_optimization.append(_extension("logwrap.__init__"))
requires_optimization = [setuptools.Extension("logwrap", glob.glob("logwrap/*.pyx"))]

# noinspection PyCallingNonCallable
ext_modules = (
Expand Down Expand Up @@ -90,9 +78,7 @@ def run(self):
root_dir = os.path.abspath(os.path.join(__file__, ".."))
target_dir = build_dir if not self.inplace else root_dir

src_files = (
os.path.join("logwrap", "__init__.py"),
)
src_files = (os.path.join("logwrap", "__init__.py"),)

for src_file in src_files:
src = os.path.join(root_dir, src_file)
Expand Down Expand Up @@ -233,7 +219,7 @@ def get_simple_vars_from_src(src):
"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"
"setuptools_scm",
],
use_scm_version=True,
install_requires=required,
Expand Down

0 comments on commit 6345fce

Please sign in to comment.