Skip to content

Commit

Permalink
Merge pull request #275 from pytest-dev/upgrade-vendor-libs
Browse files Browse the repository at this point in the history
upgrade apipkg
  • Loading branch information
RonnyPfannschmidt authored Sep 24, 2021
2 parents d2a6541 + f3a1a59 commit e116b2b
Show file tree
Hide file tree
Showing 15 changed files with 112 additions and 73 deletions.
6 changes: 1 addition & 5 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,9 @@ jobs:
uses: actions/setup-python@v2
with:
python-version: ${{ matrix.python }}
- name: Install tox
run: |
python -m pip install --upgrade pip
pip install tox
- name: Test
run: |
tox -e ${{ matrix.tox_env }}
pipx run tox -e ${{ matrix.tox_env }}
deploy:

Expand Down
10 changes: 0 additions & 10 deletions py/_vendored_packages/apipkg-1.5.dist-info/RECORD

This file was deleted.

18 changes: 18 additions & 0 deletions py/_vendored_packages/apipkg-2.0.0.dist-info/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
Metadata-Version: 2.1
Name: apipkg
Version: 1.5
Version: 2.0.0
Summary: apipkg: namespace control and lazy-import mechanism
Home-page: https://github.com/pytest-dev/apipkg
Author: holger krekel
Maintainer: Ronny Pfannschmidt
Maintainer-email: [email protected]
License: MIT License
License: MIT
Platform: unix
Platform: linux
Platform: osx
Expand All @@ -15,21 +15,27 @@ Platform: win32
Classifier: Development Status :: 4 - Beta
Classifier: Intended Audience :: Developers
Classifier: License :: OSI Approved :: MIT License
Classifier: Operating System :: POSIX
Classifier: Operating System :: Microsoft :: Windows
Classifier: Operating System :: MacOS :: MacOS X
Classifier: Topic :: Software Development :: Libraries
Classifier: Operating System :: Microsoft :: Windows
Classifier: Operating System :: POSIX
Classifier: Programming Language :: Python
Classifier: Programming Language :: Python :: 2
Classifier: Programming Language :: Python :: 2.7
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.4
Classifier: Programming Language :: Python :: 3.5
Classifier: Programming Language :: Python :: 3.6
Requires-Python: >=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*
Classifier: Programming Language :: Python :: 3.7
Classifier: Programming Language :: Python :: 3.8
Classifier: Programming Language :: Python :: 3.9
Classifier: Programming Language :: Python :: Implementation :: CPython
Classifier: Topic :: Software Development :: Libraries
Requires-Python: !=3.0.*,!=3.1.*,!=3.2.*,!=3.3.*,>=2.7
Description-Content-Type: text/x-rst
License-File: LICENSE

Welcome to apipkg!
------------------------
Welcome to apipkg !
-------------------

With apipkg you can control the exported namespace of a Python package and
greatly reduce the number of imports for your users.
Expand All @@ -47,6 +53,7 @@ Tutorial example
Here is a simple ``mypkg`` package that specifies one namespace
and exports two objects imported from different modules::


