Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

mkdocs build will fail when as_datetime is true #18

Open
hitsumabushi845 opened this issue Feb 9, 2021 · 1 comment
Open

mkdocs build will fail when as_datetime is true #18

hitsumabushi845 opened this issue Feb 9, 2021 · 1 comment

Comments

@hitsumabushi845
Copy link

Hi
I'm facing the problem below, please let me know if there is some workaround to build document with as_datetime setting is enabled.

Description

When if as_datetime: true as the plugin setting, then the command mkdocs build will fail by the following error:

ERROR   -  Error reading page 'index.md': decoding to str: need a bytes-like object, datetime.datetime found 
Traceback (most recent call last):
  File "/usr/local/bin/mkdocs", line 8, in <module>
    sys.exit(cli())
  File "/usr/local/lib/python3.8/site-packages/click/core.py", line 829, in __call__
    return self.main(*args, **kwargs)
  File "/usr/local/lib/python3.8/site-packages/click/core.py", line 782, in main
    rv = self.invoke(ctx)
  File "/usr/local/lib/python3.8/site-packages/click/core.py", line 1259, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "/usr/local/lib/python3.8/site-packages/click/core.py", line 1066, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "/usr/local/lib/python3.8/site-packages/click/core.py", line 610, in invoke
    return callback(*args, **kwargs)
  File "/usr/local/lib/python3.8/site-packages/mkdocs/__main__.py", line 152, in build_command
    build.build(config.load_config(**kwargs), dirty=not clean)
  File "/usr/local/lib/python3.8/site-packages/mkdocs/commands/build.py", line 271, in build
    _populate_page(file.page, config, files, dirty)
  File "/usr/local/lib/python3.8/site-packages/mkdocs/commands/build.py", line 167, in _populate_page
    page.markdown = config['plugins'].run_event(
  File "/usr/local/lib/python3.8/site-packages/mkdocs/plugins.py", line 94, in run_event
    result = method(item, **kwargs)
  File "/usr/local/lib/python3.8/site-packages/mkdocs_git_revision_date_plugin/plugin.py", line 57, in on_page_markdown
    markdown = re.sub(r"\{\{(\s)*git_revision_date(\s)*\}\}",
  File "/usr/local/lib/python3.8/re.py", line 210, in sub
    return _compile(pattern, flags).sub(repl, string, count)
  File "/usr/local/lib/python3.8/re.py", line 327, in _subx
    template = _compile_repl(template, pattern)
  File "/usr/local/lib/python3.8/re.py", line 318, in _compile_repl
    return sre_parse.parse_template(repl, pattern)
  File "/usr/local/lib/python3.8/sre_parse.py", line 972, in parse_template
    s = Tokenizer(source)
  File "/usr/local/lib/python3.8/sre_parse.py", line 228, in __init__
    string = str(string, 'latin1')
TypeError: decoding to str: need a bytes-like object, datetime.datetime found

Steps to reproduce the bug

The problem can be reproduced by using the simple project below with the package versions below:
https://github.com/hitsumabushi845/git-revision-issue-reproduction

Package versions

  • Python: 3.8.6
  • MkDocs: 1.1.2
  • git-revision-plugin: 0.3.1
@hitsumabushi845
Copy link
Author

I'm investigating this issue.
it is caused by regex replacing as reported in the stacktrace above:

  File "/usr/local/lib/python3.8/site-packages/mkdocs_git_revision_date_plugin/plugin.py", line 57, in on_page_markdown
    markdown = re.sub(r"\{\{(\s)*git_revision_date(\s)*\}\}",

The repl argument of re.sub should be string or function but it is taking datetime object because of as_datetime: true.

This change is created by the PR #10, and it had been provided to solve the issue #9.

I have no idea to avoid both (reported here and #9) issues for now...I'll investigate for more.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant