Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Publish to pypi#59

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
ThomasWaldmann merged 2 commits intomicropython:masterfromwnienhaus:publish-to-pypi
Nov 21, 2021

Conversation

@wnienhaus
Copy link
Collaborator

@wnienhauswnienhaus commentedNov 21, 2021
edited by ThomasWaldmann
Loading

This PR adds a GitHub Actions workflow for publishing our upip package to PyPi. Itresolves#58.

Overview

I was inspired to create this by this article:https://simonwillison.net/2021/Nov/4/publish-open-source-python-library/, even though I now saw, that GitHub offers a workflow template for this too, using an action from its Actions Marketplace.

Instead of using a hardcoded version number during the build, setup.py now uses setuptools-scm to derive a useful/relevant version from git metadata (tags/commits).

The below is documentation mainly for once the PR has been merged, and for how to then test it and later release 1.0.0.

Setup

The workflow in this PR will require setting up 2 repository secrets (Settings -> Secrets -> Actions secrets -> New repository secret), namelyTEST_PYPI_API_TOKEN andPYPI_API_TOKEN (for TestPyPi and real PyPI respectively). These tokens can be generated in TestPyPI and real PyPI as follows:

  • Log in
  • Going to Account Settings -> API tokens
  • Selecting "Add API token"
  • Entering a token name, e.g. "publish-py-esp32-ulp"
  • Selecting the right project
  • And selecting "Add token"
  • Copy the resulting token, which should be a long string starting withpypi-

Once you have the tokens for both TestPyPI and real PyPI, add them as repository secret to the Github repo.

Testing

To test this PR, it sadly needs to be merged to master (or a "dummy" publish.yml must be committed to master), otherwise Github does make this workflow available in the user interface. However, merging to master should be safe, as this workflow is only triggered when creating a release (which is a deliberate step) or by manually triggering the workflow.

Once merged to master, it can be tested by either triggering the workflow manually (a good first step), or by creating a new Release with Github.

  • NOTE: Since PyPI does not allow reusing version numbers, it might be best to try the first release with a version number lower than 1.0.0, e.g. 0.0.1 and then deleting that version again once 1.0.0 is released (or just before).
  • It might also be good to not configure the livePYPI_API_TOKEN secret initially, to prevent accidentally publishing test releases to the live PyPI.
  • When manually triggering the workflow, and thus no tag is (yet) added to the repo, the version number of the package will be derived by setuptools-scm as0.1-devX whereX is the number of commits since the last tag (in our case, since the beginning of history, since we have no tags yet)

Test-before-publish

The article that inspired me to create this publishing workflow suggested to run the automated tests again as part of the publishing workflow to ensure no untested code is published. I like that idea.

However, I could not find a good way to do that without duplicating the test steps from the existing workflow into the new publish workflow. I tried many ways (seethe ideas I tried) and eventually decided to leave this out. Github Actions sadly does not provide good enough ways to reuse workflows or to make workflows dependent on each other.

I ended up deciding that simple is better and that publishing is a deliberate act on our part anyway (creating a Release with Github) so we can choose to release only when we know all tests pass.

Happy to get feedback on this.

Disable appending local part to version because we'retesting uploads to TestPyPI, and pypi does not supportthe local part in version numbers (see:https://github.com/pypa/setuptools_scm/#version-number-construction)
This workflow is triggered when publishing a new releaseusing the GitHub Releases functionality. It can also betriggered manually for testing.The workflow will always publish to Test PyPI, but willonly publish to the real PyPI, when releasing a newversion using the GitHub Releases functionality.The version for the package is generated by setuptools_scm,based on the git tags/commits. For all non-tagged commits,a "dev version" is generated with the format "0.1.2-dev3",where 0.1.2 is the latest tag plus one more in the last partof the version number (i.e. given the last tag was 0.1.1,0.1.2 will be used for the dev version) and the 3 in "-dev3"comes from the number of commits since the last tag.(This all is standard setuptools_scm behaviour.)
@ThomasWaldmann
Copy link
Collaborator

Looks good, thanks for working on this. I set up the TEST secret (but no the production one) already, so let's try this...

@ThomasWaldmannThomasWaldmann merged commitfd10ea7 intomicropython:masterNov 21, 2021
@ThomasWaldmann
Copy link
Collaborator

ThomasWaldmann commentedNov 21, 2021
edited
Loading

@wnienhauswnienhaus deleted the publish-to-pypi branchNovember 28, 2021 10:37
@ThomasWaldmann
Copy link
Collaborator

ThomasWaldmann commentedDec 3, 2021
edited
Loading

Hmm, it seems that I am not owner of the pypi.org project yet, so I can't generate the pypi api token.

Ehrm, that doesn't exist yet. And one can't create (specific) tokens for non-existing projects.

Update: using a temporary scary global token worked to create the pypi.org project, now replaced that again with a project-specific token.

wnienhaus reacted with thumbs up emoji

Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment

Reviewers

No reviews

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Automate publish to PyPI

2 participants

@wnienhaus@ThomasWaldmann

[8]ページ先頭

©2009-2025 Movatter.jp