Skip to main content

poetry-stabs-package-sample

パッケージ公開サンプル

poetry config repositories.testpypi https://test.pypi.org/legacy/
poetry publish -r poetry-stabs-package-sample

型を付ける

addは型がついている、つまりちゃんとannotateしていればpyiとかpy.typedとかは必要ない 自分の理解は最初こうだったんですが mypy はこけてしまう!!

❯ mypy awesome-poetry-cache/
awesome-poetry-cache/awesome_poetry_cache/sample.py:1: error: Skipping analyzing "poetry_stabs_package_sample": module is installed, but missing library stubs or py.typed marker  [import-untyped]
awesome-poetry-cache/awesome_poetry_cache/sample.py:1: note: See https://mypy.readthedocs.io/en/stable/running_mypy.html#missing-imports
Found 1 error in 1 file (checked 3 source files)

https://blog.ymyzk.com/2018/09/creating-packages-using-pep-561/

テストを書く

awesome linters

documents

publish package

pypa/gh-action-pypi-publish@release/v1 を使うと公開できる、pypi とは odic で連携してるっぽいので事前に pypi の設定が必要 https://docs.github.com/ja/actions/deployment/security-hardening-your-deployments/configuring-openid-connect-in-pypi

poetry publish をする

poetry に token の設定が必要

普通に公開しようとすると夏期のようなエラーが出た

❯ poetry publish --build -r testpypi
There are 2 files ready for publishing. Build anyway? (yes/no) [no] yes
Building poetry-stabs-package-sample (0.1.0)
  - Building sdist
  - Built poetry_stabs_package_sample-0.1.0.tar.gz
  - Building wheel
  - Built poetry_stabs_package_sample-0.1.0-py3-none-any.whl

Publishing poetry-stabs-package-sample (0.1.0) to testpypi
 - Uploading poetry_stabs_package_sample-0.1.0-py3-none-any.whl FAILED

HTTP Error 403: Invalid or non-existent authentication information. See https://test.pypi.org/help/#invalid-auth for more information. | b'<html>\n <head>\n  <title>403 Invalid or non-existent authentication information. See https://test.pypi.org/help/#invalid-auth for more information.\n \n <body>\n  <h1>403 Invalid or non-existent authentication information. See https://test.pypi.org/help/#invalid-auth for more information.\n  Access was denied to this resource.<br/><br/>\nInvalid or non-existent authentication information. See https://test.pypi.org/help/#invalid-auth for more information.\n\n\n \n'

poetry config pypi-token.testpypi "pypi-xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"

通った

❯ poetry publish --build -r testpypi
There are 2 files ready for publishing. Build anyway? (yes/no) [no] yes
Building poetry-stabs-package-sample (0.1.0)
  - Building sdist
  - Built poetry_stabs_package_sample-0.1.0.tar.gz
  - Building wheel
  - Built poetry_stabs_package_sample-0.1.0-py3-none-any.whl

Publishing poetry-stabs-package-sample (0.1.0) to testpypi
 - Uploading poetry_stabs_package_sample-0.1.0-py3-none-any.whl 100%
 - Uploading poetry_stabs_package_sample-0.1.0.tar.gz 100%

バージョンを上げる

poetry version patch

上でバージョンを上げても github 上の ci release ではバージョンは上がらなかったので pypi 上のバージョンは git tags のバージョンに依存してそう。pyproject.toml や自動で再デプロイするとバージョンが上がるわけではなさそう

そんなことはなくて普通に pyproject.toml に依存してる。ただしpoetry buildを忘れないこと

pypi にいれる release env みたいなやつ

入れないほうが無難。

test.pypi は?

めっちゃ flakey。成功するまでリトライするとかするといいかもしれない。ghaction には現在再試行するオプションはなさそうだったので 3 回同じ文を書く脳筋実装をした

    - name: publish testpypi
      id: publish
      uses: pypa/gh-action-pypi-publish@release/v1
      with:
        repository-url: https://test.pypi.org/legacy/
      continue-on-error: true
    - name: retry publish testpypi
      if: steps.publish.outcome == 'failure'
      uses: pypa/gh-action-pypi-publish@release/v1
      with:
        repository-url: https://test.pypi.org/legacy/
      continue-on-error: true
    - name: retry publish testpypi (2nd attempt)
      if: steps.publish.outcome == 'failure'
      uses: pypa/gh-action-pypi-publish@release/v1
      with:
        repository-url: https://test.pypi.org/legacy/
      continue-on-error: true

badge

https://zenn.dev/atu4403/articles/howto-poetry-dev#badge%E3%81%AE%E5%8F%96%E5%BE%97 fury.io で取得できる。今は test.pypi なのでできないけど

その他 tips

content: write を付けないと gh actions 上で該当のリポジトリへ push ができない

permissions:
  contents: write

init.py で flake8 が import not used エラーを出すやつ

https://stackoverflow.com/questions/31079047/python-pep8-class-in-init-imported-but-not-used allを使える

ref

https://cylomw.hatenablog.com/entry/2021/01/19/174847 https://blog.ymyzk.com/2018/09/creating-packages-using-pep-561/

Release files for poetry-stabs-package-sample 0.1.8

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for poetry-stabs-package-sample 0.1.8
File Size Uploaded
poetry_stabs_package_sample-0.1.8.tar.gz 5.0 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for poetry-stabs-package-sample 0.1.8
File Interpreter ABI Platform
poetry_stabs_package_sample-0.1.8-py3-none-any.whl Python 3 none any Details

Total release size: 12.1 kB

Release files / poetry_stabs_package_sample-0.1.8.tar.gz

Download URL poetry_stabs_package_sample-0.1.8.tar.gz
Size 5.0 kB
Tags Source
SHA-256 checksum
How to use checksums
579ef67ba24e88ad704c5990a8cb1201b50c27e064c97f31089d9f574932d972
BLAKE2b-256 checksum
How to use checksums
fe8c95d34b686c917573aaea517cee0d9b694915f8099cc88791010363e9f3c9
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.8.3 CPython/3.12.3 Linux/5.15.153.1-microsoft-standard-WSL2

Release files / poetry_stabs_package_sample-0.1.8-py3-none-any.whl

Download URL poetry_stabs_package_sample-0.1.8-py3-none-any.whl
Size 7.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
f9942f5a95380417c1c45c814b22fa083ecc8593037dfeeb809528476edd8c54
BLAKE2b-256 checksum
How to use checksums
06fa0b393502292bce85cc49f1783f69d4dfdbb1aaaa850ad8c95abaa38fdffd
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.8.3 CPython/3.12.3 Linux/5.15.153.1-microsoft-standard-WSL2

Release history Release notifications | RSS feed

This release

0.1.8 This release

2 release files

0.1.7

2 release files

0.1.6

2 release files

0.1.3

2 release files

0.1.1

2 release files

0.1.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page