Dashにchainerのドキュメントを登録する

魚について調べる時、(Wikipediaもいいんですが)FishBase : A Global Information System on Fishesとかは結構分量も凄くて、英語中心ですがときどき役に立ちます。

さて、Macを3年ぐらい使ってきてて恥ずかしながらわりと最近までドキュメントのインクリメンタルサーチができるDashを知らなかったんですけども、ちょっと前から使うようになりました。仕事や趣味でChainerを使うんですが、ChainerのドキュメントはDashで提供されてないので、自分でドキュメントをDash用に変換する必要があります。

とは言えChainerはSphinxでドキュメントが書かれているので、doc2dashというpipを使えば一発でできます。

なのですごい簡単なんですが、環境を新しくする度にやり方を調べてやってる気がするので、メモ。
別にchainer限定ではなくて他の何にでも当てはまる一般的な話なんですが、あえてchainer specificな話題にしてみました。

# 準備。doc2dashを入れる。
% pip install doc2dash

# Cloneしてくる
% git clone https://github.com/pfnet/chainer.git --branch v2.0.0
% cd chainer/docs

# Optional: アイコンに使う画像をダウンロードしてくる。ここではTwitterから。
% wget https://pbs.twimg.com/profile_images/606654945438203905/D7LygzpN_400x400.png -O chainer_logo.png

# ドキュメントをビルドし、dash形式に変換
% make html
% doc2dash build/html -n chainer2 -i chainer_logo.png
# % doc2dash build/html -n chainer2   #アイコンが不要な場合

これを実行すると、chainer2.docsetというディレクトリが生成されます。Sphinx等はもちろん入っている必要があるので、怒られた場合は指示に従って入れてください。
Dashをインストール済みのMacでFinderにてこのディレクトリをダブルクリックすると、検索できるドキュメントとして追加されます。

ぼくの場合手元のMacだと、2017/7/3現在でのmasterのときsphinxのビルド(上記のmake html)がこんなかんじで失敗することがあったので、Linux環境でmakeしました。また、いきなりmake htmlするとエラーで死ぬんですがmake dirhtmlしてからmake htmlすると通ることも度々ありました。ちょっと謎。

% make dirhtml
...
...
reading sources... [ 76%] reference/generated/chainer.links.StatelessLSTM
reading sources... [ 76%] reference/generated/chainer.links.VGG16Layers
reading sources... [ 76%] reference/generated/chainer.links.caffe.CaffeFunction
reading sources... [ 77%] reference/generated/chainer.links.model.vision.googlenet.prepare
reading sources... [ 77%] reference/generated/chainer.links.model.vision.resnet.ResNetLayers
reading sources... [ 77%] reference/generated/chainer.links.model.vision.resnet.prepare
reading sources... [ 77%] reference/generated/chainer.links.model.vision.vgg.prepare
reading sources... [ 78%] reference/generated/chainer.optimizers.AdaDelta
/Users/hoge/Work/chainer/chainer/docs/source/reference/check.rst:30: WARNING: failed to import chainer.gradient_check.check_backward
/Users/hoge/Work/chainer/chainer/docs/source/reference/check.rst:30: WARNING: failed to import chainer.gradient_check.numerical_grad
/Users/hoge/Work/chainer/chainer/docs/source/reference/check.rst:30: WARNING: toctree references unknown document 'reference/generated/chainer.gradient_check.check_backward'
/Users/hoge/Work/chainer/chainer/docs/source/reference/check.rst:30: WARNING: toctree references unknown document 'reference/generated/chainer.gradient_check.numerical_grad'
/Users/hoge/Work/chainer/chainer/docs/source/reference/check.rst:43: WARNING: failed to import chainer.testing.assert_allclose
/Users/hoge/Work/chainer/chainer/docs/source/reference/check.rst:43: WARNING: toctree references unknown document 'reference/generated/chainer.testing.assert_allclose'
/Users/hoge/Work/chainer/chainer/docs/source/reference/check.rst:53: WARNING: failed to import chainer.testing.unary_math_function_unittest
/Users/hoge/Work/chainer/chainer/docs/source/reference/check.rst:53: WARNING: toctree references unknown document 'reference/generated/chainer.testing.unary_math_function_unittest'
/Users/hoge/.pyenv/versions/3.6.1/lib/python3.6/site-packages/chainer/link.py:docstring of chainer.Chain.init_scope:19: WARNING: Unexpected indentation.
/Users/hoge/.pyenv/versions/3.6.1/lib/python3.6/site-packages/chainer/link.py:docstring of chainer.ChainList.init_scope:19: WARNING: Unexpected indentation.
/Users/hoge/.pyenv/versions/3.6.1/lib/python3.6/site-packages/chainer/link.py:docstring of chainer.Link.init_scope:19: WARNING: Unexpected indentation.
/Users/hoge/Work/chainer/chainer/docs/source/reference/core/optimizer.rst:4: WARNING: failed to import chainer.Hyperparameter
/Users/hoge/Work/chainer/chainer/docs/source/reference/core/optimizer.rst:4: WARNING: toctree references unknown document 'reference/core/generated/chainer.Hyperparameter'
WARNING: /Users/hoge/Work/chainer/chainer/docs/source/reference/datasets.rst:57: (WARNING/2) autodoc: failed to import class 'ConcatenatedDataset' from module 'chainer.datasets'; the following exception was raised:
Traceback (most recent call last):
  File "/Users/hoge/.pyenv/versions/3.6.1/lib/python3.6/site-packages/sphinx/util/inspect.py", line 169, in safe_getattr
    return getattr(obj, name, *defargs)
