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

Linux: Empty environment variables should use defaults #130

Open
clbarnes opened this issue Feb 19, 2020 · 0 comments
Open

Linux: Empty environment variables should use defaults #130

clbarnes opened this issue Feb 19, 2020 · 0 comments

Comments

@clbarnes
Copy link

I believe appdirs does not conform to the XDG spec when environment variables exist, but are empty.

The XDG spec says:

If $XDG_DATA_HOME is either not set or empty, a default equal to $HOME/.local/share should be used.

However, the implementation here uses path = os.getenv('XDG_DATA_HOME', os.path.expanduser("~/.local/share")), which is correct when the environment variable does not exist, but incorrect when it exists but is empty.

I propose a helper function like

def getenv(name, default=None):
    value = os.getenv(name)
    if not value:
        value = default
    return value

and using that wherever os.getenv is currently used.

This is a breaking change, but necessary for conformance with the XDG spec.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant