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

Treat empty environment variables like unset ones #131

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from 1 commit
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
18 changes: 12 additions & 6 deletions appdirs.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,12 @@
system = sys.platform


def getenv(name, default=None):
value = os.getenv(name)
if not value:
value = default
return value
clbarnes marked this conversation as resolved.
Show resolved Hide resolved


def user_data_dir(appname=None, appauthor=None, version=None, roaming=False):
r"""Return full path to the user-specific data dir for this application.
Expand Down Expand Up @@ -89,7 +95,7 @@ def user_data_dir(appname=None, appauthor=None, version=None, roaming=False):
if appname:
path = os.path.join(path, appname)
else:
path = os.getenv('XDG_DATA_HOME', os.path.expanduser("~/.local/share"))
path = getenv('XDG_DATA_HOME', os.path.expanduser("~/.local/share"))
if appname:
path = os.path.join(path, appname)
if appname and version:
Expand Down Expand Up @@ -144,7 +150,7 @@ def site_data_dir(appname=None, appauthor=None, version=None, multipath=False):
else:
# XDG default for $XDG_DATA_DIRS
# only first, if multipath is False
path = os.getenv('XDG_DATA_DIRS',
path = getenv('XDG_DATA_DIRS',
os.pathsep.join(['/usr/local/share', '/usr/share']))
clbarnes marked this conversation as resolved.
Show resolved Hide resolved
pathlist = [os.path.expanduser(x.rstrip(os.sep)) for x in path.split(os.pathsep)]
if appname:
Expand Down Expand Up @@ -199,7 +205,7 @@ def user_config_dir(appname=None, appauthor=None, version=None, roaming=False):
if appname:
path = os.path.join(path, appname)
else:
path = os.getenv('XDG_CONFIG_HOME', os.path.expanduser("~/.config"))
path = getenv('XDG_CONFIG_HOME', os.path.expanduser("~/.config"))
if appname:
path = os.path.join(path, appname)
if appname and version:
Expand Down Expand Up @@ -248,7 +254,7 @@ def site_config_dir(appname=None, appauthor=None, version=None, multipath=False)
else:
# XDG default for $XDG_CONFIG_DIRS
# only first, if multipath is False
path = os.getenv('XDG_CONFIG_DIRS', '/etc/xdg')
path = getenv('XDG_CONFIG_DIRS', '/etc/xdg')
pathlist = [os.path.expanduser(x.rstrip(os.sep)) for x in path.split(os.pathsep)]
if appname:
if version:
Expand Down Expand Up @@ -311,7 +317,7 @@ def user_cache_dir(appname=None, appauthor=None, version=None, opinion=True):
if appname:
path = os.path.join(path, appname)
else:
path = os.getenv('XDG_CACHE_HOME', os.path.expanduser('~/.cache'))
path = getenv('XDG_CACHE_HOME', os.path.expanduser('~/.cache'))
if appname:
path = os.path.join(path, appname)
if appname and version:
Expand Down Expand Up @@ -353,7 +359,7 @@ def user_state_dir(appname=None, appauthor=None, version=None, roaming=False):
if system in ["win32", "darwin"]:
path = user_data_dir(appname, appauthor, None, roaming)
else:
path = os.getenv('XDG_STATE_HOME', os.path.expanduser("~/.local/state"))
path = getenv('XDG_STATE_HOME', os.path.expanduser("~/.local/state"))
if appname:
path = os.path.join(path, appname)
if appname and version:
Expand Down