Skip to content

Commit 40fff2d

Browse files
authored
Merge pull request #18 from aikikode/feature/fix_lint_and_2.7
FIX: Remove deprecated pkgversion; code reformats; fix 2.7 type hints error
2 parents 41939cb + 04f8436 commit 40fff2d

16 files changed

+186
-188
lines changed

.gitignore

+1-2
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,6 @@ var/
127127
.installed.cfg
128128
*.egg
129129
.python-version
130-
setup.py
131130

132131
# PyInstaller
133132
# Usually these files are written by a python script from a template
@@ -146,7 +145,7 @@ htmlcov/
146145
.coverage.*
147146
.cache
148147
nosetests.xml
149-
coverage.xml
148+
coverage*.xml
150149
*,cover
151150

152151
# Translations

Makefile

+3-8
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ venv:
3131
@python3.6 -m venv venv
3232
@$(PIP) install -U "pip>=7.0" -q
3333
@$(PIP) install -U setuptools -q
34-
@$(PIP) install -r $(DEPS)
34+
@$(PIP) install --use-feature=2020-resolver -r $(DEPS)
3535

3636
test: venv pyclean
3737
$(TOX) -e $(TOX_PY_LIST)
@@ -40,8 +40,8 @@ test/%: venv pyclean
4040
$(TOX) -e $(TOX_PY_LIST) -- $*
4141

4242
lint: venv
43-
@$(TOX) -e lint
4443
@$(TOX) -e isort-check
44+
@$(TOX) -e flake8
4545

4646
isort: venv
4747
@$(TOX) -e isort-fix
@@ -53,14 +53,9 @@ docker/%:
5353
$(DOCKER_COMPOSE) run --rm --service-ports app make $*
5454

