From 671df9f4a85c91fc397b898d4a437c2e1d308d65 Mon Sep 17 00:00:00 2001 From: Sorin Sbarnea Date: Fri, 25 Jun 2021 16:01:11 +0100 Subject: [PATCH] Replace ansible-lint dependency with ansible-compat Related: https://github.com/ansible-community/ansible-compat/issues/4 --- .pre-commit-config.yaml | 3 +-- setup.cfg | 2 +- src/molecule/command/base.py | 3 +-- src/molecule/config.py | 6 ++++-- src/molecule/shell.py | 6 ++++-- src/molecule/test/functional/conftest.py | 6 ++++-- 6 files changed, 15 insertions(+), 11 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 6c6bf786b..d29c07551 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -54,7 +54,7 @@ repos: entry: mypy src/ pass_filenames: false additional_dependencies: - - ansible-lint>=5.0.10 + - ansible-compat - packaging - enrich>=1.2.5 - subprocess-tee>=0.2.0 @@ -63,7 +63,6 @@ repos: hooks: - id: pylint additional_dependencies: - - ansible-lint>=5.0.10 - enrich>=1.2.5 - subprocess-tee>=0.2.0 - testinfra diff --git a/setup.cfg b/setup.cfg index 423d6fa37..34e52c1c4 100644 --- a/setup.cfg +++ b/setup.cfg @@ -66,7 +66,7 @@ setup_requires = # These are required in actual runtime: install_requires = - ansible-lint >= 5.0.12 # only for the prerun functionality + ansible-compat >= 0.1.0 cerberus >= 1.3.1, !=1.3.3, !=1.3.4 click >= 8.0, < 9 click-help-colors >= 0.9 diff --git a/src/molecule/command/base.py b/src/molecule/command/base.py index d32f57c7d..b85b0324a 100644 --- a/src/molecule/command/base.py +++ b/src/molecule/command/base.py @@ -28,7 +28,6 @@ from typing import Any, Callable import click -from ansiblelint.prerun import prepare_environment from click_help_colors import HelpColorsCommand, HelpColorsGroup import molecule.scenarios @@ -109,7 +108,7 @@ def execute_cmdline_scenarios(scenario_name, args, command_args, ansible_args=() if scenario.config.config["prerun"]: LOG.info("Performing prerun...") - prepare_environment() + scenario.config.runtime.prepare_environment() if command_args.get("subcommand") == "reset": LOG.info("Removing %s" % scenario.ephemeral_directory) diff --git a/src/molecule/config.py b/src/molecule/config.py index d926b8c72..fc231caff 100644 --- a/src/molecule/config.py +++ b/src/molecule/config.py @@ -26,7 +26,8 @@ from typing import Callable, MutableMapping, TypeVar from uuid import uuid4 -from ansiblelint.config import ansible_version +from ansible_compat.runtime import Runtime +from packaging.version import Version from molecule import api, interpolation, platforms, scenario, state, util from molecule.dependency import ansible_galaxy, shell @@ -102,6 +103,7 @@ def __init__(self, molecule_file: str, args={}, command_args={}, ansible_args=() self._action = None self._run_uuid = str(uuid4()) self.project_directory = os.getenv("MOLECULE_PROJECT_DIRECTORY", os.getcwd()) + self.runtime = Runtime(isolated=True) def after_init(self): self.config = self._reget_config() @@ -115,7 +117,7 @@ def write(self) -> None: def ansible_collections_path(self): """Return collection path variable for current version of Ansible.""" # https://github.com/ansible/ansible/pull/70007 - if ansible_version() >= ansible_version("2.10.0.dev0"): + if self.runtime.version >= Version("2.10.0.dev0"): return "ANSIBLE_COLLECTIONS_PATH" else: return "ANSIBLE_COLLECTIONS_PATHS" diff --git a/src/molecule/shell.py b/src/molecule/shell.py index 6fca6103e..d734dccfd 100644 --- a/src/molecule/shell.py +++ b/src/molecule/shell.py @@ -24,12 +24,13 @@ import click import pkg_resources +from ansible_compat.runtime import Runtime import molecule from molecule import command, logger from molecule.api import drivers from molecule.command.base import click_group_ex -from molecule.config import MOLECULE_DEBUG, MOLECULE_VERBOSITY, ansible_version +from molecule.config import MOLECULE_DEBUG, MOLECULE_VERBOSITY from molecule.console import console from molecule.util import do_report, lookup_config_file @@ -59,8 +60,9 @@ def print_version(ctx, param, value): 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" + runtime = Runtime() msg += ( - f" [repr.attrib_name]ansible[/][dim]:[/][repr.number]{ansible_version()}[/]" + f" [repr.attrib_name]ansible[/][dim]:[/][repr.number]{runtime.version}[/]" ) for driver in drivers(): msg += f"\n [repr.attrib_name]{str(driver)}[/][dim]:[/][repr.number]{driver.version}[/][dim] from {driver.module}[/]" diff --git a/src/molecule/test/functional/conftest.py b/src/molecule/test/functional/conftest.py index ebcab1c4a..6dcae644d 100644 --- a/src/molecule/test/functional/conftest.py +++ b/src/molecule/test/functional/conftest.py @@ -28,8 +28,9 @@ import pkg_resources import pytest +from ansible_compat.runtime import Runtime +from packaging.version import Version from molecule import logger, util -from molecule.config import ansible_version from molecule.test.conftest import change_dir_to from molecule.text import strip_ansi_color from molecule.util import run_command @@ -267,4 +268,5 @@ def supports_docker(): def min_ansible(version: str) -> bool: """Ensure current Ansible is newer than a given a minimal one.""" - return ansible_version() >= ansible_version(version) + runtime = Runtime() + return bool(runtime.version >= Version(version))