やってみる

アウトプットすべく己を導くためのブログ。その試行錯誤すらたれ流す。

Pelicanのプラグインasciidoc_readerがPython2のみ対応で使えなかった

静的サイトジェネレータPelicanでAsciiDocを使いたかったが…。

開発環境

  • Linux Mint 17.3 MATE 32bit
  • pyenv
    • Python 3.6.1
    • (system)
      • Python 3.4.3 (default, Nov 17 2016, 01:11:57) [GCC 4.8.4] on linux
      • Python 2.7.6 (default, Jun 22 2015, 18:00:18) [GCC 4.8.2] on linux2
      • pip3 1.5.4 from /usr/lib/python3/dist-packages (python 3.4)
  • pelican-quickstart v3.7.1

前回まで

Ruby

Python

Pelicanのプラグインをダウンロードしたものの、AsciiDocプラグインが使えなかった。Python2で環境構築せねばならない。2は2020年でサポート終了するらしいので、今更使うかどうするか迷いどころ。Ruby製のAsciiDoctorにしたほうがいいか?

参考

準備

bash -l
$ python -V
Python 3.6.1
$ source .../venv/3_6_1/pelican_install/bin/activate
$ cd .../pelican_quickstart_blog
  • pyenvを有効にする
  • pythonは3.6.1を使う
  • venvで作った仮想環境pelican_installをアクティブにする
  • cdでブログのひな形を作ったディレクトリに移動する

プラグイン使用準備するも使えなかった

pelicanconf.py

PLUGIN_PATHS = ['.../root/pj/venv/3_6_1/pelican-plugins']
PLUGINS = ['asciidoc_reader', 'related_posts', 'tag_cloud', 'tipue_search', 'sitemap']

以下、AsciiDocが使えなかったログ。

$ make html

ERROR: Could not process ./index.asc
  | ModuleNotFoundError: No module named 'cStringIO'

stringio - python 3.x ImportError: No module named 'cStringIO' - Stack Overflow

asciidoc_reader.pyfrom cStringIO import StringIOfrom io import StringIOに変更する。

$ make html

ERROR: Could not process ./index.asc
  | TypeError: initial_value must be str or None, not bytes

stackoverflow.com

以下のように修正した。

    def read(self, source_path):
        """Parse content and metadata of asciidoc files"""
#        from cStringIO import StringIO
#        from io import StringIO
        from io import BytesIO
        with pelican_open(source_path) as source:
#            text = StringIO(source.encode('utf8'))
            text = BytesIO(source.encode('utf8'))
#        content = StringIO()
        content = BytesIO()
        ad = AsciiDocAPI()
$ make html

ERROR: Could not process ./index.asc
  | NameError: name 'AsciiDocAPI' is not defined

https://github.com/getpelican/pelican-plugins/tree/master/asciidoc_reader

asciidoc_readerはPython3では動作しないらしい。これはひどい

これならRuby製のAsciiDoctorを使ったほうがいいか。

所感

どうしよう…。

AsciiDoctorのRubyにしろ、AsciiDocAPIのPythonにしろ、大本のSDK環境構築とその利用が煩雑でむずかしい。