AttributeError: module 'chainer.datasets' has no attribute 'ConcatenatedDataset'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
  File "/Users/hoge/.pyenv/versions/3.6.1/lib/python3.6/site-packages/sphinx/ext/autodoc.py", line 664, in import_object
    obj = self.get_attr(obj, part)
  File "/Users/hoge/.pyenv/versions/3.6.1/lib/python3.6/site-packages/sphinx/ext/autodoc.py", line 554, in get_attr
    return safe_getattr(obj, name, *defargs)
  File "/Users/hoge/.pyenv/versions/3.6.1/lib/python3.6/site-packages/sphinx/util/inspect.py", line 185, in safe_getattr
    raise AttributeError(name)
AttributeError: ConcatenatedDataset
/Users/hoge/Work/chainer/chainer/docs/source/reference/functions.rst:30: WARNING: failed to import chainer.functions.tree_lstm
/Users/hoge/Work/chainer/chainer/docs/source/reference/functions.rst:30: WARNING: toctree references unknown document 'reference/generated/chainer.functions.tree_lstm'
/Users/hoge/Work/chainer/chainer/docs/source/reference/functions.rst:216: WARNING: failed to import chainer.functions.layer_normalization
/Users/hoge/Work/chainer/chainer/docs/source/reference/functions.rst:216: WARNING: toctree references unknown document 'reference/generated/chainer.functions.layer_normalization'
/Users/hoge/.pyenv/versions/3.6.1/lib/python3.6/site-packages/chainer/link.py:docstring of chainer.links.BatchNormalization.init_scope:19: WARNING: Unexpected indentation.
/Users/hoge/.pyenv/versions/3.6.1/lib/python3.6/site-packages/chainer/link.py:docstring of chainer.links.Bias.init_scope:19: WARNING: Unexpected indentation.
/Users/hoge/.pyenv/versions/3.6.1/lib/python3.6/site-packages/chainer/link.py:docstring of chainer.links.Bilinear.init_scope:19: WARNING: Unexpected indentation.
/Users/hoge/.pyenv/versions/3.6.1/lib/python3.6/site-packages/chainer/link.py:docstring of chainer.links.BinaryHierarchicalSoftmax.init_scope:19: WARNING: Unexpected indentation.
/Users/hoge/.pyenv/versions/3.6.1/lib/python3.6/site-packages/chainer/link.py:docstring of chainer.links.BlackOut.init_scope:19: WARNING: Unexpected indentation.
/Users/hoge/.pyenv/versions/3.6.1/lib/python3.6/site-packages/chainer/link.py:docstring of chainer.links.CRF1d.init_scope:19: WARNING: Unexpected indentation.
/Users/hoge/.pyenv/versions/3.6.1/lib/python3.6/site-packages/chainer/link.py:docstring of chainer.links.Classifier.init_scope:19: WARNING: Unexpected indentation.
/Users/hoge/.pyenv/versions/3.6.1/lib/python3.6/site-packages/chainer/link.py:docstring of chainer.links.Convolution2D.init_scope:19: WARNING: Unexpected indentation.
/Users/hoge/.pyenv/versions/3.6.1/lib/python3.6/site-packages/chainer/link.py:docstring of chainer.links.ConvolutionND.init_scope:19: WARNING: Unexpected indentation.
/Users/hoge/.pyenv/versions/3.6.1/lib/python3.6/site-packages/chainer/link.py:docstring of chainer.links.Deconvolution2D.init_scope:19: WARNING: Unexpected indentation.
/Users/hoge/.pyenv/versions/3.6.1/lib/python3.6/site-packages/chainer/link.py:docstring of chainer.links.DeconvolutionND.init_scope:19: WARNING: Unexpected indentation.
/Users/hoge/.pyenv/versions/3.6.1/lib/python3.6/site-packages/chainer/link.py:docstring of chainer.links.DepthwiseConvolution2D.init_scope:19: WARNING: Unexpected indentation.
/Users/hoge/.pyenv/versions/3.6.1/lib/python3.6/site-packages/chainer/link.py:docstring of chainer.links.DilatedConvolution2D.init_scope:19: WARNING: Unexpected indentation.
/Users/hoge/.pyenv/versions/3.6.1/lib/python3.6/site-packages/chainer/link.py:docstring of chainer.links.EmbedID.init_scope:19: WARNING: Unexpected indentation.
/Users/hoge/.pyenv/versions/3.6.1/lib/python3.6/site-packages/chainer/link.py:docstring of chainer.links.GRU.init_scope:19: WARNING: Unexpected indentation.
/Users/hoge/.pyenv/versions/3.6.1/lib/python3.6/site-packages/chainer/link.py:docstring of chainer.links.GoogLeNet.init_scope:19: WARNING: Unexpected indentation.
/Users/hoge/.pyenv/versions/3.6.1/lib/python3.6/site-packages/chainer/link.py:docstring of chainer.links.Highway.init_scope:19: WARNING: Unexpected indentation.
/Users/hoge/.pyenv/versions/3.6.1/lib/python3.6/site-packages/chainer/link.py:docstring of chainer.links.Inception.init_scope:19: WARNING: Unexpected indentation.
/Users/hoge/.pyenv/versions/3.6.1/lib/python3.6/site-packages/chainer/link.py:docstring of chainer.links.InceptionBN.init_scope:19: WARNING: Unexpected indentation.
/Users/hoge/.pyenv/versions/3.6.1/lib/python3.6/site-packages/chainer/link.py:docstring of chainer.links.LSTM.init_scope:19: WARNING: Unexpected indentation.
/Users/hoge/.pyenv/versions/3.6.1/lib/python3.6/site-packages/chainer/link.py:docstring of chainer.links.LayerNormalization.init_scope:19: WARNING: Unexpected indentation.
/Users/hoge/.pyenv/versions/3.6.1/lib/python3.6/site-packages/chainer/link.py:docstring of chainer.links.Linear.init_scope:19: WARNING: Unexpected indentation.
/Users/hoge/.pyenv/versions/3.6.1/lib/python3.6/site-packages/chainer/link.py:docstring of chainer.links.MLPConvolution2D.init_scope:19: WARNING: Unexpected indentation.
/Users/hoge/.pyenv/versions/3.6.1/lib/python3.6/site-packages/chainer/link.py:docstring of chainer.links.Maxout.init_scope:19: WARNING: Unexpected indentation.
/Users/hoge/.pyenv/versions/3.6.1/lib/python3.6/site-packages/chainer/link.py:docstring of chainer.links.NStepBiGRU.init_scope:19: WARNING: Unexpected indentation.
/Users/hoge/.pyenv/versions/3.6.1/lib/python3.6/site-packages/chainer/link.py:docstring of chainer.links.NStepBiLSTM.init_scope:19: WARNING: Unexpected indentation.
/Users/hoge/.pyenv/versions/3.6.1/lib/python3.6/site-packages/chainer/link.py:docstring of chainer.links.NStepBiRNNReLU.init_scope:19: WARNING: Unexpected indentation.
/Users/hoge/.pyenv/versions/3.6.1/lib/python3.6/site-packages/chainer/link.py:docstring of chainer.links.NStepBiRNNTanh.init_scope:19: WARNING: Unexpected indentation.
/Users/hoge/.pyenv/versions/3.6.1/lib/python3.6/site-packages/chainer/link.py:docstring of chainer.links.NStepGRU.init_scope:19: WARNING: Unexpected indentation.
/Users/hoge/.pyenv/versions/3.6.1/lib/python3.6/site-packages/chainer/link.py:docstring of chainer.links.NStepLSTM.init_scope:19: WARNING: Unexpected indentation.
/Users/hoge/.pyenv/versions/3.6.1/lib/python3.6/site-packages/chainer/link.py:docstring of chainer.links.NStepRNNReLU.init_scope:19: WARNING: Unexpected indentation.
/Users/hoge/.pyenv/versions/3.6.1/lib/python3.6/site-packages/chainer/link.py:docstring of chainer.links.NStepRNNTanh.init_scope:19: WARNING: Unexpected indentation.
/Users/hoge/.pyenv/versions/3.6.1/lib/python3.6/site-packages/chainer/link.py:docstring of chainer.links.NegativeSampling.init_scope:19: WARNING: Unexpected indentation.
/Users/hoge/.pyenv/versions/3.6.1/lib/python3.6/site-packages/chainer/link.py:docstring of chainer.links.PReLU.init_scope:19: WARNING: Unexpected indentation.
/Users/hoge/.pyenv/versions/3.6.1/lib/python3.6/site-packages/chainer/link.py:docstring of chainer.links.ResNet101Layers.init_scope:19: WARNING: Unexpected indentation.
/Users/hoge/.pyenv/versions/3.6.1/lib/python3.6/site-packages/chainer/link.py:docstring of chainer.links.ResNet152Layers.init_scope:19: WARNING: Unexpected indentation.
/Users/hoge/.pyenv/versions/3.6.1/lib/python3.6/site-packages/chainer/link.py:docstring of chainer.links.ResNet50Layers.init_scope:19: WARNING: Unexpected indentation.
/Users/hoge/.pyenv/versions/3.6.1/lib/python3.6/site-packages/chainer/link.py:docstring of chainer.links.Scale.init_scope:19: WARNING: Unexpected indentation.
/Users/hoge/.pyenv/versions/3.6.1/lib/python3.6/site-packages/chainer/link.py:docstring of chainer.links.SimplifiedDropconnect.init_scope:19: WARNING: Unexpected indentation.
/Users/hoge/.pyenv/versions/3.6.1/lib/python3.6/site-packages/chainer/link.py:docstring of chainer.links.StatefulGRU.init_scope:19: WARNING: Unexpected indentation.
/Users/hoge/.pyenv/versions/3.6.1/lib/python3.6/site-packages/chainer/link.py:docstring of chainer.links.StatefulPeepholeLSTM.init_scope:19: WARNING: Unexpected indentation.
/Users/hoge/.pyenv/versions/3.6.1/lib/python3.6/site-packages/chainer/link.py:docstring of chainer.links.StatelessLSTM.init_scope:19: WARNING: Unexpected indentation.
/Users/hoge/.pyenv/versions/3.6.1/lib/python3.6/site-packages/chainer/link.py:docstring of chainer.links.VGG16Layers.init_scope:19: WARNING: Unexpected indentation.
/Users/hoge/.pyenv/versions/3.6.1/lib/python3.6/site-packages/chainer/link.py:docstring of chainer.links.caffe.CaffeFunction.init_scope:19: WARNING: Unexpected indentation.
/Users/hoge/.pyenv/versions/3.6.1/lib/python3.6/site-packages/chainer/link.py:docstring of chainer.links.model.vision.resnet.ResNetLayers.init_scope:19: WARNING: Unexpected indentation.
Exception occurred:
  File "/Users/hoge/.pyenv/versions/3.6.1/lib/python3.6/site-packages/chainer/optimizer.py", line 598, in __get__
    return getattr(obj.hyperparam, self._attr_name)
