Skip to content

Commit 432f4d6

Browse files
Get attr module version without importlib [RHELDST-32151] (#665)
For python versions older than 3.8, importlib_metadata module needs to be installed separately, however no such RPM package is available for RHEL 8. The whole ordeal of getting the version of attr module currently installed can be done without importing importlib. This commit also updates .gitignore to ignore artifacts generated during local tox runs. --------- Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
1 parent e8ab189 commit 432f4d6

5 files changed

Lines changed: 20 additions & 19 deletions

File tree

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ coverage.xml
4646
*.cover
4747
.hypothesis/
4848
.pytest_cache/
49+
artifacts/
4950

5051
# Translations
5152
*.mo

src/pushsource/_impl/compat_attr.py

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,8 @@
11
import attr
22

3-
# importlib.metadata is available for py3.8 and higher
4-
# previous versions get it from importlib_metadata installed
5-
# from importlib-metadata
6-
try:
7-
from importlib.metadata import version
8-
except ImportError: # pragma: no cover
9-
from importlib_metadata import version
10-
11-
123
# Wrappers for attr module to deal with some incompatibilities between versions
134

14-
15-
ATTR_VERSION = tuple(int(x) for x in (version("attrs")).split(".")[0:2])
5+
ATTR_VERSION = tuple(int(x) for x in attr.__version__.split(".")[0:2])
166

177

188
def s():

test-requirements.in

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,5 @@ pyhamcrest
2020
sphinx
2121
alabaster
2222
pidiff
23-
importlib-resources
2423
bandit
2524
pytest-mock

test-requirements.txt

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -464,10 +464,6 @@ importlib-metadata==8.7.0 \
464464
--hash=sha256:d13b81ad223b890aa16c5471f2ac3056cf76c5f10f82d6f9292f0b415f389000 \
465465
--hash=sha256:e5dd1551894c77868a30651cef00984d50e1002d06942a7101d34870c5f02afd
466466
# via sphinx
467-
importlib-resources==6.5.2 \
468-
--hash=sha256:185f87adef5bcc288449d98fb4fba07cea78bc036455dd44c5fc4a2fe78fed2c \
469-
--hash=sha256:789cfdc3ed28c78b67a06acb8126751ced69a3d5f79c095a98298cd8a760ccec
470-
# via -r test-requirements.in
471467
iniconfig==2.1.0 \
472468
--hash=sha256:3abbd2e30b36733fee78f9c7f7308f2d0050e88f0087fd25c2645f63c773e1c7 \
473469
--hash=sha256:9deba5723312380e77435581c6bf4935c94cbfab9b1ed33ef8d238ea168eb760
@@ -1009,9 +1005,7 @@ virtualenv-api==2.1.18 \
10091005
zipp==3.21.0 \
10101006
--hash=sha256:2c9958f6430a2040341a52eb608ed6dd93ef4392e02ffe219417c1b28b5dd1f4 \
10111007
--hash=sha256:ac1bbe05fd2991f160ebce24ffbac5f6d11d83dc90891255885223d42b3cd931
1012-
# via
1013-
# importlib-metadata
1014-
# importlib-resources
1008+
# via importlib-metadata
10151009

10161010
# WARNING: The following packages were not pinned, but pip requires them to be
10171011
# pinned when the requirements file includes hashes and the requirement is not

tests/test_compat_attr.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
from pushsource._impl import compat_attr
2+
3+
from mock import patch
4+
5+
6+
@patch("attr.s")
7+
def test_attrs(attr_s, monkeypatch):
8+
monkeypatch.setattr(compat_attr, "ATTR_VERSION", (17, 4))
9+
compat_attr.s()
10+
attr_s.assert_called_once_with(frozen=True, slots=True)
11+
12+
13+
@patch("attr.s")
14+
def test_attrs_18_2(attr_s, monkeypatch):
15+
monkeypatch.setattr(compat_attr, "ATTR_VERSION", (18, 2))
16+
compat_attr.s()
17+
attr_s.assert_called_once_with(frozen=True, slots=True, kw_only=True)

0 commit comments

Comments
 (0)