Skip to content

add support for loading pypi cred from token and pypirc - #374

Merged
konstin merged 1 commit into
PyO3:masterfrom
houqp:qp_pypi
Nov 10, 2020
Merged

add support for loading pypi cred from token and pypirc#374
konstin merged 1 commit into
PyO3:masterfrom
houqp:qp_pypi

Conversation

@houqp

@houqp houqp commented Nov 1, 2020

Copy link
Copy Markdown
Contributor

Is pypi token is specified through MATURIN_PYPI_TOKEN env var, then it will be used. Next it will look for credentials stored in ~/.pypirc before prompting for username and password.

@konstin

konstin commented Nov 10, 2020

Copy link
Copy Markdown
Member

Thank you!

@konstin
konstin merged commit e5a01c4 into PyO3:master Nov 10, 2020
@houqp
houqp deleted the qp_pypi branch November 10, 2020 17:41
Comment thread src/main.rs
}

if let (Some(username), Some(password)) = (
config.get(package_name, "username"),

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

@houqp Sorry for asking so late, but shouldn't this be the registry name rather than the package name?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

this is because pypi tokens can be scoped to packages. I was expecting users to set token config per package. perhaps we should fallback to the registry when per package config is not found?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Do you have an example file? I've read https://packaging.python.org/specifications/pypirc/ and I only see how you can set username/password per repository, but I haven't found a way to scope this per package.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Ha, looking at the doc again, maybe i misused the config section name. They way i have it configured locally is to set the section name as package name:

[package-name]
repository = https://upload.pypi.org/legacy/
username = __token__
password = API_TOKEN 

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

i think the correct behavior here should be just picking the first repo from index-servers key instead of using package name?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Hmm, I understood the header in square brackets as the name of the repository rather than name of the package, e.g. you could do twine upload -r first-repository myproject/dist/* and twine upload -r first-repository myproject/dist/*, given the example from the docs:

[distutils]
index-servers =
    first-repository
    second-repository

[first-repository]
repository = <first-repository URL>
username = <first-repository username>
password = <first-repository password>

[second-repository]
repository = <second-repository URL>
username = <second-repository username>
password = <second-repository password>

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

yeah, based on the doc, section names are supposed to be mapped to repo name. although i think this is a design issue with pypi, which makes it hard to use package scoped tokens for security best practices, it's better to stick to the official spec to avoid surprises for now.

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

Successfully merging this pull request may close these issues.

2 participants