# mypkg/__init__.py
import apipkg
apipkg.initpkg(__name__, {
Expand Down Expand Up @@ -106,10 +113,13 @@ Feedback?

If you have questions you are welcome to

* join the #pylib channel on irc.freenode.net
* create an issue on https://github.com/pytest-dev/apipkg/issues
* join the **#pytest** channel on irc.libera.chat_
(using an IRC client, via webchat_, or via Matrix_).
* create an issue on the bugtracker_

have fun,
holger krekel
.. _irc.libera.chat: ircs://irc.libera.chat:6697/#pytest
.. _webchat: https://web.libera.chat/#pytest
.. _matrix: https://matrix.to/#/%23pytest:libera.chat
.. _bugtracker: https://github.com/pytest-dev/apipkg/issues


11 changes: 11 additions & 0 deletions py/_vendored_packages/apipkg-2.0.0.dist-info/RECORD
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
apipkg-2.0.0.dist-info/INSTALLER,sha256=zuuue4knoyJ-UwPPXg8fezS7VCrXJQrAP7zeNuwvFQg,4
apipkg-2.0.0.dist-info/LICENSE,sha256=6J7tEHTTqUMZi6E5uAhE9bRFuGC7p0qK6twGEFZhZOo,1054
apipkg-2.0.0.dist-info/METADATA,sha256=GqNwkxraK5UTxObLVXTLc2UqktOPwZnKqdk2ThzHX0A,4292
apipkg-2.0.0.dist-info/RECORD,,
apipkg-2.0.0.dist-info/REQUESTED,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
apipkg-2.0.0.dist-info/WHEEL,sha256=WzZ8cwjh8l0jtULNjYq1Hpr-WCqCRgPr--TX4P5I1Wo,110
apipkg-2.0.0.dist-info/top_level.txt,sha256=3TGS6nmN7kjxhUK4LpPCB3QkQI34QYGrT0ZQGWajoZ8,7
apipkg/__init__.py,sha256=gpbD3O57S9f-LsO2e-XwI6IGISayicfnCq3B5y_8frg,6978
apipkg/__pycache__/__init__.cpython-39.pyc,,
apipkg/__pycache__/version.cpython-39.pyc,,
apipkg/version.py,sha256=bgZFg-f3UKhgE-z2w8RoFrwqRBzJBZkM4_jKFiYB9eU,142
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
Wheel-Version: 1.0
Generator: bdist_wheel (0.31.1)
Generator: bdist_wheel (0.37.0)
Root-Is-Purelib: true
Tag: py2-none-any
Tag: py3-none-any
Expand Down
88 changes: 48 additions & 40 deletions py/_vendored_packages/apipkg/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,15 @@
import sys
from types import ModuleType

from .version import version as __version__
from .version import version as __version__ # NOQA:F401


def _py_abspath(path):
"""
special version of abspath
that will leave paths from jython jars alone
"""
if path.startswith('__pyclasspath__'):
if path.startswith("__pyclasspath__"):

return path
else:
Expand All @@ -28,6 +28,7 @@ def distribution_version(name):
"""try to get the version of the named distribution,
returs None on failure"""
from pkg_resources import get_distribution, DistributionNotFound

try:
dist = get_distribution(name)
except DistributionNotFound:
Expand All @@ -41,35 +42,37 @@ def initpkg(pkgname, exportdefs, attr=None, eager=False):
attr = attr or {}
oldmod = sys.modules.get(pkgname)
d = {}
f = getattr(oldmod, '__file__', None)
f = getattr(oldmod, "__file__", None)
if f:
f = _py_abspath(f)
d['__file__'] = f
if hasattr(oldmod, '__version__'):
d['__version__'] = oldmod.__version__
if hasattr(oldmod, '__loader__'):
d['__loader__'] = oldmod.__loader__
if hasattr(oldmod, '__path__'):
d['__path__'] = [_py_abspath(p) for p in oldmod.__path__]
if hasattr(oldmod, '__package__'):
d['__package__'] = oldmod.__package__
if '__doc__' not in exportdefs and getattr(oldmod, '__doc__', None):
d['__doc__'] = oldmod.__doc__
d["__file__"] = f
if hasattr(oldmod, "__version__"):
d["__version__"] = oldmod.__version__
if hasattr(oldmod, "__loader__"):
d["__loader__"] = oldmod.__loader__
if hasattr(oldmod, "__path__"):
d["__path__"] = [_py_abspath(p) for p in oldmod.__path__]
if hasattr(oldmod, "__package__"):
d["__package__"] = oldmod.__package__
if "__doc__" not in exportdefs and getattr(oldmod, "__doc__", None):
d["__doc__"] = oldmod.__doc__
d["__spec__"] = getattr(oldmod, "__spec__", None)
d.update(attr)
if hasattr(oldmod, "__dict__"):
oldmod.__dict__.update(d)
mod = ApiModule(pkgname, exportdefs, implprefix=pkgname, attr=d)
sys.modules[pkgname] = mod
# eagerload in bypthon to avoid their monkeypatching breaking packages
if 'bpython' in sys.modules or eager:
if "bpython" in sys.modules or eager:
for module in list(sys.modules.values()):
if isinstance(module, ApiModule):
module.__dict__
return mod


def importobj(modpath, attrname):
"""imports a module, then resolves the attrname on it"""
module = __import__(modpath, None, None, ['__doc__'])
module = __import__(modpath, None, None, ["__doc__"])
if not attrname:
return module

Expand All @@ -82,20 +85,22 @@ def importobj(modpath, attrname):

class ApiModule(ModuleType):
"""the magical lazy-loading module standing"""

def __docget(self):
try:
return self.__doc
except AttributeError:
if '__doc__' in self.__map__:
return self.__makeattr('__doc__')
if "__doc__" in self.__map__:
return self.__makeattr("__doc__")

def __docset(self, value):
self.__doc = value

__doc__ = property(__docget, __docset)

def __init__(self, name, importspec, implprefix=None, attr=None):
self.__name__ = name
self.__all__ = [x for x in importspec if x != '__onfirstaccess__']
self.__all__ = [x for x in importspec if x != "__onfirstaccess__"]
self.__map__ = {}
self.__implprefix__ = implprefix or name
if attr:
Expand All @@ -104,47 +109,47 @@ def __init__(self, name, importspec, implprefix=None, attr=None):
setattr(self, name, val)
for name, importspec in importspec.items():
if isinstance(importspec, dict):
subname = '%s.%s' % (self.__name__, name)
subname = "{}.{}".format(self.__name__, name)
apimod = ApiModule(subname, importspec, implprefix)
sys.modules[subname] = apimod
setattr(self, name, apimod)
else:
parts = importspec.split(':')
parts = importspec.split(":")
modpath = parts.pop(0)
attrname = parts and parts[0] or ""
if modpath[0] == '.':
if modpath[0] == ".":
modpath = implprefix + modpath

if not attrname:
subname = '%s.%s' % (self.__name__, name)
subname = "{}.{}".format(self.__name__, name)
apimod = AliasModule(subname, modpath)
sys.modules[subname] = apimod
if '.' not in name:
if "." not in name:
setattr(self, name, apimod)
else:
self.__map__[name] = (modpath, attrname)

def __repr__(self):
repr_list = []
if hasattr(self, '__version__'):
if hasattr(self, "__version__"):
repr_list.append("version=" + repr(self.__version__))
if hasattr(self, '__file__'):
repr_list.append('from ' + repr(self.__file__))
if hasattr(self, "__file__"):
repr_list.append("from " + repr(self.__file__))
if repr_list:
return '<ApiModule %r %s>' % (self.__name__, " ".join(repr_list))
return '<ApiModule %r>' % (self.__name__,)
return "<ApiModule {!r} {}>".format(self.__name__, " ".join(repr_list))
return "<ApiModule {!r}>".format(self.__name__)

def __makeattr(self, name):
"""lazily compute value for name or raise AttributeError if unknown."""
# print "makeattr", self.__name__, name
target = None
if '__onfirstaccess__' in self.__map__:
target = self.__map__.pop('__onfirstaccess__')
if "__onfirstaccess__" in self.__map__:
target = self.__map__.pop("__onfirstaccess__")
importobj(*target)()
try:
modpath, attrname = self.__map__[name]
except KeyError:
if target is not None and name != '__onfirstaccess__':
if target is not None and name != "__onfirstaccess__":
# retry, onfirstaccess might have set attrs
return getattr(self, name)
raise AttributeError(name)
Expand All @@ -163,10 +168,10 @@ def __makeattr(self, name):
def __dict__(self):
# force all the content of the module
# to be loaded when __dict__ is read
dictdescr = ModuleType.__dict__['__dict__']
dictdescr = ModuleType.__dict__["__dict__"]
dict = dictdescr.__get__(self)
if dict is not None:
hasattr(self, 'some')
hasattr(self, "some")
for name in self.__all__:
try:
self.__makeattr(name)
Expand All @@ -186,19 +191,22 @@ def getmod():
mod.append(x)
return mod[0]

class AliasModule(ModuleType):
x = modpath + ("." + attrname if attrname else "")
repr_result = "<AliasModule {!r} for {!r}>".format(modname, x)

class AliasModule(ModuleType):
def __repr__(self):
x = modpath
if attrname:
x += "." + attrname
return '<AliasModule %r for %r>' % (modname, x)
return repr_result

def __getattribute__(self, name):
try:
return getattr(getmod(), name)
except ImportError:
return None
if modpath == "pytest" and attrname is None:
# hack for pylibs py.test
return None
else:
raise

def __setattr__(self, name, value):
setattr(getmod(), name, value)
Expand Down
3 changes: 2 additions & 1 deletion py/_vendored_packages/apipkg/version.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# coding: utf-8
# file generated by setuptools_scm
# don't change, don't track in version control
version = '1.5'
version = '2.0.0'
version_tuple = (2, 0, 0)
2 changes: 1 addition & 1 deletion py/_vendored_packages/iniconfig-1.1.1.dist-info/RECORD
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
../../../../home/ran/.cache/pycache/tmp/pip-target-oxds71ih/lib/python/iniconfig/__init__.cpython-39.pyc,,
iniconfig-1.1.1.dist-info/INSTALLER,sha256=zuuue4knoyJ-UwPPXg8fezS7VCrXJQrAP7zeNuwvFQg,4
iniconfig-1.1.1.dist-info/LICENSE,sha256=KvaAw570k_uCgwNW0dPfGstaBgM8ui3sehniHKp3qGY,1061
iniconfig-1.1.1.dist-info/METADATA,sha256=_4-oFKpRXuZv5rzepScpXRwhq6DzqsgbnA5ZpgMUMcs,2405
Expand All @@ -8,4 +7,5 @@ iniconfig-1.1.1.dist-info/WHEEL,sha256=ADKeyaGyKF5DwBNE0sRE5pvW-bSkFMJfBuhzZ3rce
iniconfig-1.1.1.dist-info/top_level.txt,sha256=7KfM0fugdlToj9UW7enKXk2HYALQD8qHiyKtjhSzgN8,10
iniconfig/__init__.py,sha256=-pBe5AF_6aAwo1CxJQ8i_zJq6ejc6IxHta7qk2tNJhY,5208
iniconfig/__init__.pyi,sha256=-4KOctzq28ohRmTZsqlH6aylyFqsNKxYqtk1dteypi4,1205
iniconfig/__pycache__/__init__.cpython-39.pyc,,
iniconfig/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
6 changes: 6 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
[build-system]
requires = [
"setuptools",
"setuptools_scm[toml]",
]
build-backend = "setuptools.build_meta"
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ def main():
description='library with cross-python path, ini-parsing, io, code, log facilities',
long_description=open('README.rst').read(),
use_scm_version={"write_to": "py/_version.py"},
setup_requires=["setuptools-scm"],
setup_requires=["setuptools_scm"],
url='https://py.readthedocs.io/',
license='MIT license',
platforms=['unix', 'linux', 'osx', 'cygwin', 'win32'],
Expand Down
3 changes: 1 addition & 2 deletions testing/log/test_warning.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@
mypath = py.path.local(__file__).new(ext=".py")


win = sys.platform.startswith('win')
pytestmark = pytest.mark.skipif(win and LooseVersion(pytest.__version__) >= LooseVersion('3.1'),
pytestmark = pytest.mark.skipif(LooseVersion(pytest.__version__) >= LooseVersion('3.1'),
reason='apiwarn is not compatible with pytest >= 3.1 (#162)')


Expand Down

0 comments on commit e116b2b

Please sign in to comment.