Skip to content

Commit 2f6a07a

Browse files
Merge branch 'main' into maintain-2.1.x
2 parents 4289a67 + 74b782e commit 2f6a07a

File tree

8 files changed

+61
-109
lines changed

8 files changed

+61
-109
lines changed

.github/workflows/pre-commit.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,6 @@ jobs:
99
pre-commit:
1010
runs-on: ubuntu-latest
1111
steps:
12-
- uses: actions/checkout@v2
13-
- uses: actions/setup-python@v2
14-
- uses: pre-commit/[email protected].0
12+
- uses: actions/checkout@v3
13+
- uses: actions/setup-python@v3
14+
- uses: pre-commit/[email protected].3

.github/workflows/pythonapp.yml

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -16,18 +16,18 @@ jobs:
1616
runs-on: ubuntu-latest
1717
name: Python sdist/wheel
1818
steps:
19-
- uses: actions/checkout@v1
20-
- uses: actions/setup-python@v2
19+
- uses: actions/checkout@v3
20+
- uses: actions/setup-python@v3
2121
with:
22-
python-version: "3.9"
22+
python-version: "3.10"
2323
- name: Install dependencies
2424
run: |
2525
python -m pip install --upgrade pip
2626
pip install --upgrade wheel setuptools build
2727
2828
- name: Build package
2929
run: python -m build -o dist/
30-
- uses: actions/upload-artifact@v2
30+
- uses: actions/upload-artifact@v3
3131
with:
3232
name: dist
3333
path: dist
@@ -38,27 +38,27 @@ jobs:
3838
strategy:
3939
matrix:
4040
# todo: extract from source
41-
python-version: [2.7, 3.5, 3.6, 3.7, 3.8, 3.9, "3.10-dev"]
41+
python-version: [3.7, 3.8, 3.9, "3.10", "3.11-dev"]
4242
install-from: ["dist/*.whl"]
4343
include:
44-
- python-version: 3.9
44+
- python-version: "3.10"
4545
install-from: "-e ."
46-
- python-version: 3.9
46+
- python-version: "3.10"
4747
install-from: "."
48-
- python-version: 3.9
48+
- python-version: "3.10"
4949
install-from: "dist/*.tar.gz"
5050
steps:
51-
- uses: actions/checkout@v1
51+
- uses: actions/checkout@v3
5252
- name: Set up Python ${{ matrix.python-version }}
53-
uses: actions/setup-python@v2
53+
uses: actions/setup-python@v3
5454
with:
5555
python-version: ${{ matrix.python-version }}
5656
- name: Install dependencies
5757
run: |
5858
python -m pip install --upgrade pip
5959
pip install -U setuptools setuptools_scm
6060
pip install pytest
61-
- uses: actions/download-artifact@v2
61+
- uses: actions/download-artifact@v3
6262
with:
6363
name: dist
6464
path: dist
@@ -72,10 +72,10 @@ jobs:
7272
runs-on: ubuntu-latest
7373
needs: [dist]
7474
steps:
75-
- uses: actions/setup-python@v2
75+
- uses: actions/setup-python@v3
7676
with:
77-
python-version: "3.9"
78-
- uses: actions/download-artifact@v2
77+
python-version: "3.10"
78+
- uses: actions/download-artifact@v3
7979
with:
8080
name: dist
8181
path: dist
@@ -87,7 +87,7 @@ jobs:
8787
if: github.event_name == 'push' && startsWith(github.event.ref, 'refs/tags')
8888
needs: [dist_check, test]
8989
steps:
90-
- uses: actions/download-artifact@v2
90+
- uses: actions/download-artifact@v3
9191
with:
9292
name: dist
9393
path: dist

.pre-commit-config.yaml

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
repos:
22
- repo: https://github.com/psf/black
3-
rev: 20.8b1
3+
rev: 22.3.0
44
hooks:
55
- id: black
66
args: [--safe, --quiet]
77
- repo: https://github.com/pre-commit/pre-commit-hooks
8-
rev: v3.4.0
8+
rev: v4.2.0
99
hooks:
1010
- id: trailing-whitespace
1111
- id: end-of-file-fixer
@@ -15,23 +15,22 @@ repos:
1515
- id: debug-statements
1616
language_version: python3
1717
- repo: https://gitlab.com/pycqa/flake8
18-
rev: 3.8.4
18+
rev: 3.9.2
1919
hooks:
2020
- id: flake8
2121
language_version: python3
2222
additional_dependencies:
2323
- flake8-typing-imports==1.9.0
2424
- repo: https://github.com/asottile/reorder_python_imports
25-
rev: v2.3.6
25+
rev: v3.1.0
2626
hooks:
2727
- id: reorder-python-imports
2828
args: ['--application-directories=.:src']
2929
- repo: https://github.com/asottile/pyupgrade
30-
rev: v2.8.0
30+
rev: v2.32.1
3131
hooks:
3232
- id: pyupgrade
3333
- repo: https://github.com/asottile/setup-cfg-fmt
34-
rev: v1.16.0
34+
rev: v1.20.1
3535
hooks:
3636
- id: setup-cfg-fmt
37-
args: [--min-py3-version=3.4]

