Skip to content

MkDocs can't build or serve when setting plugin locale #2

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

Closed
martinbira opened this issue Dec 12, 2019 · 6 comments
Closed

MkDocs can't build or serve when setting plugin locale #2

martinbira opened this issue Dec 12, 2019 · 6 comments
Labels
bug Something isn't working

Comments

@martinbira
Copy link

Background

Tried out this plugin using MkDocs and Material for MkDocs. Initially it didn't work at all when I set type: date and locale: en. I checked the docs from https://squidfunk.github.io/mkdocs-material/extensions/revision-date/ and used the config as stated there as I wanted date and my theme language was en:

plugins:
  - git-revision-date-localized

Everything worked locally using both mkdocs serve and mkdocs build and I added mkdocs-git-revision-date-localized-plugin==0.3.3 to my requirements.txt that is called through my Jenkinsfile.

The build then failed with the exakt error message as on line 33 from plugin.py, "WARNING - plugin locale setting '{plugin_locale}' will overwrite mkdocs locale '{mkdocs_locale}'". No filled in variables, just the straight error message from the console.

So I decided to try it out more locally and what I found out was that locally the mkdocs_locale = config.get('locale') returns None. So when the mkdocs_locale is None and I set the plugin_locale to anything, including the default en both serve and build fails locally.

I have unfortunately not found any useful info so far on how to set a mkdocs_locale .

System

MkDocs: 1.0.4
Material for MkDocs: 4.6.0
MkDocs Git Revision: 0.3.3

mkdocs.yml

theme:
    language: en
...
plugins:
  - git-revision-date-localized:
      type: date 
      locale: en

Error message

PS C:\MkDocs> mkdocs build
WARNING - plugin locale setting 'en' will overwrite mkdocs locale 'None'
INFO    -  Cleaning site directory
INFO    -  Building documentation to directory: C:\MkDocs\site
ERROR   -  Error reading page 'index.md': 'NoneType' object has no attribute 'date_formats'
Traceback (most recent call last):
  File "c:\python36\lib\runpy.py", line 193, in _run_module_as_main
    "__main__", mod_spec)
  File "c:\python36\lib\runpy.py", line 85, in _run_code
    exec(code, run_globals)
  File "C:\Python36\Scripts\mkdocs.exe\__main__.py", line 9, in <module>
  File "c:\python36\lib\site-packages\click\core.py", line 722, in __call__
    return self.main(*args, **kwargs)
  File "c:\python36\lib\site-packages\click\core.py", line 697, in main
    rv = self.invoke(ctx)
  File "c:\python36\lib\site-packages\click\core.py", line 1066, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "c:\python36\lib\site-packages\click\core.py", line 895, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "c:\python36\lib\site-packages\click\core.py", line 535, in invoke
    return callback(*args, **kwargs)
  File "c:\python36\lib\site-packages\mkdocs\__main__.py", line 163, in build_command
    ), dirty=not clean)
  File "c:\python36\lib\site-packages\mkdocs\commands\build.py", line 274, in build
    _populate_page(file.page, config, files, dirty)
  File "c:\python36\lib\site-packages\mkdocs\commands\build.py", line 174, in _populate_page
    'page_markdown', page.markdown, page=page, config=config, files=files
  File "c:\python36\lib\site-packages\mkdocs\plugins.py", line 94, in run_event
    result = method(item, **kwargs)
  File "c:\python36\lib\site-packages\mkdocs_git_revision_date_localized_plugin\plugin.py", line 52, in on_page_markdown
    locale = self.locale
  File "c:\python36\lib\site-packages\mkdocs_git_revision_date_localized_plugin\util.py", line 22, in get_revision_date_for_file
    'date' : format_date(revision_date, format="long", locale=locale),
  File "c:\python36\lib\site-packages\babel\dates.py", line 698, in format_date
    format = get_date_format(format, locale=locale)
  File "c:\python36\lib\site-packages\babel\dates.py", line 378, in get_date_format
    return Locale.parse(locale).date_formats[format]
AttributeError: 'NoneType' object has no attribute 'date_formats'
@timvink
Copy link
Owner

timvink commented Dec 16, 2019

Thanks for this! Was a bug on my side, fixed in the new version. Can you try again with:

pip install --upgrade mkdocs-git-revision-date-localized-plugin

@timvink timvink added the bug Something isn't working label Dec 16, 2019
@martinbira
Copy link
Author

I'm now getting a different error after updating:

PS C:\MkDocs> mkdocs build
Traceback (most recent call last):
  File "c:\python36\lib\runpy.py", line 193, in _run_module_as_main
    "__main__", mod_spec)
  File "c:\python36\lib\runpy.py", line 85, in _run_code
    exec(code, run_globals)
  File "C:\Python36\Scripts\mkdocs.exe\__main__.py", line 9, in <module>
  File "c:\python36\lib\site-packages\click\core.py", line 722, in __call__
    return self.main(*args, **kwargs)
  File "c:\python36\lib\site-packages\click\core.py", line 697, in main
    rv = self.invoke(ctx)
  File "c:\python36\lib\site-packages\click\core.py", line 1066, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "c:\python36\lib\site-packages\click\core.py", line 895, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "c:\python36\lib\site-packages\click\core.py", line 535, in invoke
    return callback(*args, **kwargs)
  File "c:\python36\lib\site-packages\mkdocs\__main__.py", line 163, in build_command
    ), dirty=not clean)
  File "c:\python36\lib\site-packages\mkdocs\commands\build.py", line 240, in build
    config = config['plugins'].run_event('config', config)
  File "c:\python36\lib\site-packages\mkdocs\plugins.py", line 94, in run_event
    result = method(item, **kwargs)
  File "c:\python36\lib\site-packages\mkdocs_git_revision_date_localized_plugin\plugin.py", line 26, in on_config
    theme_locale = vars(self.config['theme']).get('_vars', {}).get('locale')
  File "c:\python36\lib\collections\__init__.py", line 993, in __getitem__
    raise KeyError(key)
KeyError: 'theme'

Same error regardless if using the config with or without type and locale.

@timvink
Copy link
Owner

timvink commented Dec 16, 2019

Yes I introduced a new bug in that release, sorry for that. I need to write some units tests.. Should work now in v0.4.2

When you set the theme language the plugin locale is ignored, so no need to set both.

@martinbira
Copy link
Author

Plugin works as intended for me now! If you're all doe with test cases and such, please close the issue. Thanks for a great plugin!

@timvink
Copy link
Owner

timvink commented Dec 17, 2019

Opened #5 for adding unit tests. Thanks again for the feedback!

@timvink timvink closed this as completed Dec 17, 2019
@tcitworld
Copy link

Can confirmed it's fixed as well, thanks !

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants