Skip to content

Support XDG Base Directory Specification #830

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

Closed
wants to merge 1 commit into from
Closed
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
15 changes: 14 additions & 1 deletion twine/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,20 @@
DEFAULT_REPOSITORY = "https://upload.pypi.org/legacy/"
TEST_REPOSITORY = "https://test.pypi.org/legacy/"

DEFAULT_CONFIG_FILE = "~/.pypirc"
# Obtain config file location following XDG spec
XDG_CONFIG_HOME = os.environ.get(
"XDG_CONFIG_HOME", os.path.join(os.path.expanduser("~"), ".config")
)
XDG_CONFIG_FILE = os.path.join(XDG_CONFIG_HOME, "pypi", "pypirc")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I should have noticed this in your suggestion on the PR: I don't think Twine should unilaterally decide to put its configuration in a pypi directory. First, I don't think it's accurate; despite the name, .pypirc can be used to define other package repositories besides PyPI. It could be twine, but I think it's also worth keeping in mind that other tools (like flit) can use .pypirc. So maybe it should be be pypa, but I'd want buy-in from other PyPA maintainers before claiming that name.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@pradyunsg I'm particularly interested in your thoughts from pip's perspective.

Maybe also @takluyver, with flit's perspective.


# Obtain old config file location to add backward compatibility
OLD_CONFIG_FILE = os.path.join(os.path.expanduser("~"), ".pypirc")

# Obtain config file, ${HOME}/.pypirc if exists else
# ${XDG_CONFIG_HOME}/pypi/pypirc
DEFAULT_CONFIG_FILE = (
OLD_CONFIG_FILE if os.path.isfile(OLD_CONFIG_FILE) else XDG_CONFIG_FILE
)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd prefer using pathlib, which I think makes this more readable:

XDG_CONFIG_HOME = os.environ.get("XDG_CONFIG_HOME", Path.home() /  ".config")
XDG_CONFIG_FILE = XDG_CONFIG_HOME / "pypa" / "pypirc"

HOME_CONFIG_FILE = Path.home() / ".pypirc"

DEFAULT_CONFIG_FILE = (
    HOME_CONFIG_FILE if HOME_CONFIG_FILE.is_file() else XDG_CONFIG_FILE
)


# TODO: In general, it seems to be assumed that the values retrieved from
# instances of this type aren't None, except for username and password.
Expand Down