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 audeer.set_or_delete_env_variable() #164

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
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
17 changes: 17 additions & 0 deletions audeer/core/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import inspect
import multiprocessing
import operator
import os
import queue
import subprocess
import sys
Expand Down Expand Up @@ -774,6 +775,22 @@ def sort_key(value):
return sorted(versions, key=sort_key)


def set_or_delete_env_variable(name, value):
"""Set or delete environment variable.

Args:
name: name of environment variable
value: value of environment variable.
If ``None``,
the variable is deleted

"""
if value is None:
del os.environ[name]
else:
os.environ[name] = value


def to_list(x: typing.Any):
"""Convert to list.

Expand Down
Loading