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

Adjusts local_context_data #185

Closed
wants to merge 9 commits into from
Closed
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Updates is_truthy.
  • Loading branch information
jvanderaa committed Jan 14, 2025
commit 5b9555a553f76dc607c9e41b03a3e61e0e8baf96
25 changes: 23 additions & 2 deletions tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import os
import sys
from distutils.util import strtobool
from invoke import task

try:
Expand All @@ -18,6 +17,28 @@
# Can be set to a separate Python version to be used for launching or building image
PYTHON_VER = os.getenv("INVOKE_PYNAUTOBOT_PYTHON_VER", os.getenv("PYTHON_VER", "3.8"))

def is_truthy(arg):
"""Convert "truthy" strings into Booleans.

Examples
--------
>>> is_truthy('yes')
True
Args:
arg (str): Truthy string (True values are y, yes, t, true, on and 1; false values are n, no,
f, false, off and 0. Raises ValueError if val is anything else.
"""
if isinstance(arg, bool):
return arg

val = str(arg).lower()
if val in ("y", "yes", "t", "true", "on", "1"):
return True
elif val in ("n", "no", "f", "false", "off", "0"):
return False
else:
raise ValueError(f"Invalid truthy value: `{arg}`")


def _get_image_name_and_tag():
"""Return image name and tag. Necessary to avoid double build in upstream testing"""
Expand All @@ -37,7 +58,7 @@ def _get_image_name_and_tag():
# Gather current working directory for Docker commands
PWD = os.getcwd()
# Local or Docker execution provide "local" to run locally without docker execution
INVOKE_LOCAL = strtobool(os.getenv("INVOKE_LOCAL", "False"))
INVOKE_LOCAL = is_truthy(os.getenv("INVOKE_LOCAL", "False"))

_DEFAULT_SERVICE = "pynautobot-dev"
_DOCKER_COMPOSE_ENV = {
Expand Down
Loading