README.rst

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ Welcome to apipkg !
33

44
With apipkg you can control the exported namespace of a Python package and
55
greatly reduce the number of imports for your users.
6-
It is a `small pure Python module`_ that works on CPython 2.7 and 3.4+,
6+
It is a `small pure Python module`_ that works on CPython 3.7+,
77
Jython and PyPy. It cooperates well with Python's ``help()`` system,
88
custom importers (PEP302) and common command-line completion tools.
99

@@ -15,8 +15,9 @@ Tutorial example
1515
-------------------
1616

1717
Here is a simple ``mypkg`` package that specifies one namespace
18-
and exports two objects imported from different modules::
18+
and exports two objects imported from different modules:
1919

20+
.. code-block:: python
2021
2122
# mypkg/__init__.py
2223
import apipkg
@@ -37,7 +38,9 @@ regular Python package.
3738
Namespace dictionaries contain ``name: value`` mappings
3839
where the value may be another namespace dictionary or
3940
a string specifying an import location. On accessing
40-
an namespace attribute an import will be performed::
41+
an namespace attribute an import will be performed:
42+
43+
.. code-block:: pycon
4144
4245
>>> import mypkg
4346
>>> mypkg.path
@@ -55,7 +58,9 @@ loaded when they are accessed. This means:
5558
* only the root "mypkg" ever needs to be imported to get
5659
access to the complete functionality
5760
58-
* the underlying modules are also accessible, for example::
61+
* the underlying modules are also accessible, for example:
62+
63+
.. code-block:: python
5964
6065
from mypkg.sub import Class1
6166

setup.cfg

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,24 +23,22 @@ classifiers =
2323
Operating System :: Microsoft :: Windows
2424
Operating System :: POSIX
2525
Programming Language :: Python
26-
Programming Language :: Python :: 2
27-
Programming Language :: Python :: 2.7
2826
Programming Language :: Python :: 3
29-
Programming Language :: Python :: 3.5
30-
Programming Language :: Python :: 3.6
27+
Programming Language :: Python :: 3 :: Only
3128
Programming Language :: Python :: 3.7
3229
Programming Language :: Python :: 3.8
3330
Programming Language :: Python :: 3.9
31+
Programming Language :: Python :: 3.10
3432
Programming Language :: Python :: Implementation :: CPython
3533
Topic :: Software Development :: Libraries
3634

3735
[options]
3836
packages = find:
39-
python_requires = >=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*, !=3.4.*
37+
python_requires = >=3.7
4038
package_dir = =src
4139
setup_requires =
4240
setuptools>=30.3.0
43-
setuptools_scm
41+
setuptools-scm
4442

4543
[options.packages.find]
4644
where = src

src/apipkg/__init__.py

