Skip to content
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

PyPI Trusted Publisher Support #1868

Closed
BlueGlassBlock opened this issue May 1, 2023 · 7 comments · Fixed by #1899
Closed

PyPI Trusted Publisher Support #1868

BlueGlassBlock opened this issue May 1, 2023 · 7 comments · Fixed by #1899
Assignees
Labels
⭐ enhancement Improvements for existing features

Comments

@BlueGlassBlock
Copy link
Contributor

PyPI announced the Trusted Publishers feature some days ago. Would be nice to see in pdm publish.

I already saw maturin support this in this PR.

For technical reference, PyPI Docs basically has all the details.

@BlueGlassBlock BlueGlassBlock added the ⭐ enhancement Improvements for existing features label May 1, 2023
@frostming frostming self-assigned this May 8, 2023
frostming added a commit that referenced this issue May 8, 2023
Fixes #1868

Signed-off-by: Frost Ming <me@frostming.com>
@e10v
Copy link

e10v commented May 9, 2023

I've just tried to use this feature in github action and failed.
I'm using pdm-project/setup-pdm@v3 to install the latest version of PDM. I made sure it installed the latest version (2.6.0).
But calling pdm publish (in github action) returns an error: "[PdmUsageError]: Username and password are required".
Are there any command line options or environment variables I should use?

@frostming
Copy link
Collaborator

@e10v Did you see the output: Failed to get PyPI token via GitHub Actions OIDC?

Please follow these steps to set up publishers
https://pdm.fming.dev/latest/usage/publish/#publish-with-trusted-publishers

@e10v
Copy link

e10v commented May 9, 2023

Did you see the output: Failed to get PyPI token via GitHub Actions OIDC?

No I didn't see this message. But I didn't set up "permissions: id-token: write". I will try with next release. Thank you for quick replay and sorry for bothering 🙏

@e10v
Copy link

e10v commented May 9, 2023

@frostming I've just tried again. And now I'm getting the following error:

Traceback (most recent call last):
  File "/home/runner/.local/bin/pdm", line 8, in <module>
    sys.exit(main())
  File "/home/runner/.local/share/pdm/venv/lib/python3.10/site-packages/pdm/core.py", line 268, in main
    return Core().main(args)
  File "/home/runner/.local/share/pdm/venv/lib/python3.10/site-packages/pdm/core.py", line 192, in main
    raise cast(Exception, err).with_traceback(traceback) from None
  File "/home/runner/.local/share/pdm/venv/lib/python3.10/site-packages/pdm/core.py", line 187, in main
    self.handle(project, options)
  File "/home/runner/.local/share/pdm/venv/lib/python3.10/site-packages/pdm/core.py", line 153, in handle
    command.handle(project, options)
  File "/home/runner/.local/share/pdm/venv/lib/python3.10/site-packages/pdm/cli/commands/publish/__init__.py", line 133, in handle
    repository = self.get_repository(project, options)
  File "/home/runner/.local/share/pdm/venv/lib/python3.10/site-packages/pdm/cli/commands/publish/__init__.py", line 120, in get_repository
    return Repository(project, config.url, config.username, config.password, config.ca_certs)
  File "/home/runner/.local/share/pdm/venv/lib/python3.10/site-packages/pdm/cli/commands/publish/repository.py", line 37, in __init__
    username, password = self._ensure_credentials(username, password)
  File "/home/runner/.local/share/pdm/venv/lib/python3.10/site-packages/pdm/cli/commands/publish/repository.py", line 48, in _ensure_credentials
    token = self._get_pypi_token_via_oidc()
  File "/home/runner/.local/share/pdm/venv/lib/python3.10/site-packages/pdm/cli/commands/publish/repository.py", line 63, in _get_pypi_token_via_oidc
    self.ui.echo("Getting PyPI token via GitHub Actions OIDC...")
AttributeError: 'Repository' object has no attribute 'ui'
Error: Process completed with exit code 1.

@BlueGlassBlock
Copy link
Contributor Author

class Repository:
def __init__(
self,
project: Project,
url: str,
username: str | None,
password: str | None,
ca_certs: str | None,
) -> None:
self.url = url
self.session = project.environment._build_session([])
if ca_certs is not None:
self.session.set_ca_certificates(pathlib.Path(ca_certs))
self._credentials_to_save: tuple[str, str, str] | None = None
username, password = self._ensure_credentials(username, password)
self.session.auth = (username, password)
weakref.finalize(self, self.session.close)
self.ui = project.core.ui

self.ui = project.core.ui

should move to be the first in __init__.

frostming added a commit that referenced this issue May 9, 2023
Related #1868

Signed-off-by: Frost Ming <me@frostming.com>
@frostming
Copy link
Collaborator

@e10v Try the head version:

- uses: pdm-project/setup-pdm@v3
  with:
    version: 'head'

@frostming
Copy link
Collaborator

Tested with 2.6.1 and it succeeded.
image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
⭐ enhancement Improvements for existing features
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants