2021年2月25日木曜日

Python の DocstringをGithubで公開

 Python の DocstringをGithubで公開する方法


・Sphinxをインストール

conda install sphinx

・mfapyパッケージ内に

./docs

./htmlというフォルダを作る。

・公開したい(例:mfapy)パッケージ内で

sphinx-apidoc -F -o ./docs ./mfapy

という呪文を唱える ./mfapyのなかにモジュールのPythonファイルが入っている。

・./doc/conf.pyを開き

# import os

# import sys

# sys.path.insert(0, 'C:\\Temp3\\mfapy\\mfapy_latest\\mfapy')

をコメントアウト

extensions = [

    'sphinx.ext.autodoc',

    'sphinx.ext.viewcode',

    'sphinx.ext.todo',

    'sphinx.ext.githubpages',

    'sphinx.ext.napoleon',

]

のように'sphinx.ext.githubpages'、'sphinx.ext.napoleon'拡張を追加

・次なる呪文

     sphinx-build -a ./docs ./html

を唱える。./html内にファイルができる。

・./html/index.htmlを開き


<!DOCTYPE html>


<html lang="en">

  <head>

    <base href="{{site.github.url}}" charset="utf-8"/>

となるよう<base href="{{site.github.url}}" charset="utf-8"/>を追加


・Githubに例えば./mfapy-document/のようなレポジトリを作成する。

・Githubにプッシュ

・できたレポジトリのsetting => GitHub PagesのSourceをmasterにしてSaveする

・うまくいくと

https://fumiomatsuda.github.io/mfapy-document/

のように表示される。


頑張ってDocstringを書こう。