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

Site build fails if using custom font, social plugin is enabled and deprecated cards_font is not set to a Google font #5628

Closed
4 tasks done
pereorga opened this issue Jun 21, 2023 · 4 comments
Labels
bug Issue reports a bug resolved Issue is resolved, yet unreleased if open

Comments

@pereorga
Copy link
Contributor

Context

No response

Bug description

I am experiencing an error with the following example configs:

theme:
  name: material
  font:
    text: Helvetica Neue
plugins:
  material/social:
theme:
  name: material
  font:
    text: Helvetica Neue
plugins:
  material/social:
    cards_layout_options:
      font_family: Roboto

The following config works though:

theme:
  name: material
  font:
    text: Helvetica Neue
plugins:
  material/social:
    cards_font: Roboto
$> poetry run mkdocs serve
Configuration file exists at /Users/pere/Library/Preferences/pypoetry, reusing this directory.

Consider moving TOML configuration files to /Users/pere/Library/Application Support/pypoetry, as support for the legacy directory will be removed in an upcoming release.
WARNING  -  Config value 'plugins': Plugin 'material/social' option 'cards_font': Deprecated, use 'cards_layout_options.font_family'
INFO     -  Building documentation...
[...]

With the first and second example configs, the error is:

Configuration file exists at /Users/pere/Library/Preferences/pypoetry, reusing this directory.