5555
## Distribution
56-
setup.py: venv
57-
@$(PYTHON) setup_gen.py
58-
5956
build: venv tox
60-
-rm -f setup.py
6157
-rm -rf dist build
62-
$(MAKE) setup.py
63-
$(PYTHON) setup.py sdist
58+
$(PYTHON) setup.py sdist bdist_wheel
6459
$(TWINE) check dist/*
6560

6661
publish: build

fqn_decorators/async.py

-9
This file was deleted.

fqn_decorators/asynchronous.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,12 @@ async def async_wrapper(*args, **kwargs):
1919
self.before()
2020
try:
2121
self.result = await self.func(*self.args, **self.kwargs)
22-
except:
22+
except: # noqa: E722
2323
self.exc_info = sys.exc_info()
2424
self.exception()
2525
raise
2626
finally:
2727
self.after()
2828
return self.result
29+
2930
return async_wrapper(*args, **kwargs)

fqn_decorators/decorators.py

+19-19
Original file line numberDiff line numberDiff line change
@@ -9,26 +9,26 @@ def get_fqn(obj):
99
It only works for classes, methods and functions.
1010
It is unable to properly determine the FQN of class instances, static methods and class methods.
1111
"""
12-
path = [getattr(obj, '__module__', None)]
13-
qualname = getattr(obj, '__qualname__', None)
12+
path = [getattr(obj, "__module__", None)]
13+
qualname = getattr(obj, "__qualname__", None)
1414
if qualname:
15-
path.append(qualname.replace('<locals>.', ''))
16-
im_self = getattr(obj, '__self__', None)
17-
im_class = getattr(im_self, '__class__', None)
15+
path.append(qualname.replace("<locals>.", ""))
16+
im_self = getattr(obj, "__self__", None)
17+
im_class = getattr(im_self, "__class__", None)
1818
if im_self and im_class:
1919
path = [
20-
getattr(im_class, '__module__', None),
21-
getattr(im_class, '__name__', None),
22-
getattr(obj, '__name__', None)
20+
getattr(im_class, "__module__", None),
21+
getattr(im_class, "__name__", None),
22+
getattr(obj, "__name__", None),
2323
]
2424
else:
25-
im_class = getattr(obj, 'im_class', None)
26-
im_class_module = getattr(im_class, '__module__', None)
25+
im_class = getattr(obj, "im_class", None)
26+
im_class_module = getattr(im_class, "__module__", None)
2727
if im_class and im_class_module:
2828
path = [im_class_module]
29-
path.append(getattr(im_class, '__name__', None))
30-
path.append(getattr(obj, '__name__', None))
31-
return '.'.join(filter(None, path))
29+
path.append(getattr(im_class, "__name__", None))
30+
path.append(getattr(obj, "__name__", None))
31+
return ".".join(filter(None, path))
3232

3333

3434
class Decorator(object):
@@ -77,7 +77,7 @@ def _ensure_decorator_instance(self, *args, **kwargs):
7777
if not self.func:
7878
# Decorator was initialized with arguments
7979
return self.__class__(args[0], **self.params), True
80-
return self.__class__(self.func, _initialized=True, **self.params)(*args, **kwargs), True
80+
return self.__class__(self.func, _initialized=True, **self.params)(*args, **kwargs), True
8181
self.fqn = self.get_fqn()
8282
self.args = args
8383
self.kwargs = kwargs
@@ -91,7 +91,7 @@ def __call__(self, *args, **kwargs):
9191
self.before()
9292
try:
9393
self.result = self.func(*self.args, **self.kwargs)
94-
except:
94+
except: # noqa: E722
9595
self.exc_info = sys.exc_info()
9696
self.exception()
9797
raise
@@ -133,14 +133,14 @@ class ChainedDecorator(Decorator):
133133

134134
def __init__(self, func=None, decorators=None, **params):
135135
"""Override the init just to make the decorators argument more visible"""
136-
params['decorators'] = decorators
136+
params["decorators"] = decorators
137137
super(ChainedDecorator, self).__init__(func, **params)
138138

139139
def before(self):
140-
for decorator in self.params.get('decorators', []):
140+
for decorator in self.params.get("decorators", []):
141141
self.func = decorator(self.func)
142-
if hasattr(self.func, 'fqn'):
143-
setattr(self.func, 'fqn', self.fqn)
142+
if hasattr(self.func, "fqn"):
143+
setattr(self.func, "fqn", self.fqn)
144144

145145

146146
chained_decorator = ChainedDecorator

pyproject.toml

+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
[tool.black]
2+
line-length = 120
3+
target_version = ["py27", "py35", "py36", "py37"]
4+
5+
[tool.isort]
6+
combine_as_imports = true
7+
default_section = "THIRDPARTY"
8+
known_first_party = ["fqn_decorators", "tests"]
9+
from_first = false
10+
include_trailing_comma = true
11+
length_sort = false
12+
multi_line_output = 3
13+
order_by_type = true
14+
sections = ["FUTURE", "STDLIB", "THIRDPARTY", "FIRSTPARTY", "LOCALFOLDER"]
15+
use_parentheses = true
16+
line_length = 120
17+
force_grid_wrap = 0
18+
19+
[tool.coverage.run]
20+
source = ["fqn_decorators"]
21+
relative_files = true
22+
branch = true
23+
omit = ["tests/*"]
24+
25+
[tool.setuptools_scm]
26+
27+
[build-system]
28+
requires = ["setuptools>=42", "wheel", "setuptools_scm[toml]>=3.4"]

requirements.txt

+20-3
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,20 @@
1-
# Additional packages
2-
-r requirements/requirements-base.txt
3-
-r requirements/requirements-testing.txt
1+
# Package in develop mode
2+
-e .
3+
4+
importlib-metadata
5+
6+
# Distribution
7+
twine
8+
wheel
9+
10+
# Code style
11+
mypy; python_version >= '3.5'
12+
isort[pyproject]
13+
flake8
14+
15+
# Tests
16+
tox
17+
pytest
18+
pytest-cov
19+
pytest-asyncio; python_version >= '3.5'
20+
mock

requirements/requirements-base.txt

Whitespace-only changes.

requirements/requirements-testing.txt

-14
This file was deleted.

setup.cfg

+13-22
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,14 @@
11
[flake8]
2-
exclude = build,.git,**migrations/
3-
ignore = E902
4-
max-line-length = 119
5-
6-
[isort]
7-
combine_as_imports = true
8-
default_section = THIRDPARTY
9-
from_first = false
10-
include_trailing_comma = true
11-
12-
length_sort = false
13-
multi_line_output = 5
14-
not_skip = __init__.py
15-
order_by_type = true
16-
sections = FUTURE,STDLIB,THIRDPARTY,OTHER,FIRSTPARTY,LOCALFOLDER
17-
use_parenthesis = true
18-
19-
[wheel]
20-
universal = 1
21-
22-
[coverage:run]
23-
omit = tests/*
2+
exclude = build,.git
3+
max-line-length = 120
4+
select = B,E,F,W,C,W504,B902,B903,B950
5+
ignore =
6+
# flake8 misbehaves: https://github.com/PyCQA/pycodestyle/issues/373
7+
E203
8+
# duplicate for B950
9+
E501
10+
E902
11+
# mutual exclusive with W504
12+
W503
13+
# conflicts with FastAPI `Query`, `Header`, `Body` functions
14+
B008

setup.py

+38
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
#!/usr/bin/env python
2+
# -*- coding: utf-8 -*-
3+
from setuptools import find_packages, setup
4+
5+
with open("README.md") as f:
6+
long_description = f.read()
7+
8+
9+
setup(
10+
name="fqn-decorators",
11+
use_scm_version=True,
12+
setup_requires=["setuptools_scm"],
13+
description="Easily create multi-purpose decorators that have access to the FQN of the original function.",
14+
long_description=long_description,
15+
long_description_content_type="text/markdown",
16+
author="Mattias Sluis",
17+
author_email="[email protected]",
18+
url="https://github.com/kpn-digital/py-fqn-decorators",
19+
packages=find_packages(exclude=["tests*"]),
20+
tests_require=["tox"],
21+
include_package_data=True,
22+
zip_safe=False,
23+
classifiers=[
24+
"Development Status :: 5 - Production/Stable",
25+
"Environment :: Web Environment",
26+
"Intended Audience :: Developers",
27+
"Operating System :: OS Independent",
28+
"Programming Language :: Python",
29+
"Programming Language :: Python :: 2",
30+
"Programming Language :: Python :: 2.7",
31+
"Programming Language :: Python :: 3",
32+
"Programming Language :: Python :: 3.5",
33+
"Programming Language :: Python :: 3.6",
34+
"Programming Language :: Python :: 3.7",
35+
"Programming Language :: Python :: 3.8",
36+
"Topic :: Internet :: WWW/HTTP",
37+
],
38+
)

setup_gen.py

-35
This file was deleted.

tests/examples.py

-2
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,12 @@ def my_test_func(a):
88

99
@fqn_decorators.Decorator()
1010
class A(object):
11-
1211
@fqn_decorators.Decorator
1312
def method(self, a):
1413
return a
1514

1615

1716
class B(object):
18-
1917
@fqn_decorators.Decorator
2018
def method(self, b):
2119
return b

0 commit comments

Comments
 (0)