Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Python 3 only -- fixes deprecation warnings #63

Merged
merged 11 commits into from
Nov 5, 2019
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
14 changes: 14 additions & 0 deletions .coveragerc
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
[run]
parallel = true
source =
venusian

[paths]
source =
src/venusian
*/src/venusian
*/site-packages/venusian

[report]
show_missing = true
precision = 2
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
.*.swp
.cache/
.coverage
.coverage.*
.tox/
__pycache__/
build/
Expand Down
28 changes: 18 additions & 10 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,24 +4,32 @@ sudo: false

matrix:
include:
- python: 2.7
env: TOXENV=py27
- python: 3.4
env: TOXENV=py34
- python: 3.5
env: TOXENV=py35
- python: pypy
env: TOXENV=pypy
- python: 3.5
env: TOXENV=py2-cover,py3-cover,coverage
- python: 3.5
env: TOXENV=docs
- python: 3.8
env: TOXENV=lint
dist: xenial
sudo: true
- python: 3.8
env: TOXENV=build
dist: xenial
sudo: true
- python: 3.5
env: TOXENV=py35
- python: 3.6
env: TOXENV=py36
dist: xenial
sudo: true
- python: 3.7
env: TOXENV=py37
dist: xenial
sudo: true
- python: 3.8
env: TOXENV=py38
dist: xenial
sudo: true
allow_failures:
- env: TOXENV=lint

install:
- travis_retry pip install tox
Expand Down
18 changes: 18 additions & 0 deletions MANIFEST.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
graft src/venusian
graft tests
graft docs
prune docs/_build
prune docs/_themes

include README.rst
include CHANGES.rst
include LICENSE.txt
include CONTRIBUTING.rst
include CONTRIBUTORS.txt
include COPYRIGHT.txt

include pyproject.toml setup.cfg
include .coveragerc
include tox.ini .travis.yml rtd.txt

recursive-exclude * __pycache__ *.py[cod]
12 changes: 12 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
[build-system]
requires = ["setuptools >= 40.9.0"]
build-backend = "setuptools.build_meta"

