ftnext / PyConTalkSummary

PyConで聞いたトークのサマリーをIssueに蓄積(arXivTimesリスペクト)
0 stars 0 forks source link

[PyConAfrica2020] Building your First Open Source Python Library #27

Open ftnext opened 4 years ago

ftnext commented 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/math.py mathist/__init__.pyも作ってパッケージにする

テスト

mathist/testディレクトリも作成。cd mathist; pytest test/*でテストする pip install pytest

mathist/test/test_math.py(math.pyのテスト) testディレクトリに__init__.pyを作りパッケージにする(インポートできる)

import pytest
from mathist import math  # テスト対象のモジュール

def test_add():
    expected = 20
    output = math.add(10, 10)
    assert expected == output

実装中のdocstring

Adds two numbers together
Args:
    a: int,float first number to add
    b: int,float second number to add
Returns:
    int/float

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

from mathist import math

print(math.add(20, 20))

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一般では見かけるが、自分のリポジトリではできていない点をどうやればいいのかがわかった(バッジなど)

トークで知って試したいこと

調査したい事項

感想