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

Rename environment.get_value_string() to get_value_raw(). #4132

Draft
wants to merge 3 commits into
base: master
Choose a base branch
from
Draft
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
5 changes: 2 additions & 3 deletions src/clusterfuzz/_internal/bot/tasks/utasks/fuzz_task.py
Original file line number Diff line number Diff line change
Expand Up @@ -1172,11 +1172,10 @@ def key_fn(crash):

def _get_issue_metadata_from_environment(variable_name):
"""Get issue metadata from environment."""
values = str(environment.get_value_string(variable_name, '')).split(',')
values = environment.get_value_raw(variable_name, '').split(',')
# Allow a variation with a '_1' to specified. This is needed in cases where
# this is specified in both the job and the bot environment.
values.extend(
str(environment.get_value_string(variable_name + '_1', '')).split(','))
values.extend(environment.get_value_raw(variable_name + '_1', '').split(','))
return [value.strip() for value in values if value.strip()]


Expand Down
14 changes: 11 additions & 3 deletions src/clusterfuzz/_internal/system/environment.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@
import socket
import subprocess
import sys
from typing import Optional
from typing import TypeVar
from typing import Union

import yaml

Expand Down Expand Up @@ -600,9 +603,14 @@ def get_ubsan_disabled_options():
}


def get_value_string(environment_variable, default_value=None):
"""Get environment variable (as a string)."""
return os.getenv(environment_variable, default_value)
# This allows the type checker to notice that if the default value passed to
# `get_value_raw()` is not None, then the function will never return None.
_MaybeStr = TypeVar('MaybeStr', bound=Optional[str])


def get_value_raw(var: str, default: _MaybeStr = None) -> Union[str, _MaybeStr]:
"""Returns environment variable `var` directly, without evaluating it."""
return os.environ.get(var, default)


def get_value(environment_variable, default_value=None, env=None):
Expand Down
Loading