From 603fdd8b4f9b62cb284dbffe0d45317de700766a Mon Sep 17 00:00:00 2001 From: Sorin Sbarnea Date: Tue, 31 Aug 2021 12:45:40 +0100 Subject: [PATCH] Remove dependency on setuptools Fixes: #3219 --- constraints.txt | 2 ++ mypy.ini | 3 --- setup.cfg | 3 ++- src/molecule/__init__.py | 4 ++-- src/molecule/driver/base.py | 4 ++-- src/molecule/shell.py | 4 ++-- src/molecule/test/functional/conftest.py | 6 +++--- 7 files changed, 13 insertions(+), 13 deletions(-) diff --git a/constraints.txt b/constraints.txt index d7fef8aa7b..412bac9e7e 100644 --- a/constraints.txt +++ b/constraints.txt @@ -26,6 +26,7 @@ distro==1.6.0 enrich==1.2.6 execnet==1.9.0 idna==3.2 +importlib-metadata==4.8.1 ; python_version > "3.7" iniconfig==1.1.1 jinja2==3.0.1 jinja2-time==0.2.0 @@ -63,6 +64,7 @@ subprocess-tee==0.3.2 text-unidecode==1.3 toml==0.10.2 urllib3==1.26.6 +zipp==3.5.0 # The following packages are considered to be unsafe in a requirements file: # setuptools diff --git a/mypy.ini b/mypy.ini index 99346acdd7..c10054b53b 100644 --- a/mypy.ini +++ b/mypy.ini @@ -31,9 +31,6 @@ ignore_missing_imports = True [mypy-ruamel] ignore_missing_imports = True -[mypy-setuptools] -ignore_missing_imports = True - [mypy-testinfra.*] ignore_missing_imports = True diff --git a/setup.cfg b/setup.cfg index 50e5234fd7..5b940f962a 100644 --- a/setup.cfg +++ b/setup.cfg @@ -73,6 +73,8 @@ install_requires = cookiecutter >= 1.7.3 # dependency issues in older versions dataclasses; python_version<"3.7" enrich >= 1.2.5 + importlib-metadata<2; python_version<="3.7" + importlib-metadata; python_version>"3.7" Jinja2 >= 2.11.3 packaging paramiko >= 2.5.0, < 3 @@ -80,7 +82,6 @@ install_requires = PyYAML >= 5.1, < 6 rich >= 9.5.1 subprocess-tee >= 0.3.2 - setuptools >= 42 # for pkg_resources # selinux python module is needed as least by ansible-docker/podman modules # and allows us of isolated (default) virtualenvs. It does not avoid need # to install the system selinux libraries but it will provide a clear diff --git a/src/molecule/__init__.py b/src/molecule/__init__.py index 99418861f8..428397f8f0 100644 --- a/src/molecule/__init__.py +++ b/src/molecule/__init__.py @@ -25,8 +25,8 @@ __metaclass__ = type try: - import pkg_resources + import importlib_metadata - __version__ = pkg_resources.get_distribution("molecule").version + __version__ = importlib_metadata.version("molecule") # type: ignore except Exception: __version__ = "unknown" diff --git a/src/molecule/driver/base.py b/src/molecule/driver/base.py index 0384b9b0a3..caca7e0f67 100644 --- a/src/molecule/driver/base.py +++ b/src/molecule/driver/base.py @@ -24,7 +24,7 @@ from abc import ABCMeta, abstractmethod from typing import Dict -import pkg_resources +from importlib_metadata import version import molecule from molecule.status import Status @@ -45,7 +45,7 @@ def __init__(self, config=None): self._config = config self._path = os.path.abspath(os.path.dirname(inspect.getfile(self.__class__))) self.module = self.__module__.split(".", maxsplit=1)[0] - self.version = pkg_resources.get_distribution(self.module).version + self.version = version(self.module) @property @abstractmethod diff --git a/src/molecule/shell.py b/src/molecule/shell.py index 27c789f06e..b47d306c25 100644 --- a/src/molecule/shell.py +++ b/src/molecule/shell.py @@ -23,7 +23,7 @@ import sys import click -import pkg_resources +import packaging from ansible_compat.runtime import Runtime import molecule @@ -56,7 +56,7 @@ def print_version(ctx, param, value): if not value or ctx.resilient_parsing: return - v = pkg_resources.parse_version(molecule.__version__) + v = packaging.version.Version(molecule.__version__) color = "bright_yellow" if v.is_prerelease else "green" msg = f"molecule [{color}]{v}[/] using python [repr.number]{sys.version_info[0]}.{sys.version_info[1]}[/] \n" diff --git a/src/molecule/test/functional/conftest.py b/src/molecule/test/functional/conftest.py index d94104f783..b8a526a932 100644 --- a/src/molecule/test/functional/conftest.py +++ b/src/molecule/test/functional/conftest.py @@ -25,8 +25,8 @@ from subprocess import PIPE from typing import Optional +import importlib_metadata import pexpect -import pkg_resources import pytest from ansible_compat.runtime import Runtime from packaging.version import Version @@ -47,8 +47,8 @@ @pytest.fixture(scope="session", autouse=True) def require_installed_package(): try: - pkg_resources.require("molecule") - except pkg_resources.DistributionNotFound as e: + importlib_metadata.version("molecule") + except importlib_metadata.PackageNotFoundError as e: pytest.fail( "Functional tests require molecule package to be installed: {}".format(e) )