Open ftnext opened 4 years ago
Pythonパッケージ開発一歩目までのクイックツアー テスト、ドキュメント、配布、Ci/CDをカバー
https://africa.pycon.org/speakers/rising-odegua#talk
Rising Odegua
2020/08/04
四則演算をするライブラリmathistを作成 作る前にpypiでname collisionがないか確認した GitHubリポジトリを作りローカル開発環境にcloneする
mathist
リポジトリの中に、ライブラリ名のディレクトリmathistを作る mathist/math.py mathist/__init__.pyも作ってパッケージにする
mathist/__init__.py
mathist/testディレクトリも作成。cd mathist; pytest test/*でテストする pip install pytest
cd mathist; pytest test/*
pip install pytest
mathist/test/test_math.py(math.pyのテスト) testディレクトリに__init__.pyを作りパッケージにする(インポートできる)
__init__.py
import pytest from mathist import math # テスト対象のモジュール def test_add(): expected = 20 output = math.add(10, 10) assert expected == output
Adds two numbers together Args: a: int,float first number to add b: int,float second number to add Returns: int/float
VSCodeやColabでどんな関数かが見られる
pip install setuptools wheel
python setup.py sdist bdist_wheel
ソースコードとバイナリ(wheel)の配布 →build/ディレクトリとdist/ディレクトリができる(mathist.egg-info もできる) 中にバージョン0.1のtar.gz このtar.gzのパスを指定してpip installできる! 動作確認に使ったapp.py
from mathist import math print(math.add(20, 20))
pip install twine twine upload --repository testpypi dist/* sdistもbdistもアップロード →https://test.pypi.org/project/mathist/
pip install twine
twine upload --repository testpypi dist/*
Publish Python Packageを使う https://docs.github.com/en/actions/language-and-framework-guides/using-python-with-github-actions 例:https://github.com/actions/starter-workflows/blob/master/ci/python-publish.yml
Publish Python Package
[以下はオプション]
環境の扱いに荒削りなところを残しつつも、1時間で簡単なパッケージを例に、 テスト・ドキュメント・パッケージ化・CI/CDを説明しきったのは見事。 OSS一般では見かけるが、自分のリポジトリではできていない点をどうやればいいのかがわかった(バッジなど)
https://github.com/<OWNER>/<REPOSITORY>/workflows/<WORKFLOW_NAME>/badge.svg
pytest test/*
long_description
assert 20/10 == 2
virtualenv mathist-env
from mathist import math
from mathist.math import add,...
一言でいうと
Pythonパッケージ開発一歩目までのクイックツアー テスト、ドキュメント、配布、Ci/CDをカバー
発表資料リンク
https://africa.pycon.org/speakers/rising-odegua#talk
発表者/所属
Rising Odegua
発表日付
2020/08/04
概要
四則演算をするライブラリ
mathist
を作成 作る前にpypiでname collisionがないか確認した GitHubリポジトリを作りローカル開発環境にcloneするリポジトリの中に、ライブラリ名のディレクトリ
mathist
を作る mathist/math.pymathist/__init__.py
も作ってパッケージにするテスト
mathist/testディレクトリも作成。
cd mathist; pytest test/*
でテストするpip install pytest
mathist/test/test_math.py(math.pyのテスト) testディレクトリに
__init__.py
を作りパッケージにする(インポートできる)実装中のdocstring
VSCodeやColabでどんな関数かが見られる
setup.pyを書いていく
pip install setuptools wheel
python setup.py sdist bdist_wheel
ソースコードとバイナリ(wheel)の配布 →build/ディレクトリとdist/ディレクトリができる(mathist.egg-info もできる) 中にバージョン0.1のtar.gz このtar.gzのパスを指定してpip installできる! 動作確認に使ったapp.py
twineでPyPIにアップロードする(TestPyPIの例)
pip install twine
twine upload --repository testpypi dist/*
sdistもbdistもアップロード →https://test.pypi.org/project/mathist/GitHub ActionsでCi/CD
Publish Python Package
を使う https://docs.github.com/en/actions/language-and-framework-guides/using-python-with-github-actions 例:https://github.com/actions/starter-workflows/blob/master/ci/python-publish.yml[以下はオプション]
新規性・差分
環境の扱いに荒削りなところを残しつつも、1時間で簡単なパッケージを例に、 テスト・ドキュメント・パッケージ化・CI/CDを説明しきったのは見事。 OSS一般では見かけるが、自分のリポジトリではできていない点をどうやればいいのかがわかった(バッジなど)
トークで知って試したいこと
https://github.com/<OWNER>/<REPOSITORY>/workflows/<WORKFLOW_NAME>/badge.svg
調査したい事項
pytest test/*
はpytestの命名規則に従えばもっと短いコマンドになる?long_description
にする場合、markdownが解釈されるにはどうするのか?assert 20/10 == 2
がTrueになる?感想
virtualenv mathist-env
(condaも入っていそうな感じ)mathist/__init__.py
にfrom mathist import math
from mathist.math import add,...
としたい)