Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace ansible-lint dependency with ansible-compat #3169

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
2 changes: 1 addition & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 1 addition & 2 deletions src/molecule/command/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down
6 changes: 4 additions & 2 deletions src/molecule/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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()
Expand All @@ -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"
Expand Down
6 changes: 4 additions & 2 deletions src/molecule/shell.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

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