Skip to content

Commit

Permalink
Remove _expand and _str_to_python_value
Browse files Browse the repository at this point in the history
  • Loading branch information
damoncro committed Dec 2, 2021
1 parent 5948b55 commit 23fbc32
Showing 1 changed file with 0 additions and 40 deletions.
40 changes: 0 additions & 40 deletions pystarport/expansion.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
import os
import re
from pathlib import Path
from typing import Any, Mapping, Optional, Text

import yaml
from dotenv import dotenv_values, load_dotenv
from dotenv.variables import parse_variables


def expand_posix_vars(obj: Any, variables: Mapping[Text, Optional[Any]]) -> Any:
Expand All @@ -21,47 +19,9 @@ def expand_posix_vars(obj: Any, variables: Mapping[Text, Optional[Any]]) -> Any:
elif isinstance(obj, (list,)):
for index in range(len(obj)):
obj[index] = expand_posix_vars(obj[index], variables)
elif isinstance(obj, (str,)):
obj = _str_to_python_value(_expand(obj, variables))
return obj


def _expand(value, variables={}):
"""_expand does POSIX-style variable expansion
This is adapted from python-dotenv, specifically here:
https://github.com/theskumar/python-dotenv/commit/17dba65244c1d4d10f591fe37c924bd2c6fd1cfc
We need this layer here so we can explicitly pass in variables;
python-dotenv assumes you want to use os.environ.
"""

if not isinstance(value, (str,)):
return value
atoms = parse_variables(value)
return "".join([str(atom.resolve(variables)) for atom in atoms])


INT_REGEX = re.compile(r"^[-+]?[0-9]+$")


def _str_to_python_value(val):
"""_str_to_python_value infers the data type from a string.
This could eventually use PyYAML's parsing logic.
"""
if not isinstance(val, (str,)):
return val
elif val == "true" or val == "True" or val == "on":
return True
elif val == "false" or val == "False" or val == "off":
return False
# elif INT_REGEX.match(val):
# return int(val)
return val


def expand_yaml(config_path, dotenv):
config = yaml.safe_load(open(config_path))

Expand Down

0 comments on commit 23fbc32

Please sign in to comment.