Skip to content

Linux: Empty environment variables should use defaults #130

@clbarnes

Description

@clbarnes

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions