Skip to content

Commit df4ca02

Browse files
committed
Drop support for EOL Python 2.7-3.6
1 parent b0d2f01 commit df4ca02

File tree

7 files changed

+16
-71
lines changed

7 files changed

+16
-71
lines changed

.github/workflows/pythonapp.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ 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", "3.11-dev"]
41+
python-version: [3.7, 3.8, 3.9, "3.10", "3.11-dev"]
4242
install-from: ["dist/*.whl"]
4343
include:
4444
- python-version: "3.10"

.pre-commit-config.yaml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,4 +34,3 @@ repos:
3434
rev: v1.20.1
3535
hooks:
3636
- id: setup-cfg-fmt
37-
args: [--min-py3-version=3.4]

README.rst

Lines changed: 1 addition & 1 deletion
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

setup.cfg

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,8 @@ 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.4
30-
Programming Language :: Python :: 3.5
31-
Programming Language :: Python :: 3.6
27+
Programming Language :: Python :: 3 :: Only
3228
Programming Language :: Python :: 3.7
3329
Programming Language :: Python :: 3.8
3430
Programming Language :: Python :: 3.9
@@ -38,7 +34,7 @@ classifiers =
3834

3935
[options]
4036
packages = find:
41-
python_requires = >=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*
37+
python_requires = >=3.7
4238
package_dir = =src
4339
setup_requires =
4440
setuptools>=30.3.0

src/apipkg/__init__.py

Lines changed: 5 additions & 47 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__",
@@ -63,10 +56,7 @@ def initpkg(pkgname, exportdefs, attr=None, eager=False):
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

test_apipkg.py

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2,22 +2,14 @@
22
import subprocess
33
import sys
44
import textwrap
5+
import threading
56
import types
67

7-
try:
8-
import threading
9-
except ImportError:
10-
pass
11-
128
import pytest
139

1410
import apipkg
1511

1612

17-
PY2 = sys.version_info[0] == 2
18-
PY3 = sys.version_info[0] == 3
19-
20-
2113
#
2214
# test support for importing modules
2315
#
@@ -280,7 +272,7 @@ def test_initpkg_updates_sysmodules(monkeypatch):
280272
monkeypatch.setitem(sys.modules, "hello", mod)
281273
apipkg.initpkg("hello", {"x": "os.path:abspath"})
282274
newmod = sys.modules["hello"]
283-
assert (PY2 and newmod != mod) or (PY3 and newmod is mod)
275+
assert newmod is mod
284276
assert newmod.x == os.path.abspath
285277

286278

@@ -295,7 +287,7 @@ def test_initpkg_transfers_attrs(monkeypatch):
295287
monkeypatch.setitem(sys.modules, "hello", mod)
296288
apipkg.initpkg("hello", {})
297289
newmod = sys.modules["hello"]
298-
assert (PY2 and newmod != mod) or (PY3 and newmod is mod)
290+
assert newmod is mod
299291
assert newmod.__file__ == os.path.abspath(mod.__file__)
300292
assert newmod.__version__ == mod.__version__
301293
assert newmod.__loader__ == mod.__loader__
@@ -319,7 +311,7 @@ def test_initpkg_overwrite_doc(monkeypatch):
319311
monkeypatch.setitem(sys.modules, "hello", hello)
320312
apipkg.initpkg("hello", {"__doc__": "sys:__doc__"})
321313
newhello = sys.modules["hello"]
322-
assert (PY2 and newhello != hello) or (PY3 and newhello is hello)
314+
assert newhello is hello
323315
assert newhello.__doc__ == sys.__doc__
324316

325317

@@ -331,7 +323,7 @@ def test_initpkg_not_transfers_not_existing_attrs(monkeypatch):
331323
monkeypatch.setitem(sys.modules, "hello", mod)
332324
apipkg.initpkg("hello", {})
333325
newmod = sys.modules["hello"]
334-
assert (PY2 and newmod != mod) or (PY3 and newmod is mod)
326+
assert newmod is mod
335327
assert newmod.__file__ == os.path.abspath(mod.__file__)
336328
assert not hasattr(newmod, "__path__")
337329
assert not hasattr(newmod, "__package__") or mod.__package__ is None
@@ -344,7 +336,7 @@ def test_initpkg_not_changing_jython_paths(monkeypatch):
344336
monkeypatch.setitem(sys.modules, "hello", mod)
345337
apipkg.initpkg("hello", {})
346338
newmod = sys.modules["hello"]
347-
assert (PY2 and newmod != mod) or (PY3 and newmod is mod)
339+
assert newmod is mod
348340
assert newmod.__file__.startswith("__pyclasspath__")
349341
unchanged, changed = newmod.__path__
350342
assert changed != "ichange"

tox.ini

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
[tox]
2-
envlist=py27,py34,py35,py36,py37,py38,py39,py310,py311
2+
envlist=py37,py38,py39,py310,py311
33

44
[testenv]
55
deps=pytest

0 commit comments

Comments
 (0)