Skip to content

Commit

Permalink
Remove dependency on setuptools (#3221)
Browse files Browse the repository at this point in the history
Fixes: #3219
  • Loading branch information
ssbarnea committed Sep 2, 2021
1 parent cc8f128 commit 37bc4d8
Show file tree
Hide file tree
Showing 6 changed files with 13 additions and 17 deletions.
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
2 changes: 1 addition & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -73,14 +73,14 @@ 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.8"
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
11 changes: 6 additions & 5 deletions src/molecule/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,11 @@
from __future__ import absolute_import, division, print_function

__metaclass__ = type

try:
import pkg_resources
# py38+
from importlib.metadata import version # type: ignore
except ImportError:
# py36-py37
from importlib_metadata import version

__version__ = pkg_resources.get_distribution("molecule").version
except Exception:
__version__ = "unknown"
__version__ = version("molecule")
4 changes: 1 addition & 3 deletions src/molecule/driver/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,6 @@
from abc import ABCMeta, abstractmethod
from typing import Dict

import pkg_resources

import molecule
from molecule.status import Status

Expand All @@ -45,7 +43,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 = molecule.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 @@ -26,11 +26,11 @@
from typing import Optional

import pexpect
import pkg_resources
import pytest
from ansible_compat.runtime import Runtime
from packaging.version import Version

import molecule
from molecule import logger, util
from molecule.test.conftest import change_dir_to, molecule_directory
from molecule.text import strip_ansi_color
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:
molecule.version("molecule")
except Exception as e:
pytest.fail(
"Functional tests require molecule package to be installed: {}".format(e)
)
Expand Down

0 comments on commit 37bc4d8

Please sign in to comment.