Skip to content

Commit

Permalink
Add audeer.set_or_delete_env_variable()
Browse files Browse the repository at this point in the history
  • Loading branch information
hagenw committed Dec 4, 2024
1 parent b438c9e commit 8fd4875
Showing 1 changed file with 17 additions and 0 deletions.
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

0 comments on commit 8fd4875

Please sign in to comment.