PPP3: パッケージ作成(続き)
03-03-07 README.rst: 開発環境セットアップ手順
README.rstにセットアップ手順を記載
rstはreStructuredTextの略
Markdownじゃないのは何かのお約束なのか単なるローカルルールなのか
見た目はMarkdownのほうが好きかなあ
見出しが目立つのはいいところかもしれない
やれとは書いてないけどadd
してcommit
してpush
.rstでもGitHubはちゃんと表示するんだ
vscodeがrst用のエクステンション入れてね♡と言ってきたのでいれておく
そのまんまreStructuredTextっていう名前で一番上に出てきたやつ
シンタックスハイライトとかlintとかpreviewとかしてくれる
03-03-08 依存パッケージを変更する
依存パッケージを変更したらpip install -e .
をやりなおす
python3 -m venv --clear venv
で仮想環境をリセット
03-03-09 requirements.txtで開発バージョンを固定する
Webアプリをデプロイするだけ、などsetup.pyが不要な場合は
requirements.txtを使うのが効率的
pip freeze > requirements.txt
で作って
pip install -r reqirements.txt
でインストール
03-03-10 python setup.py bdist_wheel: wheel配布パッケージを作る
python setup.py bdist_wheel
でwheelパッケージを作成
インストールはpip install xxx.whl
ソースパッケージに比べて高速にインストールされる
あんまりなじみのない拡張子だけど
03-03-11 PyPIにアップロードして公開する
PyPIは誰でもPythonパッケージを登録したりダウンロードしたりできるPythonの公式サイトです。作成したパッケージが公開してもよいものであれば、PyPIに登録しましょう。
そういう位置づけなんだ
まあ審査とかするのも大変だから
twine PyPIにパッケージを登録するためのツール
pip install twine
でインストール
https://pypi.org でアカウント作成・・・しとくかなせっかくだから
ホンモノを使う気はしないので、https://test.pypi.org にも登録してそっちで
norilogでいっぱい登録されてるかなと思ったら意外とそうでもない
全然違う名前で登録されてるのかな
それともやってるひとが少ないのか
終わったら消してるのか
setup.pyを修正
けっこう長くなっている
long_descriptionはreSTで書く
つまりPythonの世界ではreSTがおすすめなのか
あらかじめREADME.rstが正しいかどうか確かめておく
といってもvscodeのエクステンションでチェックされてるけど一応
$ python setup.py check
Traceback (most recent call last):
File "setup.py", line 17, in <module>
long_description=read_file("README.rst"),
File "setup.py", line 9, in read_file
return open(filepath).read()
UnicodeDecodeError: 'cp932' codec can't decode byte 0x84 in position 58: illegal multibyte sequence
あれ
エンコードを指定してやらないといけないの?
どうも文字コード関連はよくわかってないんだよな
とりあえずこうした
if os.path.exists(filepath):
return open(filepath, encoding="utf-8").read()
どれ
(winenv)
$ python setup.py check
C:\Python\Python37\lib\distutils\dist.py:274: UserWarning: Unknown distribution option: 'classfier'
warnings.warn(msg)
running check
通ったみたい
しかも間違ってた
-r -s
でREADME.rstのチェックか
$ python setup.py check -r -s
running check
warning: Check: This command has been deprecated. Use `twine check` instead: https://packaging.python.org/guides/making-a-pypi-friendly-readme#validating-restructuredtext-markup
The project's long description is valid RST.
-r -s
はdeprecateらしいけどREADME.rstはOK
twine check
もやってみよう
$ twine check dist
InvalidDistribution: Unknown distribution format: 'dist'
Checking distribution dist:
なにも言わないのはOKってことだよな
ではアップロード
testPyPIに
$ twine upload --repository-url https://test.pypi.org/legacy/ dist/*
Enter your username: kb84tkhr
Enter your password:
Uploading distributions to https://test.pypi.org/legacy/
Uploading norilog-1.0.0-py3-none-any.whl
NOTE: Try --verbose to see response content.
HTTPError: 403 Client Error: The user 'kb84tkhr' isn't allowed to upload to project 'norilog'. See https://test.pypi.org/help/#project-name for more information. for url: https://test.pypi.org/legacy/
おっとっと
名前変えないとな
name="norilog.kb84tkhr",
これでいいの?
パッケージは作り直したほうがいいのかな
$ twine upload --repository-url https://test.pypi.org/legacy/ dist/*
Enter your username: kb84tkhr
Enter your password:
Uploading distributions to https://test.pypi.org/legacy/
Uploading norilog.kb84tkhr-1.0.0-py3-none-any.whl