Skip to content
This repository has been archived by the owner on Jan 8, 2023. It is now read-only.

Lazily load podman executable #82

Merged
Merged
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
14 changes: 7 additions & 7 deletions .github/workflows/tox.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,19 +27,19 @@ jobs:
- tox_env: lint
# - tox_env: docs
- tox_env: py36-ansible29
PREFIX: PYTEST_REQPASS=4
PREFIX: PYTEST_REQPASS=5
- tox_env: py36-ansible210
PREFIX: PYTEST_REQPASS=4
PREFIX: PYTEST_REQPASS=5
- tox_env: py36-ansible211
PREFIX: PYTEST_REQPASS=4
PREFIX: PYTEST_REQPASS=5
- tox_env: py37-ansible211
PREFIX: PYTEST_REQPASS=4
PREFIX: PYTEST_REQPASS=5
- tox_env: py38-ansible211
PREFIX: PYTEST_REQPASS=4
PREFIX: PYTEST_REQPASS=5
- tox_env: py39-ansible211
PREFIX: PYTEST_REQPASS=4
PREFIX: PYTEST_REQPASS=5
- tox_env: py39-devel-ansible211
PREFIX: PYTEST_REQPASS=4
PREFIX: PYTEST_REQPASS=5
- tox_env: packaging

steps:
Expand Down
15 changes: 11 additions & 4 deletions src/molecule_podman/driver.py
Original file line number Diff line number Diff line change
Expand Up @@ -161,10 +161,17 @@ def __init__(self, config=None):
# MOLECULE_PODMAN_EXECUTABLE
# An example could be MOLECULE_PODMAN_EXECUTABLE=podman-remote
self.podman_exec = os.environ.get("MOLECULE_PODMAN_EXECUTABLE", "podman")
self.podman_cmd = distutils.spawn.find_executable(self.podman_exec)
if not self.podman_cmd:
msg = f"command not found in PATH {self.podman_exec}"
util.sysexit_with_message(msg)
self._podman_cmd = None

@property
def podman_cmd(self):
"""Lazily calculate the podman command."""
if not self._podman_cmd:
self._podman_cmd = distutils.spawn.find_executable(self.podman_exec)
if not self._podman_cmd:
msg = f"command not found in PATH {self.podman_exec}"
util.sysexit_with_message(msg)
return self._podman_cmd

@property
def name(self):
Expand Down
8 changes: 8 additions & 0 deletions src/molecule_podman/test/test_driver.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,15 @@
"""Unit tests."""
from molecule import api

from molecule_podman.driver import Podman


def test_driver_is_detected():
"""Asserts that molecule recognizes the driver."""
assert any(str(d) == "podman" for d in api.drivers())


def test_driver_initializes_without_podman_executable(monkeypatch):
"""Make sure we can initiaize driver without having an executable present."""
monkeypatch.setenv("MOLECULE_PODMAN_EXECUTABLE", "bad-executable")
Podman()