Consider moving TOML configuration files to /Users/pere/Library/Application Support/pypoetry, as support for the legacy directory will be removed in an upcoming release.
INFO     -  Building documentation...
Traceback (most recent call last):
  File "/Users/pere/Library/Caches/pypoetry/virtualenvs/docs-theme-demo-H653cWUy-py3.11/bin/mkdocs", line 8, in <module>
    sys.exit(cli())
             ^^^^^
  File "/Users/pere/Library/Caches/pypoetry/virtualenvs/docs-theme-demo-H653cWUy-py3.11/lib/python3.11/site-packages/click/core.py", line 1130, in __call__
    return self.main(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/pere/Library/Caches/pypoetry/virtualenvs/docs-theme-demo-H653cWUy-py3.11/lib/python3.11/site-packages/click/core.py", line 1055, in main
    rv = self.invoke(ctx)
         ^^^^^^^^^^^^^^^^
  File "/Users/pere/Library/Caches/pypoetry/virtualenvs/docs-theme-demo-H653cWUy-py3.11/lib/python3.11/site-packages/click/core.py", line 1657, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
                           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/pere/Library/Caches/pypoetry/virtualenvs/docs-theme-demo-H653cWUy-py3.11/lib/python3.11/site-packages/click/core.py", line 1404, in invoke
    return ctx.invoke(self.callback, **ctx.params)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/pere/Library/Caches/pypoetry/virtualenvs/docs-theme-demo-H653cWUy-py3.11/lib/python3.11/site-packages/click/core.py", line 760, in invoke
    return __callback(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/pere/Library/Caches/pypoetry/virtualenvs/docs-theme-demo-H653cWUy-py3.11/lib/python3.11/site-packages/mkdocs/__main__.py", line 234, in serve_command
    serve.serve(dev_addr=dev_addr, livereload=livereload, watch=watch, **kwargs)
  File "/Users/pere/Library/Caches/pypoetry/virtualenvs/docs-theme-demo-H653cWUy-py3.11/lib/python3.11/site-packages/mkdocs/commands/serve.py", line 83, in serve
    builder(config)
  File "/Users/pere/Library/Caches/pypoetry/virtualenvs/docs-theme-demo-H653cWUy-py3.11/lib/python3.11/site-packages/mkdocs/commands/serve.py", line 76, in builder
    build(config, live_server=live_server, dirty=dirty)
  File "/Users/pere/Library/Caches/pypoetry/virtualenvs/docs-theme-demo-H653cWUy-py3.11/lib/python3.11/site-packages/mkdocs/commands/build.py", line 270, in build
    config = config.plugins.run_event('config', config)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/pere/Library/Caches/pypoetry/virtualenvs/docs-theme-demo-H653cWUy-py3.11/lib/python3.11/site-packages/mkdocs/plugins.py", line 520, in run_event
    result = method(item, **kwargs)
             ^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/pere/Library/Caches/pypoetry/virtualenvs/docs-theme-demo-H653cWUy-py3.11/lib/python3.11/site-packages/material/plugins/social/plugin.py", line 157, in on_config
    self.font = self._load_font(config)
                ^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/pere/Library/Caches/pypoetry/virtualenvs/docs-theme-demo-H653cWUy-py3.11/lib/python3.11/site-packages/material/plugins/social/plugin.py", line 469, in _load_font
    self._load_font_from_google(name)
  File "/Users/pere/Library/Caches/pypoetry/virtualenvs/docs-theme-demo-H653cWUy-py3.11/lib/python3.11/site-packages/material/plugins/social/plugin.py", line 492, in _load_font_from_google
    zip = ZipFile(tmp)
          ^^^^^^^^^^^^
  File "/opt/homebrew/Cellar/[email protected]/3.11.4/Frameworks/Python.framework/Versions/3.11/lib/python3.11/zipfile.py", line 1302, in __init__
    self._RealGetContents()
  File "/opt/homebrew/Cellar/[email protected]/3.11.4/Frameworks/Python.framework/Versions/3.11/lib/python3.11/zipfile.py", line 1369, in _RealGetContents
    raise BadZipFile("File is not a zip file")
zipfile.BadZipFile: File is not a zip file

I tried adding a debug statement in material/plugins/social/plugin.py:

        # If none found, fetch from Google and try again
        if len(font) == 0:
            print ("Fetching font %s from Google" % name)
            self._load_font_from_google(name)

And it seems it is trying to download the custom font set in theme.font.text from Google Fonts:

$ poetry run mkdocs serve --config-file mkdocs-public.yml
Configuration file exists at /Users/pere/Library/Preferences/pypoetry, reusing this directory.

Consider moving TOML configuration files to /Users/pere/Library/Application Support/pypoetry, as support for the legacy directory will be removed in an upcoming release.
INFO     -  Building documentation...
Fetching font <CUSTOM_FONT_NAME> from Google
Traceback (most recent call last):
  File "/Users/pere/Library/Caches/pypoetry/virtualenvs/docs-theme-demo-H653cWUy-py3.11/bin/mkdocs", line 8, in <module>
    sys.exit(cli())
             ^^^^^
[...]

Related links

Reproduction

mk-test-1.zip

Steps to reproduce

Run mkdocs serve with the provided examples

Browser

No response

Before submitting

@squidfunk squidfunk added the needs investigation Issue must be investigated by the maintainers label Jun 23, 2023
@squidfunk
Copy link
Owner

Thanks for reporting! Fixed in d8a0e36. Indeed, this was not working as intended. MkDocs will set all undefined parameters to None unless defaults are given, which led to the font set to None. This should now be fixed.

@squidfunk squidfunk added bug Issue reports a bug resolved Issue is resolved, yet unreleased if open and removed needs investigation Issue must be investigated by the maintainers labels Jun 23, 2023
@squidfunk
Copy link
Owner

Released as part of 9.1.17.

@xanterx
Copy link

xanterx commented Jan 17, 2024

Still seeing the same error as part of 9.4.8 this version also.

Traceback (most recent call last):
  File "/Users/xanterx/Dojo/dop/dop-docs/.venv/bin/mkdocs", line 8, in <module>
    sys.exit(cli())
             ^^^^^
  File "/Users/xanterx/Dojo/dop/dop-docs/.venv/lib/python3.12/site-packages/click/core.py", line 1157, in __call__
    return self.main(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/xanterx/Dojo/dop/dop-docs/.venv/lib/python3.12/site-packages/click/core.py", line 1078, in main
    rv = self.invoke(ctx)
         ^^^^^^^^^^^^^^^^
  File "/Users/xanterx/Dojo/dop/dop-docs/.venv/lib/python3.12/site-packages/click/core.py", line 1688, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
                           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/xanterx/Dojo/dop/dop-docs/.venv/lib/python3.12/site-packages/click/core.py", line 1434, in invoke
    return ctx.invoke(self.callback, **ctx.params)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/xanterx/Dojo/dop/dop-docs/.venv/lib/python3.12/site-packages/click/core.py", line 783, in invoke
    return __callback(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/xanterx/Dojo/dop/dop-docs/.venv/lib/python3.12/site-packages/mkdocs/__main__.py", line 270, in serve_command
    serve.serve(**kwargs)
  File "/Users/xanterx/Dojo/dop/dop-docs/.venv/lib/python3.12/site-packages/mkdocs/commands/serve.py", line 86, in serve
    builder(config)
  File "/Users/xanterx/Dojo/dop/dop-docs/.venv/lib/python3.12/site-packages/mkdocs/commands/serve.py", line 67, in builder
    build(config, live_server=None if is_clean else server, dirty=is_dirty)
  File "/Users/xanterx/Dojo/dop/dop-docs/.venv/lib/python3.12/site-packages/mkdocs/commands/build.py", line 277, in build
    config = config.plugins.on_config(config)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/xanterx/Dojo/dop/dop-docs/.venv/lib/python3.12/site-packages/mkdocs/plugins.py", line 527, in on_config
    return self.run_event('config', config)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/xanterx/Dojo/dop/dop-docs/.venv/lib/python3.12/site-packages/mkdocs/plugins.py", line 507, in run_event
    result = method(item, **kwargs)
             ^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/xanterx/Dojo/dop/dop-docs/.venv/lib/python3.12/site-packages/material/plugins/social/plugin.py", line 138, in on_config
    self.font = self._load_font(config)
                ^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/xanterx/Dojo/dop/dop-docs/.venv/lib/python3.12/site-packages/material/plugins/social/plugin.py", line 454, in _load_font
    self._load_font_from_google(name)
  File "/Users/xanterx/Dojo/dop/dop-docs/.venv/lib/python3.12/site-packages/material/plugins/social/plugin.py", line 477, in _load_font_from_google
    zip = ZipFile(tmp)
          ^^^^^^^^^^^^
  File "/Users/xanterx/.pyenv/versions/3.12.0/lib/python3.12/zipfile/__init__.py", line 1338, in __init__
    self._RealGetContents()
  File "/Users/xanterx/.pyenv/versions/3.12.0/lib/python3.12/zipfile/__init__.py", line 1405, in _RealGetContents
    raise BadZipFile("File is not a zip file")
zipfile.BadZipFile: File is not a zip file

Adding this config as mentioned in the issue seems to solve the issue.

plugins:
  - social:
      cards_font: Roboto

@squidfunk
Copy link
Owner

We'll need a fully self-contained and minimal reproduction. Please create a new issue by following our bug reporting guide.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Issue reports a bug resolved Issue is resolved, yet unreleased if open
Projects
None yet
Development

No branches or pull requests

3 participants