setup.pyの操作まとめ

はじめに

setup.pyはつくったモジュールの情報を書いておくファイル。
モジュールの名前やバージョン、作者、ライセンスなどなど。
たまにしか使わないし忘れるのでメモ。

操作いろいろ

モジュールのインストール

python setup.py install

long_descriptionをhtmlにする

long_descriptionとは、PyPIのページで表示されるドキュメント。reSTで書くことが出来る。

python setup.py --long-description | rst2html.py > output.html

readme.rstをじかにrst2html.pyで変換する方が楽。

rst2html.py readme.rst > output.html

pandocを使う方法もある。

pandoc README.rst -s -o output.html

PyPIで配布できる形式に変換

それぞれの特徴は以下の記事で。
Pythonのsource distributionとeggとwheel - 脱力系日記

sdist
python setup.py sdist
egg
python setup.py bdist_egg
win向けインストーラ
python setup.py bdist_wininst
wheel
python setup.py bdist_wheel

文法チェック

python setup.py check

PyPIに登録

PyPIに上げるためにモジュールを登録する。PyPIに上げることでpipで自作モジュールをいれられるようになる。

python setup.py register

PyPIにupload

つくったモジュールをPyPIに上げる。

python setup.py sdist bdist_wheel upload

長いのでshellのailiasに登録しとくと便利。

alias pypi="python setup.py sdist bdist_wheel upload"