Mkdocs-material: mkdocs.theme.Theme object has no attribute language

Created on 2 Apr 2018  路  20Comments  路  Source: squidfunk/mkdocs-material

Description

mkdocs 0.17.2 plus mkdocs-material 2.7.1 produces error:

jinja2.exceptions.UndefinedError: 'mkdocs.theme.Theme object' has no attribute 'language'

Expected behavior

output is built

Actual behavior

Full log with -v:

```DEBUG - Loading configuration file: /Users/jwiens/vector35/binaryninja/api/mkdocs.yml
WARNING - Config value: 'theme_dir'. Warning: The configuration option {0} has been deprecated and will be removed in a future release of MkDocs.
WARNING - Config value: 'site_favicon'. Warning: Unrecognised configuration name: site_favicon
DEBUG - Config value: 'site_name' = u'Binary Ninja Documentation'
DEBUG - Config value: 'extra' =
DEBUG - Config value: 'extra_javascript' = []
DEBUG - Config value: 'plugins' = PluginCollection([(u'search', )])
DEBUG - Config value: 'site_favicon' = u'favicon.ico'
DEBUG - Config value: 'extra_css' = [u'docs.css?1522699268']
DEBUG - Config value: 'theme_dir' = u'/Users/jwiens/vector35/binaryninja/api/mkdocs-material/material'
DEBUG - Config value: 'config_file_path' = u'/Users/jwiens/vector35/binaryninja/api/mkdocs.yml'
DEBUG - Config value: 'copyright' = u'(cc) Vector 35 LLC'
DEBUG - Config value: 'remote_branch' = u'gh-pages'
DEBUG - Config value: 'site_url' = u'https://docs.binary.ninja/'
DEBUG - Config value: 'use_directory_urls' = False
DEBUG - Config value: 'strict' = False
DEBUG - Config value: 'theme' = Theme(name='None', dirs=[u'/Users/jwiens/vector35/binaryninja/api/mkdocs-material/material', u'/usr/local/Cellar/mkdocs/0.17.2/libexec/lib/python2.7/site-packages/mkdocs/templates'], static_templates=[u'sitemap.xml'], )
DEBUG - Config value: 'docs_dir' = u'/Users/jwiens/vector35/binaryninja/api/docs'
DEBUG - Config value: 'repo_name' = u'github'
DEBUG - Config value: 'site_dir' = u'/Users/jwiens/vector35/binaryninja/api/site'
DEBUG - Config value: 'dev_addr' = Address(host=u'127.0.0.1', port=8000)
DEBUG - Config value: 'repo_url' = u'https://binary.ninja/'
DEBUG - Config value: 'remote_name' = u'origin'
DEBUG - Config value: 'pages' = [{u'Home': u'index.md'}, {u'Getting Started Guide': u'getting-started.md'}, {u'User Guide': [{u'Using and Writing Plugins': u'guide/plugins.md'}, {u'Troubleshooting': u'guide/troubleshooting.md'}]}, {u'Developer Guide': [{u'Contributing Documentation': u'dev/documentation.md'}, {u'BNIL Guide: LLIL': u'dev/bnil-llil.md'}]}, {u'About': [{u'License': u'about/license.md'}, {u'Open Source': u'about/open-source.md'}]}]
DEBUG - Config value: 'markdown_extensions' = [u'toc', u'tables', u'fenced_code', u'codehilite', u'admonition']
DEBUG - Config value: 'site_description' = u'Documentation for the Binary Ninja reverse engineering platform'
DEBUG - Config value: 'extra_templates' = []
DEBUG - Config value: 'site_author' = u'Vector 35 LLC'
DEBUG - Config value: 'google_analytics' = [u'UA-72420552-3', u'docs.binary.ninja']
DEBUG - Config value: 'mdx_configs' = {u'toc': {u'permalink': True}}
DEBUG - Config value: 'edit_uri' = u''
INFO - Cleaning site directory
INFO - Building documentation to directory: /Users/jwiens/vector35/binaryninja/api/site
DEBUG - Copying static assets from /usr/local/Cellar/mkdocs/0.17.2/libexec/lib/python2.7/site-packages/mkdocs/contrib/legacy_search/templates
DEBUG - Copying static assets from the docs dir.
DEBUG - Building template: sitemap.xml
DEBUG - Building extra_templates pages
DEBUG - Building markdown pages.
DEBUG - Building page index.md
ERROR - Error building page index.md
Traceback (most recent call last):
File "/usr/local/bin/mkdocs", line 11, in
load_entry_point('mkdocs==0.17.2', 'console_scripts', 'mkdocs')()
File "/usr/local/Cellar/mkdocs/0.17.2/libexec/lib/python2.7/site-packages/click/core.py", line 722, in __call__
return self.main(args, *kwargs)
File "/usr/local/Cellar/mkdocs/0.17.2/libexec/lib/python2.7/site-packages/click/core.py", line 697, in main
rv = self.invoke(ctx)
File "/usr/local/Cellar/mkdocs/0.17.2/libexec/lib/python2.7/site-packages/click/core.py", line 1066, in invoke
return _process_result(sub_ctx.command.invoke(sub_ctx))
File "/usr/local/Cellar/mkdocs/0.17.2/libexec/lib/python2.7/site-packages/click/core.py", line 895, in invoke
return ctx.invoke(self.callback, *ctx.params)
File "/usr/local/Cellar/mkdocs/0.17.2/libexec/lib/python2.7/site-packages/click/core.py", line 535, in invoke
return callback(
args, **kwargs)
File "/usr/local/Cellar/mkdocs/0.17.2/libexec/lib/python2.7/site-packages/mkdocs/__main__.py", line 156, in build_command
), dirty=not clean)
File "/usr/local/Cellar/mkdocs/0.17.2/libexec/lib/python2.7/site-packages/mkdocs/commands/build.py", line 282, in build
build_pages(config, dirty=dirty)
File "/usr/local/Cellar/mkdocs/0.17.2/libexec/lib/python2.7/site-packages/mkdocs/commands/build.py", line 242, in build_pages
_build_page(page, config, site_navigation, env)
File "/usr/local/Cellar/mkdocs/0.17.2/libexec/lib/python2.7/site-packages/mkdocs/commands/build.py", line 158, in _build_page
output_content = template.render(context)
File "/usr/local/Cellar/mkdocs/0.17.2/libexec/lib/python2.7/site-packages/jinja2/environment.py", line 1008, in render
return self.environment.handle_exception(exc_info, True)
File "/usr/local/Cellar/mkdocs/0.17.2/libexec/lib/python2.7/site-packages/jinja2/environment.py", line 780, in handle_exception
reraise(exc_type, exc_value, tb)
File "/Users/jwiens/vector35/binaryninja/api/mkdocs-material/material/main.html", line 1, in top-level template code
{% extends "base.html" %}
File "/Users/jwiens/vector35/binaryninja/api/mkdocs-material/material/base.html", line 1, in top-level template code
{% import "partials/language.html" as lang with context %}
File "/usr/local/Cellar/mkdocs/0.17.2/libexec/lib/python2.7/site-packages/jinja2/environment.py", line 1073, in make_module
return TemplateModule(self, self.new_context(vars, shared, locals))
File "/usr/local/Cellar/mkdocs/0.17.2/libexec/lib/python2.7/site-packages/jinja2/environment.py", line 1152, in __init__
body_stream = list(template.root_render_func(context))
File "/Users/jwiens/vector35/binaryninja/api/mkdocs-material/material/partials/language.html", line 1, in top-level template code
{% import "partials/language/" + config.theme.language + ".html" as lang %}
jinja2.exceptions.UndefinedError: 'mkdocs.theme.Theme object' has no attribute 'language'

### Steps to reproduce the bug

1. Upgraded from mkdocs 0.16.x to 0.17.2 and updated mkdocs-material to 2.7.1
2. try to `mkdocs build` using previously working configuration

### Package versions

* Python: `Python 2.7.10`
* MkDocs: `mkdocs, version 0.17.2`
* Material: See below.

I'm not using the pip version but rather specifying the theme via `theme_dir: 'mkdocs-material/material'` where I've downloaded the latest build of mkdocs-material into a subfolder:

$ head -n1 mkdocs-material/CHANGELOG
mkdocs-material-2.7.1 (2018-03-21)

### Project configuration

``` yaml
DEBUG   -  Config value: 'pages' = [{u'Home': u'index.md'}, {u'Getting Started Guide': u'getting-started.md'}, {u'User Guide': [{u'Usinsite_name: 'Binary Ninja Documentation'
site_url: 'https://docs.binary.ninja/'
repo_url: 'https://binary.ninja/'
repo_name: 'github'
site_description: 'Documentation for the Binary Ninja reverse engineering platform'
site_author: 'Vector 35 LLC'
site_favicon: 'favicon.ico'
google_analytics: ['UA-72420552-3', 'docs.binary.ninja' ]
use_directory_urls: False
extra_css: ['docs.css?1522699268']

theme_dir: 'mkdocs-material/material'
copyright: '(<a href="https://creativecommons.org/licenses/by/3.0/">cc</a>) Vector 35 LLC'

markdown_extensions:
    - codehilite
    - admonition
    - toc:
        permalink: True

pages:
    - Home: 'index.md'
    - Getting Started Guide: 'getting-started.md'
    - User Guide:
        - Using and Writing Plugins: 'guide/plugins.md'
        - Troubleshooting: 'guide/troubleshooting.md'
    - Developer Guide:
        - Contributing Documentation: 'dev/documentation.md'
        - BNIL Guide&#58; LLIL: 'dev/bnil-llil.md'
    - About:
        - License: 'about/license.md'
        - Open Source: 'about/open-source.md'

extra:
    disablesearch: True
    logo: 'images/logo.png'

System information

  • OS: MacOS 10.13.4
  • Browser: N/A

Most helpful comment

When cloning the repo and using that as your theme, it appears as you must provide all of these attributes.

theme:
  name: null
  custom_dir: mkdocs-material/material
  language: en
  palette:
    primary: indigo
    accent: indigo
  font:
    text: Roboto
    code: Roboto Mono
  logo:
    icon: "\uE80C"
  feature:
    tabs: true

All 20 comments

I just tried to install mkdocs-material via pip and use a system-wide theme and it looks like it worked fine. That said, I'd still like to be able to build using the above specified config since it makes my build infrastructure a bit easier.

Is there any reason that mkdocs-material wouldn't work if specified by theme-dir but would once installed and specified via theme?

Answered my own question. Looks like the bare theme-dir config is incorrect and it works fine with

theme: 
  theme_dir: 'mkdocs-material/material'

Still experiencing the same error

INFO    -  Building documentation...
ERROR   -  Config value: 'theme'. Error: No theme name set.

Aborted with 1 Configuration Errors!

If I use the above instruction I get this error

Please post your configuration and versions, so we can help you better.

This is the config I'm using and I get the same error:

theme:
  name: null
  custom_dir: 'material/material/'
$ mkdocs --version
mkdocs, version 1.0.4 from /home/a/.local/lib/python2.7/site-packages/mkdocs (Python 2.7)

material is a checkout of https://github.com/squidfunk/mkdocs-material.

There were two different errors discussed in this issue - which one are you getting? Please give us some more data. Also, does it work with the version from PyPI or the official Docker image? It鈥檚 most likely a configuration or installation error.

I believe I have this same exact problem, but on Ubuntu 18. Mkdocs version 1.0.4. Python 2.7.

I've installed mkdocs via pip, and I cloned mkdocs-material from this repo into the root directory of the folder mkdocs created for my project.

When my site configuration looks like this

site_name: Client Portal
theme:
  name: null
  custom_dir: 'mkdocs-material/material'

I get the following output

INFO    -  Building documentation... 
INFO    -  Cleaning site directory 
ERROR   -  Error building page 'index.md': 'mkdocs.theme.Theme object' has no attribute 'language' 
Traceback (most recent call last):
  File "/usr/local/bin/mkdocs", line 10, in <module>
    sys.exit(cli())
  File "/home/jhsheridan/.local/lib/python2.7/site-packages/click/core.py", line 722, in __call__
    return self.main(*args, **kwargs)
  File "/home/jhsheridan/.local/lib/python2.7/site-packages/click/core.py", line 697, in main
    rv = self.invoke(ctx)
  File "/home/jhsheridan/.local/lib/python2.7/site-packages/click/core.py", line 1066, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "/home/jhsheridan/.local/lib/python2.7/site-packages/click/core.py", line 895, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "/home/jhsheridan/.local/lib/python2.7/site-packages/click/core.py", line 535, in invoke
    return callback(*args, **kwargs)
  File "/usr/local/lib/python2.7/dist-packages/mkdocs/__main__.py", line 134, in serve_command
    livereload=livereload
  File "/usr/local/lib/python2.7/dist-packages/mkdocs/commands/serve.py", line 119, in serve
    config = builder()
  File "/usr/local/lib/python2.7/dist-packages/mkdocs/commands/serve.py", line 114, in builder
    build(config, live_server=live_server, dirty=dirty)
  File "/usr/local/lib/python2.7/dist-packages/mkdocs/commands/build.py", line 295, in build
    _build_page(file.page, config, files, nav, env, dirty)
  File "/usr/local/lib/python2.7/dist-packages/mkdocs/commands/build.py", line 216, in _build_page
    output = template.render(context)
  File "/home/jhsheridan/.local/lib/python2.7/site-packages/jinja2/environment.py", line 1008, in render
    return self.environment.handle_exception(exc_info, True)
  File "/home/jhsheridan/.local/lib/python2.7/site-packages/jinja2/environment.py", line 780, in handle_exception
    reraise(exc_type, exc_value, tb)
  File "/home/jhsheridan/Projects/tower26/tower26-docs/mkdocs-material/material/main.html", line 1, in top-level template code
    {% extends "base.html" %}
  File "/home/jhsheridan/Projects/tower26/tower26-docs/mkdocs-material/material/base.html", line 1, in top-level template code
    {% import "partials/language.html" as lang with context %}
  File "/home/jhsheridan/.local/lib/python2.7/site-packages/jinja2/environment.py", line 1073, in make_module
    return TemplateModule(self, self.new_context(vars, shared, locals))
  File "/home/jhsheridan/.local/lib/python2.7/site-packages/jinja2/environment.py", line 1152, in __init__
    body_stream = list(template.root_render_func(context))
  File "/home/jhsheridan/Projects/tower26/tower26-docs/mkdocs-material/material/partials/language.html", line 1, in top-level template code
    {% import "partials/language/" + config.theme.language + ".html" as lang %}
jinja2.exceptions.UndefinedError: 'mkdocs.theme.Theme object' has no attribute 'language'

When my configuration file looks like this

site_name: Client Portal
theme:
  name: null
  theme_dir: 'mkdocs-material/material'

I get the following output

INFO    -  Building documentation... 
ERROR   -  Config value: 'theme'. Error: At least one of 'theme.name' or 'theme.custom_dir' must be defined. 

Aborted with 1 Configuration Errors!

Any ideas?

When cloning the repo and using that as your theme, it appears as you must provide all of these attributes.

theme:
  name: null
  custom_dir: mkdocs-material/material
  language: en
  palette:
    primary: indigo
    accent: indigo
  font:
    text: Roboto
    code: Roboto Mono
  logo:
    icon: "\uE80C"
  feature:
    tabs: true

Hmm, MkDocs should pick up the mkdocs_theme.yml from the material directory, but it doesn't? That's odd.

@squidfunk it doesn't appear to when i tested it this morning

Confirmed. Could not find anything in the official docs regarding this behavior. However, it's probably not specific to Material, it might happen with any theme that defines defaults for configuration options in mkdocs_theme.yml that are referenced in templates.

I don't know whether it's by design or by accident, maybe @waylan can shed some light on this?

There have been no recent changes which should be causing this. Without taking a closer look, my assumption is that the problem is on your end.

@werne2j this immediately solved my problem. Thanks so much!

When cloning the repo and using that as your theme, it appears as you must provide all of these attributes.

theme:
  name: null
  custom_dir: mkdocs-material/material
  language: en
  palette:
    primary: indigo
    accent: indigo
  font:
    text: Roboto
    code: Roboto Mono
  logo:
    icon: "\uE80C"
  feature:
    tabs: true

I found that I had to specify only the top-level attributes. In my case, I had a custom build (compiled from SASS) of the theme with special colors, so doing it the way you did caused my custom colors to be overriden. This is certainly a weird behavior. I am just putting this here to hopefully save somebody else some time.

theme:
  name: null
  custom_dir: mkdocs-material/material
  language: en
  palette:
  font:
    text: Roboto
    code: Roboto Mono
  logo:
    icon: "\uE80C"
  feature:
    tabs: true

So I just reread this issue and I noticed that the user is loading the theme through the theme.custom_dir setting (theme.name is set to null). It was also explained that the user was git cloning the repo, not installing the theme as a Python package. I missed those two details earlier and those two things are the cause of the problem.

Note that mkdocs_theme.yml is not loaded from theme.custom_dir. Therefore, if a user elects to load a theme this way, the user must define all settings (including defaults) which the theme expects within the theme config of mkdocs.yml. In other words, the entire content of mkdocs_theme.yml would need to be copied to the theme config in mkdocs.yml.

If you want mkdocs_theme.yml to be used to define defaults, the theme must be installed as a Python package and must be loaded with theme.name. This is an intentional design decision my MkDocs.

Ah, that makes sense. Thank you for the clarification. Is this in the documentation anywhere? Seems like it might be worth mentioning, but maybe I just missed it.

Is this in the documentation anywhere?

Only indirectly. Under Theme Configuration, it is noted in the opening sentence that mkdocs_theme.yml is required for "a packaged theme" but nowhere do the docs explicitly state that mkdocs_theme.yml is not loaded from theme.custom_dir.

Seems like it might be worth mentioning

I agree. Therefore, I created mkdocs/mkdocs#1811 to rectify the situation.

Thanks for revisiting this, @waylan. I was suspecting that theme configuration is not picked up for custom directories but didn't find anything in the docs.

@waylan That cost me over an hour to figure out today, guess I should have googled sooner. 馃槙 Huge problem that your online docs/gh-pages are super behind and the changes never went live there.

C:\Users\Gaurav ECE\Desktop\citrixtheme>mkdocs build
INFO - Cleaning site directory
INFO - Building documentation to directory: C:\Users\Gaurav ECE\Desktop\citrixtheme\site
Traceback (most recent call last):
File "c:\users\gaurav eceappdata\local\programs\python\python36-32\lib\runpy.py", line 193, in _run_module_as_main
"__main__", mod_spec)
File "c:\users\gaurav eceappdata\local\programs\python\python36-32\lib\runpy.py", line 85, in _run_code
exec(code, run_globals)
File "C:\Users\Gaurav ECE\AppData\Local\Programs\Python\Python36-32\Scripts\mkdocs.exe__main__.py", line 9, in
File "c:\users\gaurav eceappdata\local\programs\python\python36-32\lib\site-packages\click\core.py", line 829, in __call__
return self.main(args, kwargs)
File "c:\users\gaurav eceappdata\local\programs\python\python36-32\lib\site-packages\click\core.py", line 782, in main
rv = self.invoke(ctx)
File "c:\users\gaurav eceappdata\local\programs\python\python36-32\lib\site-packages\click\core.py", line 1259, in invoke
return _process_result(sub_ctx.command.invoke(sub_ctx))
File "c:\users\gaurav eceappdata\local\programs\python\python36-32\lib\site-packages\click\core.py", line 1066, in invoke
return ctx.invoke(self.callback, *
ctx.params)
File "c:\users\gaurav eceappdata\local\programs\python\python36-32\lib\site-packages\click\core.py", line 610, in invoke
return callback(args, *kwargs)
File "c:\users\gaurav eceappdata\local\programs\python\python36-32\lib\site-packages\mkdocs__main__.py", line 152, in build_command
build.build(config.load_config(
kwargs), dirty=not clean)
File "c:\users\gaurav eceappdata\local\programs\python\python36-32\lib\site-packages\mkdocs\commands\build.py", line 285, in build
_build_theme_template(template, env, files, config, nav)
File "c:\users\gaurav eceappdata\local\programs\python\python36-32\lib\site-packages\mkdocs\commands\build.py", line 108, in _build_theme_template
output = _build_template(template_name, template, files, config, nav)
File "c:\users\gaurav eceappdata\local\programs\python\python36-32\lib\site-packages\mkdocs\commands\build.py", line 87, in _build_template
output = template.render(context)
File "c:\users\gaurav eceappdata\local\programs\python\python36-32\lib\site-packages\jinja2\environment.py", line 1090, in render
self.environment.handle_exception()
File "c:\users\gaurav eceappdata\local\programs\python\python36-32\lib\site-packages\jinja2\environment.py", line 832, in handle_exception
reraise(*rewrite_traceback_stack(source=source))
File "c:\users\gaurav eceappdata\local\programs\python\python36-32\lib\site-packages\jinja2_compat.py", line 28, in reraise
raise value.with_traceback(tb)
File "C:\Users\Gaurav ECE\Desktop\citrixtheme\custom_them\404.html", line 4, in top-level template code
{% extends "base.html" %}
File "C:\Users\Gaurav ECE\Desktop\citrixtheme\custom_them\base.html", line 108, in top-level template code
{% block header %}
File "C:\Users\Gaurav ECE\Desktop\citrixtheme\custom_them\base.html", line 109, in block "header"
{% include "partials/header.html" %}
File "C:\Users\Gaurav ECE\Desktop\citrixtheme\custom_them\partials\header.html", line 8, in top-level template code
{% if config.theme.logo.icon %}
File "c:\users\gaurav eceappdata\local\programs\python\python36-32\lib\site-packages\jinja2\environment.py", line 471, in getattr
return getattr(obj, attribute)
jinja2.exceptions.UndefinedError: 'mkdocs.theme.Theme object' has no attribute 'logo'

i am getting this as error:
my configuration looks like following
site_name: ""
nav:

  • Introduction : 'index.md'
  • Overview: 'overview.md'
  • Getting Started : 'getting-started.md'
  • Using : 'using.md'
  • Using HTTP: 'using-http.md'
  • Citrix Hypervisor Management API Extensions: 'xs-api-extensions.md'
  • XenCenter API Extension : 'xc-api-extensions.md'
    theme:
    name: null
    custom_dir: 'custom_them'
    language: en
    direction:
    features: []
    palette:
    primary:
    accent:
    font:
    text: Roboto
    code: Roboto Mono
    icon:
    favicon: assets/images/favicon.png
    include_search_page: false
    search_index_only: true
    static_templates:

    • 404.html

      extra_css:

    • css/a.css

      @waylan please resolve this

Was this page helpful?
0 / 5 - 0 ratings

Related issues

Timber232 picture Timber232  路  3Comments

yannduran picture yannduran  路  4Comments

LinusGeffarth picture LinusGeffarth  路  3Comments

40huo picture 40huo  路  3Comments

BamBalaam picture BamBalaam  路  4Comments