Lines changed: 11 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -5,22 +5,15 @@
55
66
(c) holger krekel, 2009 - MIT license
77
"""
8+
import functools
89
import os
910
import sys
11+
import threading
1012
from types import ModuleType
1113

12-
# Prior to Python 3.7 threading support was optional
13-
try:
14-
import threading
15-
except ImportError:
16-
threading = None
17-
else:
18-
import functools
19-
2014
from .version import version as __version__ # NOQA:F401
2115

2216

23-
_PY2 = sys.version_info[0] == 2
2417
_PRESERVED_MODULE_ATTRS = {
2518
"__file__",
2619
"__version__",
@@ -59,14 +52,11 @@ def distribution_version(name):
5952

6053

6154
def initpkg(pkgname, exportdefs, attr=None, eager=False):
62-
""" initialize given package from the export definitions. """
55+
"""initialize given package from the export definitions."""
6356
attr = attr or {}
6457
mod = sys.modules.get(pkgname)
6558

66-
if _PY2:
67-
mod = _initpkg_py2(mod, pkgname, exportdefs, attr=attr)
68-
else:
69-
mod = _initpkg_py3(mod, pkgname, exportdefs, attr=attr)
59+
mod = _initpkg(mod, pkgname, exportdefs, attr=attr)
7060

7161
# eagerload in bypthon to avoid their monkeypatching breaking packages
7262
if "bpython" in sys.modules or eager:
@@ -77,40 +67,8 @@ def initpkg(pkgname, exportdefs, attr=None, eager=False):
7767
return mod
7868

7969

80-
def _initpkg_py2(mod, pkgname, exportdefs, attr=None):
81-
"""Python 2 helper for initpkg.
82-
83-
In Python 2 we can't update __class__ for an instance of types.Module, and
84-
imports are protected by the global import lock anyway, so it is safe for a
85-
module to replace itself during import.
86-
87-
"""
88-
d = {}
89-
f = getattr(mod, "__file__", None)
90-
if f:
91-
f = _py_abspath(f)
92-
d["__file__"] = f
93-
if hasattr(mod, "__version__"):
94-
d["__version__"] = mod.__version__
95-
if hasattr(mod, "__loader__"):
96-
d["__loader__"] = mod.__loader__
97-
if hasattr(mod, "__path__"):
98-
d["__path__"] = [_py_abspath(p) for p in mod.__path__]
99-
if hasattr(mod, "__package__"):
100-
d["__package__"] = mod.__package__
101-
if "__doc__" not in exportdefs and getattr(mod, "__doc__", None):
102-
d["__doc__"] = mod.__doc__
103-
d["__spec__"] = getattr(mod, "__spec__", None)
104-
d.update(attr)
105-
if hasattr(mod, "__dict__"):
106-
mod.__dict__.update(d)
107-
mod = ApiModule(pkgname, exportdefs, implprefix=pkgname, attr=d)
108-
sys.modules[pkgname] = mod
109-
return mod
110-
111-
112-
def _initpkg_py3(mod, pkgname, exportdefs, attr=None):
113-
"""Python 3 helper for initpkg.
70+
def _initpkg(mod, pkgname, exportdefs, attr=None):
71+
"""Helper for initpkg.
11472
11573
Python 3.3+ uses finer grained locking for imports, and checks sys.modules before
11674
acquiring the lock to avoid the overhead of the fine-grained locking. This
@@ -197,7 +155,7 @@ def __init__(self, name, importspec, implprefix=None, attr=None):
197155
setattr(self, name, val)
198156
for name, importspec in importspec.items():
199157
if isinstance(importspec, dict):
200-
subname = "{}.{}".format(self.__name__, name)
158+
subname = f"{self.__name__}.{name}"
201159
apimod = ApiModule(subname, importspec, implprefix)
202160
sys.modules[subname] = apimod
203161
setattr(self, name, apimod)
@@ -209,7 +167,7 @@ def __init__(self, name, importspec, implprefix=None, attr=None):
209167
modpath = implprefix + modpath
210168

211169
if not attrname:
212-
subname = "{}.{}".format(self.__name__, name)
170+
subname = f"{self.__name__}.{name}"
213171
apimod = AliasModule(subname, modpath)
214172
sys.modules[subname] = apimod
215173
if "." not in name:
@@ -225,7 +183,7 @@ def __repr__(self):
225183
repr_list.append("from " + repr(self.__file__))
226184
if repr_list:
227185
return "<ApiModule {!r} {}>".format(self.__name__, " ".join(repr_list))
228-
return "<ApiModule {!r}>".format(self.__name__)
186+
return f"<ApiModule {self.__name__!r}>"
229187

230188
@_synchronized
231189
def __makeattr(self, name, isgetattr=False):
@@ -252,7 +210,7 @@ def __makeattr(self, name, isgetattr=False):
252210
# * Only call __getattribute__ if there is a possibility something has set
253211
# the attribute we're looking for since __getattr__ was called
254212
if threading is not None and isgetattr:
255-
return super(ApiModule, self).__getattribute__(name)
213+
return super().__getattribute__(name)
256214
raise AttributeError(name)
257215
else:
258216
result = importobj(modpath, attrname)
@@ -294,7 +252,7 @@ def getmod():
294252
return mod[0]
295253

296254
x = modpath + ("." + attrname if attrname else "")
297-
repr_result = "<AliasModule {!r} for {!r}>".format(modname, x)
255+
repr_result = f"<AliasModule {modname!r} for {x!r}>"
298256

299257
class AliasModule(ModuleType):
300258
def __repr__(self):

0 commit comments

Comments
 (0)