[tool.black]
py36 = false
exclude = '''
/(
\.git
| .tox
)/
'''
56 changes: 46 additions & 10 deletions setup.cfg
Original file line number Diff line number Diff line change
@@ -1,13 +1,49 @@
[easy_install]
zip_ok = false
[metadata]
name = venusian
version = 2.0.0
description = A library for deferring decorator actions
long_description = file: README.rst, CHANGES.rst
long_description_content_type = text/x-rst
keywords = web wsgi zope
license = BSD-derived (http://www.repoze.org/LICENSE.txt)
classifiers =
Development Status :: 6 - Mature
Intended Audience :: Developers
Programming Language :: Python :: 3
Programming Language :: Python :: 3.5
Programming Language :: Python :: 3.6
Programming Language :: Python :: 3.7
Programming Language :: Python :: 3.8
Programming Language :: Python :: Implementation :: CPython
Programming Language :: Python :: Implementation :: PyPy
url = https://pylonsproject.org/
author = Chris McDonough, Agendaless Consulting
author_email = pylons-devel@googlegroups.com
python_requires = >=3.5

[bdist_wheel]
universal = 1
[options]
package_dir=
=src
packages=find:

[options.packages.find]
where=src

[tools:pytest]
ignore=venusian/tests/fixtures/
testpaths=venusian/tests/
[options.extras_require]
testing =
pytest
pytest-cov
coverage
docs =
Sphinx
repoze.sphinx.autointerface

[bdist_wheel]
universal=1

[aliases]
dev = develop easy_install venusian[testing]
docs = develop easy_install venusian[docs]
[tool:pytest]
ignore=tests/fixtures/
python_files = test_*.py
testpaths =
tests
addopts = -W always --cov --cov-report=term-missing
77 changes: 4 additions & 73 deletions setup.py
Original file line number Diff line number Diff line change
@@ -1,76 +1,7 @@
##############################################################################
#
# Copyright (c) 2010 Agendaless Consulting and Contributors.
# All Rights Reserved.
#
# This software is subject to the provisions of the BSD-like license at
# http://www.repoze.org/LICENSE.txt. A copy of the license should accompany
# this distribution. THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL
# EXPRESS OR IMPLIED WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO,
# THE IMPLIED WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND
# FITNESS FOR A PARTICULAR PURPOSE
#
##############################################################################

import os
"""
Necessary for pip install -e, and python setup.py check
"""

from setuptools import setup
from setuptools import find_packages

here = os.path.abspath(os.path.dirname(__file__))

try:
with open(os.path.join(here, 'README.rst')) as f:
README = f.read()
with open(os.path.join(here, 'CHANGES.rst')) as f:
CHANGES = f.read()
except:
README = ''
CHANGES = ''

testing_extras = [
'pytest',
'coverage',
'pytest-cov',
]

docs_extras = [
'Sphinx',
'repoze.sphinx.autointerface'
]

setup(name='venusian',
version='1.2.0',
description='A library for deferring decorator actions',
long_description=README + '\n\n' + CHANGES,
classifiers=[
"Development Status :: 6 - Mature",
"Intended Audience :: Developers",
"Programming Language :: Python",
"Programming Language :: Python :: 2.7",
"Programming Language :: Python :: 3",
"Programming Language :: Python :: 3.4",
"Programming Language :: Python :: 3.5",
"Programming Language :: Python :: 3.6",
"Programming Language :: Python :: 3.7",
"Programming Language :: Python :: Implementation :: CPython",
"Programming Language :: Python :: Implementation :: PyPy",
],
keywords='web wsgi zope',
author="Chris McDonough, Agendaless Consulting",
author_email="pylons-devel@googlegroups.com",
url="https://pylonsproject.org",
license="BSD-derived (http://www.repoze.org/LICENSE.txt)",
packages=find_packages(),
include_package_data=True,
zip_safe=False,
extras_require={
'testing': testing_extras,
'docs': docs_extras,
},
tests_require=[],
install_requires=[],
test_suite='venusian',
entry_points="""\
"""
)
setup()
73 changes: 30 additions & 43 deletions venusian/__init__.py → src/venusian/__init__.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,7 @@
import imp
from inspect import getmembers, getmro, isclass
from pkgutil import iter_modules
import sys

from venusian.compat import (
is_nonstr_iter,
INT_TYPES,
)

from venusian.advice import getFrameInfo

ATTACH_ATTR = '__venusian_callbacks__'
Expand Down Expand Up @@ -108,7 +102,10 @@ def onerror(name):

pkg_name = package.__name__

if ignore is not None and not is_nonstr_iter(ignore):
if ignore is not None and (
isinstance(ignore, str) or
not hasattr(ignore, '__iter__')
):
ignore = [ignore]
elif ignore is None:
ignore = []
Expand Down Expand Up @@ -188,7 +185,7 @@ def invoke(mod_name, name, ob):
# this module but were not actually defined there
continue
callback(self, name, ob)
except ValueError:
except ValueError: # pragma: nocover
continue

for name, ob in getmembers(package):
Expand All @@ -205,41 +202,31 @@ def invoke(mod_name, name, ob):
loader = importer.find_module(modname)
if loader is not None: # happens on pypy with orphaned pyc
try:
if hasattr(loader, 'etc'):
# python < py3.3
module_type = loader.etc[2]
else: # pragma: no cover
# py3.3b2+ (importlib-using)
module_type = imp.PY_SOURCE
get_filename = getattr(loader, 'get_filename', None)
if get_filename is None:
get_filename = loader._get_filename
try:
fn = get_filename(modname)
except TypeError:
fn = get_filename()
if fn.endswith(('.pyc', '.pyo', '$py.class')):
module_type = imp.PY_COMPILED
# only scrape members from non-orphaned source files
# and package directories
if module_type in (imp.PY_SOURCE, imp.PKG_DIRECTORY):
# NB: use __import__(modname) rather than
# loader.load_module(modname) to prevent
# inappropriate double-execution of module code
try:
__import__(modname)
except Exception:
if onerror is not None:
onerror(modname)
else:
raise
module = sys.modules.get(modname)
if module is not None:
for name, ob in getmembers(module, None):
invoke(modname, name, ob)
get_filename = getattr(loader, 'get_filename', None)
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Meat of the change here...

if get_filename is None: # pragma: nocover
get_filename = loader._get_filename
try:
fn = get_filename(modname)
except TypeError: # pragma: nocover
fn = get_filename()

# NB: use __import__(modname) rather than
# loader.load_module(modname) to prevent
# inappropriate double-execution of module code
try:
__import__(modname)
except Exception:
if onerror is not None:
onerror(modname)
else:
raise
module = sys.modules.get(modname)
if module is not None:
for name, ob in getmembers(module, None):
invoke(modname, name, ob)
finally:
if ( hasattr(loader, 'file') and
hasattr(loader.file,'close') ):
if ( hasattr(loader, 'file') and
hasattr(loader.file,'close') ): # pragma: nocover
loader.file.close()

class AttachInfo(object):
Expand Down Expand Up @@ -292,7 +279,7 @@ def __init__(self, attached_to):
self.lifted = False

def attached_to(self, mod_name, name, obj):
if isinstance(self.attached_id, INT_TYPES):
if isinstance(self.attached_id, int):
return self.attached_id == id(obj)
return self.attached_id == (mod_name, name)

Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from venusian.tests.fixtures import decorator
from tests.fixtures import decorator

@decorator(function=True)
def function(request): # pragma: no cover
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from venusian.tests.fixtures import decorator
from tests.fixtures import decorator

@decorator(function=True)
def function(request): # pragma: no cover
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from venusian.tests.fixtures import categorydecorator
from venusian.tests.fixtures import categorydecorator2
from tests.fixtures import categorydecorator
from tests.fixtures import categorydecorator2

@categorydecorator(function=True)
def function(request): # pragma: no cover
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from venusian.tests.fixtures import decorator
from tests.fixtures import decorator


@decorator(class_=True)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from venusian.tests.fixtures import decorator
from tests.fixtures import decorator

@decorator(superclass=True)
class SuperClass(object):
Expand Down
7 changes: 7 additions & 0 deletions tests/fixtures/import_and_scan/one.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
from tests.fixtures import decorator
from tests.fixtures.import_and_scan.two import twofunction # should not be scanned

@decorator(function=True)
def onefunction(request): # pragma: no cover
twofunction(request)
return request
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from venusian.tests.fixtures import decorator
from tests.fixtures import decorator

@decorator(function=True)
def twofunction(request): # pragma: no cover
Expand Down