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

Add tests for config #236

Merged
merged 2 commits into from
Aug 1, 2024
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
3 changes: 3 additions & 0 deletions .config/dictionary.txt
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ fileh
fqcn
levelname
netcommon
platinclude
platlib
platstdlib
purelib
reqs
setenv
Expand Down
15 changes: 11 additions & 4 deletions src/ansible_dev_environment/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,15 +65,19 @@ def cache_dir(self: Config) -> Path:

@property
def venv(self: Config) -> Path:
"""Return the virtual environment path."""
"""Return the virtual environment path.

Raises:
SystemExit: If the virtual environment cannot be found.
"""
if self.args.venv:
return Path(self.args.venv).expanduser().resolve()
venv_str = os.environ.get("VIRTUAL_ENV")
if venv_str:
return Path(venv_str).expanduser().resolve()
err = "Failed to find a virtual environment."
self._output.critical(err)
sys.exit(1)
raise SystemExit(1) # pragma: no cover # critical exits

@property
def venv_cache_dir(self: Config) -> Path:
Expand Down Expand Up @@ -109,10 +113,13 @@ def interpreter(self: Config) -> Path:
return Path(sys.executable)

@property
def galaxy_bin(self: Config) -> Path | None:
def galaxy_bin(self: Config) -> Path:
"""Find the ansible galaxy command.

Prefer the venv over the system package over the PATH.

Raises:
SystemExit: If the command cannot be found.
"""
within_venv = self.venv_bindir / "ansible-galaxy"
if within_venv.exists():
Expand All @@ -131,7 +138,7 @@ def galaxy_bin(self: Config) -> Path | None:
return Path(last_resort)
msg = "Failed to find ansible-galaxy."
self._output.critical(msg)
return None
raise SystemExit(1) # pragma: no cover # critical exits

def _set_interpreter(
self: Config,
Expand Down
Loading
Loading