AttributeError: 'NoneType' object has no attribute 'hyperparam'
The full traceback has been saved in /var/folders/y1/tp8l6j7n67bgbz8tpm0_05b40000gn/T/sphinx-err-6hlmrj53.log, if you want to report the issue to the developers.
Please also report this if it was a user error, so that a better error message can be provided next time.
A bug report can be filed in the tracker at <https://github.com/sphinx-doc/sphinx/issues>. Thanks!
make: *** [dirhtml] Error 1

また、DashのWindows/Linux版であるZealを使っている場合、上記の手順でビルドしてできたchainer2.docsetディレクトリを、Zealのdocsetsディレクトリに入れることでZealに見えるようになります。

% mv chainer2.docset ~/.local/share/Zeal/Zeal/docsets/

(docsetsディレクトリの場所は環境によって異なる可能性があります。optionsで確認できます)

✌(‘ω’✌ )三✌(‘ω’)✌三( ✌’ω’)✌たのしい!

なお、後になってDash-User-ContributionにChainerがあることを知った…
https://github.com/Kapeli/Dash-User-Contributions/tree/master/docsets/Chainer
常に自分の責任で最新に追従させたいわけじゃなければ、これで十分。メンテナのmitmulさんは同僚ですw

コメントを残す

メールアドレスが公開されることはありません。 が付いている欄は必須項目です