Skip to content

Commit

Permalink
Merge pull request #61 from microsoft/python
Browse files Browse the repository at this point in the history
alternate env settings
  • Loading branch information
sethjuarez committed Aug 14, 2024
2 parents 4214b3d + 41aae2e commit ef8300b
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions runtime/prompty/prompty/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -213,14 +213,16 @@ def _process_file(file: str, parent: Path) -> any:
raise FileNotFoundError(f"File {file} not found")

@staticmethod
def _process_env(variable: str, env_error=True) -> any:
def _process_env(variable: str, env_error=True, default: str = None) -> any:
if variable in os.environ.keys():
return os.environ[variable]
else:
if default:
return default
if env_error:
raise ValueError(f"Variable {variable} not found in environment")
else:
return ""

return ""

@staticmethod
def normalize(attribute: any, parent: Path, env_error=True) -> any:
Expand All @@ -230,7 +232,11 @@ def normalize(attribute: any, parent: Path, env_error=True) -> any:
# check if env or file
variable = attribute[2:-1].split(":")
if variable[0] == "env" and len(variable) > 1:
return Prompty._process_env(variable[1], env_error)
return Prompty._process_env(
variable[1],
env_error,
variable[2] if len(variable) > 2 else None,
)
elif variable[0] == "file" and len(variable) > 1:
return Prompty._process_file(variable[1], parent)
else:
Expand Down

0 comments on commit ef8300b

Please sign in to comment.