Skip to content

Commit

Permalink
Remove dependency on setuptools
Browse files Browse the repository at this point in the history
Fixes: #3219
  • Loading branch information
ssbarnea committed Aug 31, 2021
1 parent b351ea0 commit f7baefa
Show file tree
Hide file tree
Showing 7 changed files with 12 additions and 18 deletions.
2 changes: 2 additions & 0 deletions constraints.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
3 changes: 0 additions & 3 deletions mypy.ini
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
3 changes: 2 additions & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -73,14 +73,15 @@ 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
pluggy >= 0.7.1, < 1.0
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
Expand Down
8 changes: 1 addition & 7 deletions src/molecule/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,4 @@
from __future__ import absolute_import, division, print_function

__metaclass__ = type

try:
import pkg_resources

__version__ = pkg_resources.get_distribution("molecule").version
except Exception:
__version__ = "unknown"
__version__ = importlib_metadata.version("molecule") # type: ignore
4 changes: 2 additions & 2 deletions src/molecule/driver/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
4 changes: 2 additions & 2 deletions src/molecule/shell.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
import sys

import click
import pkg_resources
import packaging
from ansible_compat.runtime import Runtime

import molecule
Expand Down Expand Up @@ -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"

Expand Down
6 changes: 3 additions & 3 deletions src/molecule/test/functional/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)
)
Expand Down

0 comments on commit f7baefa

Please sign in to comment.