diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 512f557c..8f52da94 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -22,7 +22,7 @@ exclude: | )$ repos: - repo: https://github.com/astral-sh/ruff-pre-commit - rev: "v0.4.7" + rev: "v0.5.0" hooks: - id: ruff args: [--fix, --exit-non-zero-on-fix] diff --git a/src/ansible_compat/config.py b/src/ansible_compat/config.py index 94355404..66d73a55 100644 --- a/src/ansible_compat/config.py +++ b/src/ansible_compat/config.py @@ -59,8 +59,8 @@ def ansible_version(version: str = "") -> Version: if version: return Version(version) - proc = subprocess.run( - ["ansible", "--version"], # noqa: S603 + proc = subprocess.run( # noqa: S603 + ["ansible", "--version"], text=True, check=False, capture_output=True, @@ -413,8 +413,8 @@ def __init__( env = os.environ.copy() # Avoid possible ANSI garbage env["ANSIBLE_FORCE_COLOR"] = "0" - config_dump = subprocess.check_output( - ["ansible-config", "dump"], # noqa: S603 + config_dump = subprocess.check_output( # noqa: S603 + ["ansible-config", "dump"], universal_newlines=True, env=env, ) diff --git a/src/ansible_compat/runtime.py b/src/ansible_compat/runtime.py index b05dedd4..9de36307 100644 --- a/src/ansible_compat/runtime.py +++ b/src/ansible_compat/runtime.py @@ -448,9 +448,7 @@ def version_in_range( """ if lower and self.version < Version(lower): return False - if upper and self.version >= Version(upper): - return False - return True + return not (upper and self.version >= Version(upper)) def has_playbook(self, playbook: str, *, basedir: Path | None = None) -> bool: """Return true if ansible can load a given playbook. @@ -701,10 +699,7 @@ def prepare_environment( # noqa: C901 galaxy_path.parent, destination=destination, ) - elif ( - Path().resolve().parent.name == "roles" - and Path("../../galaxy.yml").exists() - ): + elif Path.cwd().parent.name == "roles" and Path("../../galaxy.yml").exists(): # molecule scenario located within roles//molecule inside # a collection self.install_collection_from_disk( diff --git a/test/test_runtime.py b/test/test_runtime.py index ebf99c96..77b420d4 100644 --- a/test/test_runtime.py +++ b/test/test_runtime.py @@ -405,8 +405,8 @@ def test__update_env( def test_require_collection_wrong_version(runtime: Runtime) -> None: """Tests behaviour of require_collection.""" - subprocess.check_output( - [ # noqa: S603 + subprocess.check_output( # noqa: S603 + [ "ansible-galaxy", "collection", "install",