Skip to content

Commit 4c611fa

Browse files
Replace pkg_resources with importlib.metadata
* Replace pkg_resources with importlib.metadata * Add importlib-metadata to requirements for python_version < "3.8" Signed-off-by: Gaurav Talreja <gtalreja@redhat.com> Co-authored-by: Evgeni Golov <evgeni@golov.de>
1 parent 30842f7 commit 4c611fa

File tree

2 files changed

+8
-5
lines changed

2 files changed

+8
-5
lines changed

requirements-dev.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ rpm; python_version >= '3.12'
1212
rstcheck==3.5.0 # from https://github.com/ansible/ansible/raw/devel/test/sanity/code-smell/rstcheck.requirements.txt
1313
docker
1414
cryptography<3.1; python_version < '3.7'
15+
importlib-metadata; python_version < '3.8'
1516
-r requirements.txt
1617
pylint==2.6.0; python_version > '3.0' and python_version <= '3.8' # py 3.8 is used for "stable" ansible, but only devel has pylint rules for newer pylints
1718
pylint==2.17.3; python_version >= '3.9' # from https://raw.githubusercontent.com/ansible/ansible/devel/test/lib/ansible_test/_data/requirements/sanity.pylint.txt

tests/conftest.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,10 @@
22
import os
33

44
import ansible_runner
5-
import pkg_resources
5+
try:
6+
from importlib.metadata import version, PackageNotFoundError
7+
except ModuleNotFoundError:
8+
from importlib_metadata import version, PackageNotFoundError
69
import pytest
710
import py.path
811
import yaml
@@ -112,13 +115,12 @@ def run_playbook_vcr(tmpdir, module, extra_vars=None, limit=None, inventory=None
112115

113116

114117
def get_ansible_version():
115-
ansible_version = '2.14.0'
116118
for ansible_name in ['ansible', 'ansible-base', 'ansible-core']:
117119
try:
118-
ansible_version = pkg_resources.get_distribution(ansible_name).version
119-
except pkg_resources.DistributionNotFound:
120+
return version(ansible_name)
121+
except PackageNotFoundError:
120122
pass
121-
return ansible_version
123+
return '2.14.0'
122124

123125

124126
def assert_no_warnings(run):

0 commit comments

Comments
 (0)