Skip to content

Use XDG basedir spec to pypirc #754

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
ogarcia opened this issue May 14, 2021 · 6 comments
Closed

Use XDG basedir spec to pypirc #754

ogarcia opened this issue May 14, 2021 · 6 comments
Labels
feature request question Discussion/decision needed from maintainers

Comments

@ogarcia
Copy link

ogarcia commented May 14, 2021

https://specifications.freedesktop.org/basedir-spec/basedir-spec-latest.html

TL;DR Simply support that pypirc can reside in ${XDG_CONFIG_HOME}/pypi/pypirc. Something like this:

CONFIG_HOME = os.environ.get('XDG_CONFIG_HOME', os.path.join(os.path.expanduser('~'), '.config'))
XDG_TWINE_CONFIG = os.path.join(CONFIG_HOME, 'pypi', 'pypirc')
TWINE_CONFIG = XDG_TWINE_CONFIG if os.path.isfile(XDG_TWINE_CONFIG) else '~/.pypirc'
@sigmavirus24
Copy link
Member

I'm not aware of other Python packaging tools that support XDG like this. If they do, then it makes sense for us to support this. But otherwise, this is going to cause confusion

@bhrutledge
Copy link
Contributor

pip seems to follow the XDG spec: https://pip.pypa.io/en/stable/user_guide/#config-file. It looks like they vendor appdirs for that. It looks like another option is xdg.

While I appreciate apps that do this, instead of cluttering my home directory, I'm not sure it's worth the added complexity in code and documentation to support ~/.pypirc and XDG. But I'm open-minded to hearing a compelling argument. 😉

@bhrutledge bhrutledge added feature request question Discussion/decision needed from maintainers labels May 17, 2021
@bhrutledge
Copy link
Contributor

I'm going to close this due to inactivity. We can reopen it if somebody wants to make a compelling argument for investing in this feature.

@ogarcia
Copy link
Author

ogarcia commented Nov 11, 2021

@bhrutledge first for all sorry for big delay, I completely lost this issue.

I think that the argument of this add complexity in code has no sense, the change is only four lines with backward compatibility:

import os

# Obtain config file location following XDG spec
XDG_CONFIG_HOME = os.environ.get('XDG_CONFIG_HOME', os.path.join(os.path.expanduser('~'), '.config'))
XDG_TWINE_CONFIG = os.path.join(XDG_CONFIG_HOME, 'pypi', 'pypirc')

# Check for old ~/.pypirc to add backward compatibility
OLD_TWINE_CONFIG = os.path.join(os.path.expanduser('~'),'.pypirc')

# Get config file, ~/.pypirc if exists else ~/.config/pypi/pypirc
TWINE_CONFIG = OLD_TWINE_CONFIG if os.path.isfile(OLD_TWINE_CONFIG) else XDG_TWINE_CONFIG

print(TWINE_CONFIG)

I have no arguments other than to follow the XDG specification give order to your home directory, it makes backups easier, it's more clean and more and more softwares follow it.

IMHO, the effort is worth it.

UPDATE: Take note that ~/.pypirc is not used anymore by python.

@bhrutledge
Copy link
Contributor

bhrutledge commented Nov 11, 2021

Take note that ~/.pypirc is not used anymore by python.

That's because distutils is deprecated. As noted in https://packaging.python.org/specifications/pypirc/, it's still used by at least twine and flit (which, according to the docs, also expects it to be in the home directory).

I think that the argument of this add complexity in code has no sense, the change is only four lines with backward compatibility

In general, I would avoid suggesting that ideas make no sense; that's likely to put the person who had the idea on the defensive.

I also think the suggested code might be an over-simplification, and doesn't take into account the current implementation.

.pypirc is loaded in:

def get_config(path: str) -> Dict[str, RepositoryConfig]:

Where path is most likely the default value set in:

twine/twine/settings.py

Lines 231 to 235 in 4c9d8c1

parser.add_argument(
"--config-file",
default=utils.DEFAULT_CONFIG_FILE,
help="The .pypirc config file to use.",
)

Looking at that, I realize that twine does offer an alternative to storing .pypirc in the home directory. IE, you can put it anywhere you want, and name it whatever you want, and use the --config-file option to specify the path.

That said, @ogarcia, if you're motivated to open a PR for this, I'd review it. But I can't promise that it will be merged.

@ogarcia
Copy link
Author

ogarcia commented Nov 11, 2021

In general, I would avoid suggesting that ideas make no sense; that's likely to put the person who had the idea on the defensive.

Sorry about this. English not is my primary lenguage and maybe can be rude.

That said, @ogarcia, if you're motivated to open a PR for this, I'd review it. But I can't promise that it will be merged.

Ok. Knowing that the config is defined in utils.py I think that I can do a PR 😉

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature request question Discussion/decision needed from maintainers
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants