-
Notifications
You must be signed in to change notification settings - Fork 318
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
Conversation
Adds support to XDG Base Directory Specification maintaining backward compatibility. It looks for config file in ${HOME}/.pypirc and ${XDG_CONFIG_HOME}/pypi/pypirc. If both files exist then the first one is used. Closes #754
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for putting this together. I'm still not convinced this is a good thing for Twine to do, so I've asked for review from other maintainers.
Before this can be merged, it will need some automated tests, but I would hold off on making any changes until other folks have reviewed the proposal.
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") |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
# ${XDG_CONFIG_HOME}/pypi/pypirc | ||
DEFAULT_CONFIG_FILE = ( | ||
OLD_CONFIG_FILE if os.path.isfile(OLD_CONFIG_FILE) else XDG_CONFIG_FILE | ||
) |
There was a problem hiding this comment.
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
)
Alternatively, use |
Scratch that -- the location of the pypirc file is taken from how it is defined in https://github.com/python/cpython/blob/v3.10.0/Lib/distutils/config.py#L40 I definitely think this need broader discussion -- likely on discuss.python.org -- about what exactly we want to do here. As @bhrutledge noted, this affects a lot more than just I personally don't really think we should do this for another two years, until Python 3.12 removes |
Yeah, I'm in favor of not adding support for this until there's something that formally says (e.g., on the packaging guide) that this file might live in another directory. And as Brian points out |
I know it's always frustrating when people say this, but... I think we should have a bigger rethink of how index server URLs & credentials are stored, not just the file location. 🙂 A few of the reasons:
|
I appreciate this, @takluyver. There are few issues/discussions about this already (and probably others I'm missing):
I'd like to gather all of this into a discussion on https://discuss.python.org/c/packaging/, but since my sense is that this is not urgent, it might be awhile. If someone else is motivated to kick that off, I'd happily contribute. For now, I'm going to close this, with gratitude to @ogarcia for prompting the discussion. Further comments are welcome, but I think we should avoid going deeper here. |
Adds support to XDG Base Directory Specification maintaining backward compatibility. It looks for config file in
${HOME}/.pypirc
and${XDG_CONFIG_HOME}/pypi/pypirc
. If both files exist then the first one is used. Related / Closes #754