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

TypeError: expected string or bytes-like object in social plugin #5420

Closed
4 tasks done
jawnsy opened this issue Apr 24, 2023 · 7 comments
Closed
4 tasks done

TypeError: expected string or bytes-like object in social plugin #5420

jawnsy opened this issue Apr 24, 2023 · 7 comments
Labels
bug Issue reports a bug resolved Issue is resolved, yet unreleased if open

Comments

@jawnsy
Copy link

jawnsy commented Apr 24, 2023

Context

We are using mkdocs-insiders with the social plugin. We get an error (which may be related to our docs) but I'm not too sure how to track it down.

Bug description

Our Insiders build fails in Netlify with the following stack trace:

2:02:25 PM: Traceback (most recent call last):
2:02:25 PM:   File "/opt/buildhome/python3.8/bin/mkdocs", line 8, in <module>
2:02:25 PM:     sys.exit(cli())
2:02:25 PM:   File "/opt/buildhome/python3.8/lib/python3.8/site-packages/click/core.py", line 1130, in __call__
2:02:25 PM:     return self.main(*args, **kwargs)
2:02:25 PM:   File "/opt/buildhome/python3.8/lib/python3.8/site-packages/click/core.py", line 1055, in main
2:02:25 PM:     rv = self.invoke(ctx)
2:02:25 PM:   File "/opt/buildhome/python3.8/lib/python3.8/site-packages/click/core.py", line 1657, in invoke
2:02:25 PM:     return _process_result(sub_ctx.command.invoke(sub_ctx))
2:02:25 PM:   File "/opt/buildhome/python3.8/lib/python3.8/site-packages/click/core.py", line 1404, in invoke
2:02:25 PM:     return ctx.invoke(self.callback, **ctx.params)
2:02:25 PM:   File "/opt/buildhome/python3.8/lib/python3.8/site-packages/click/core.py", line 760, in invoke
2:02:25 PM:     return __callback(*args, **kwargs)
2:02:25 PM:   File "/opt/buildhome/python3.8/lib/python3.8/site-packages/mkdocs/__main__.py", line 250, in build_command
2:02:25 PM:     build.build(cfg, dirty=not clean)
2:02:25 PM:   File "/opt/buildhome/python3.8/lib/python3.8/site-packages/mkdocs/commands/build.py", line 332, in build
2:02:25 PM:     config.plugins.run_event('post_build', config=config)
2:02:25 PM:   File "/opt/buildhome/python3.8/lib/python3.8/site-packages/mkdocs/plugins.py", line 522, in run_event
2:02:25 PM:     result = method(**kwargs)
2:02:25 PM:   File "/opt/buildhome/python3.8/lib/python3.8/site-packages/material/plugins/social/plugin.py", line 173, in on_post_build
2:02:25 PM:     promise.result()
2:02:25 PM:   File "/usr/lib/python3.8/concurrent/futures/_base.py", line 437, in result
2:02:25 PM:     return self.__get_result()
2:02:25 PM:   File "/usr/lib/python3.8/concurrent/futures/_base.py", line 389, in __get_result
2:02:25 PM:     raise self._exception
2:02:25 PM:   File "/usr/lib/python3.8/concurrent/futures/thread.py", line 57, in run
2:02:25 PM:     result = self.fn(*self.args, **self.kwargs)
2:02:25 PM:   File "/opt/buildhome/python3.8/lib/python3.8/site-packages/material/plugins/social/plugin.py", line 180, in _cache_image
2:02:25 PM:     image = render_function()
2:02:25 PM:   File "/opt/buildhome/python3.8/lib/python3.8/site-packages/material/plugins/social/plugin.py", line 160, in <lambda>
2:02:25 PM:     render_function = lambda: self._render_card(site_name, title, description)
2:02:25 PM:   File "/opt/buildhome/python3.8/lib/python3.8/site-packages/material/plugins/social/plugin.py", line 209, in _render_card
2:02:25 PM:     self._render_text((826, 328), font, title, 3, 30),
2:02:25 PM:   File "/opt/buildhome/python3.8/lib/python3.8/site-packages/material/plugins/social/plugin.py", line 242, in _render_text
2:02:25 PM:     text = re.sub(r"(<[^>]+>)", "", text)
2:02:25 PM:   File "/usr/lib/python3.8/re.py", line 210, in sub
2:02:25 PM:     return _compile(pattern, flags).sub(repl, string, count)
2:02:25 PM: TypeError: expected string or bytes-like object

I get the same error when running locally:

Traceback (most recent call last):
  File "/opt/homebrew/Caskroom/miniconda/base/envs/prefect2-dev/bin/mkdocs", line 8, in <module>
    sys.exit(cli())
  File "/opt/homebrew/Caskroom/miniconda/base/envs/prefect2-dev/lib/python3.10/site-packages/click/core.py", line 1130, in __call__
    return self.main(*args, **kwargs)
  File "/opt/homebrew/Caskroom/miniconda/base/envs/prefect2-dev/lib/python3.10/site-packages/click/core.py", line 1055, in main
    rv = self.invoke(ctx)
  File "/opt/homebrew/Caskroom/miniconda/base/envs/prefect2-dev/lib/python3.10/site-packages/click/core.py", line 1657, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "/opt/homebrew/Caskroom/miniconda/base/envs/prefect2-dev/lib/python3.10/site-packages/click/core.py", line 1404, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "/opt/homebrew/Caskroom/miniconda/base/envs/prefect2-dev/lib/python3.10/site-packages/click/core.py", line 760, in invoke
    return __callback(*args, **kwargs)
  File "/opt/homebrew/Caskroom/miniconda/base/envs/prefect2-dev/lib/python3.10/site-packages/mkdocs/__main__.py", line 250, in build_command
    build.build(cfg, dirty=not clean)
  File "/opt/homebrew/Caskroom/miniconda/base/envs/prefect2-dev/lib/python3.10/site-packages/mkdocs/commands/build.py", line 332, in build
    config.plugins.run_event('post_build', config=config)
  File "/opt/homebrew/Caskroom/miniconda/base/envs/prefect2-dev/lib/python3.10/site-packages/mkdocs/plugins.py", line 522, in run_event
    result = method(**kwargs)
  File "/Users/jawnsy/projects/work/mkdocs-material-insiders/material/plugins/social/plugin.py", line 173, in on_post_build
    promise.result()
  File "/opt/homebrew/Caskroom/miniconda/base/envs/prefect2-dev/lib/python3.10/concurrent/futures/_base.py", line 451, in result
    return self.__get_result()
  File "/opt/homebrew/Caskroom/miniconda/base/envs/prefect2-dev/lib/python3.10/concurrent/futures/_base.py", line 403, in __get_result
    raise self._exception
  File "/opt/homebrew/Caskroom/miniconda/base/envs/prefect2-dev/lib/python3.10/concurrent/futures/thread.py", line 58, in run
    result = self.fn(*self.args, **self.kwargs)
  File "/Users/jawnsy/projects/work/mkdocs-material-insiders/material/plugins/social/plugin.py", line 180, in _cache_image
    image = render_function()
  File "/Users/jawnsy/projects/work/mkdocs-material-insiders/material/plugins/social/plugin.py", line 160, in <lambda>
    render_function = lambda: self._render_card(site_name, title, description)
  File "/Users/jawnsy/projects/work/mkdocs-material-insiders/material/plugins/social/plugin.py", line 209, in _render_card
    self._render_text((826, 328), font, title, 3, 30),
  File "/Users/jawnsy/projects/work/mkdocs-material-insiders/material/plugins/social/plugin.py", line 242, in _render_text
    text = re.sub(r"(<[^>]+>)", "", text)
  File "/opt/homebrew/Caskroom/miniconda/base/envs/prefect2-dev/lib/python3.10/re.py", line 209, in sub
    return _compile(pattern, flags).sub(repl, string, count)
TypeError: expected string or bytes-like object

Related links

Reproduction

I don't know how to create a minimal reproduction for this particular issue, given the information in the stack trace and build logs

Steps to reproduce

Running an Insiders build from https://github.com/PrefectHQ/prefect with mkdocs.insiders.yml and the social plugin enabled should reproduce this issue.

Browser

No response

Before submitting

@squidfunk
Copy link
Owner

Thanks for reporting! My guess would be that you set description or title in the front matter of a page to a non-string value. However, in order to look into this, we really need a reproduction to look into this. Have you tried the steps outlined in our docs? If so, what exactly does not work?

@squidfunk squidfunk added the needs reproduction Issue lacks a minimal reproduction .zip file label Apr 24, 2023
@jawnsy
Copy link
Author

jawnsy commented Apr 25, 2023

Thanks for taking a look, Martin! The title hint was a great one, I think I'm much closer to figuring out what's going on. I think there's actually three separate issues here.

Issue 1: our mkdocs private fork is out of date

Private fork issues?

Our fork is out of date:

image

However the compare view does not show anything:

image

These are the latest commits we have:

image

I'm unsure if this is really a problem, but it stops me from using the info plugin:

ERROR    -  Please upgrade to the latest version.

  When reporting issues, please first upgrade to the latest
  version of Material for MkDocs, as the problem might already
  be fixed in the latest version. This helps reduce duplicate
  efforts and saves us maintainers time.

  Please update from 9.1.7+insiders.4.32.6 to 9.1.8.

  pip install --upgrade --force-reinstall mkdocs-material

Issue 2: strange caching behavior

There is something funny going on with the cache. Once I fix Issue 3, then I can build once, but attempting to rebuild results in an error with the stack trace:

Traceback
Traceback (most recent call last):
  File "/opt/homebrew/Caskroom/miniconda/base/envs/prefect2-dev/bin/mkdocs", line 8, in <module>
    sys.exit(cli())
  File "/opt/homebrew/Caskroom/miniconda/base/envs/prefect2-dev/lib/python3.10/site-packages/click/core.py", line 1130, in __call__
    return self.main(*args, **kwargs)
  File "/opt/homebrew/Caskroom/miniconda/base/envs/prefect2-dev/lib/python3.10/site-packages/click/core.py", line 1055, in main
    rv = self.invoke(ctx)
  File "/opt/homebrew/Caskroom/miniconda/base/envs/prefect2-dev/lib/python3.10/site-packages/click/core.py", line 1657, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "/opt/homebrew/Caskroom/miniconda/base/envs/prefect2-dev/lib/python3.10/site-packages/click/core.py", line 1404, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "/opt/homebrew/Caskroom/miniconda/base/envs/prefect2-dev/lib/python3.10/site-packages/click/core.py", line 760, in invoke
    return __callback(*args, **kwargs)
  File "/opt/homebrew/Caskroom/miniconda/base/envs/prefect2-dev/lib/python3.10/site-packages/mkdocs/__main__.py", line 250, in build_command
    build.build(cfg, dirty=not clean)
  File "/opt/homebrew/Caskroom/miniconda/base/envs/prefect2-dev/lib/python3.10/site-packages/mkdocs/commands/build.py", line 332, in build
    config.plugins.run_event('post_build', config=config)
  File "/opt/homebrew/Caskroom/miniconda/base/envs/prefect2-dev/lib/python3.10/site-packages/mkdocs/plugins.py", line 522, in run_event
    result = method(**kwargs)
  File "/opt/homebrew/Caskroom/miniconda/base/envs/prefect2-dev/lib/python3.10/site-packages/material/plugins/social/plugin.py", line 173, in on_post_build
    promise.result()
  File "/opt/homebrew/Caskroom/miniconda/base/envs/prefect2-dev/lib/python3.10/concurrent/futures/_base.py", line 451, in result
    return self.__get_result()
  File "/opt/homebrew/Caskroom/miniconda/base/envs/prefect2-dev/lib/python3.10/concurrent/futures/_base.py", line 403, in __get_result
    raise self._exception
  File "/opt/homebrew/Caskroom/miniconda/base/envs/prefect2-dev/lib/python3.10/concurrent/futures/thread.py", line 58, in run
    result = self.fn(*self.args, **self.kwargs)
  File "/opt/homebrew/Caskroom/miniconda/base/envs/prefect2-dev/lib/python3.10/site-packages/material/plugins/social/plugin.py", line 180, in _cache_image
    image = render_function()
  File "/opt/homebrew/Caskroom/miniconda/base/envs/prefect2-dev/lib/python3.10/site-packages/material/plugins/social/plugin.py", line 160, in <lambda>
    render_function = lambda: self._render_card(site_name, title, description)
  File "/opt/homebrew/Caskroom/miniconda/base/envs/prefect2-dev/lib/python3.10/site-packages/material/plugins/social/plugin.py", line 201, in _render_card
    font = self._get_font("Bold", 36)
  File "/opt/homebrew/Caskroom/miniconda/base/envs/prefect2-dev/lib/python3.10/site-packages/material/plugins/social/plugin.py", line 188, in _get_font
    return ImageFont.truetype(self.font[kind], size)
  File "/opt/homebrew/Caskroom/miniconda/base/envs/prefect2-dev/lib/python3.10/site-packages/material/plugins/social/plugin.py", line 420, in <lambda>
    return defaultdict(lambda: font["Regular"], font)
KeyError: 'Regular'

If I remove .cache and re-try, then things succeed.

Issue 3: dealing with titles that include a list

So this is where your hint came in very handy. We had front matter defined like this:

---
description: Cool description
title:
  - Profiles and Configuration
---

The title being a list is what caused the problem. Once you fix this and re-build, you run into the above caching issue.

Steps to reproduce

  1. Unzip this archive: prefect-repro.zip
  2. Run a build, you'll get something similar to "Output 1" shown below
  3. Fix the index.md front matter (change the title from a list to a string)
  4. Run another build, you'll get something similar to "Output 2" shown below
  5. Remove the .cache directory (rm -rf .cache)
  6. Run another build, you'll get something similar to "Output 3" shown below -- the build is now successful
  7. Run another build, now you'll get an error like "Output 2" again, even if you use --clean

Output 1

I've added some debug print statements to my local build but otherwise the output should be the same:

Expected string or bytes-like object
$ mkdocs build --clean --config-file mkdocs.yml
WARNING  -  The "social" plugin needs the "site_url" configuration option to be defined. It will likely not work correctly.
FONT: Inter
FONT FILES: []
LOADING FONT FROM GOOGLE: Inter
FONT FILES AFTER: ['static/Inter-Thin.ttf', 'static/Inter-ExtraLight.ttf', 'static/Inter-Light.ttf', 'static/Inter-Regular.ttf', 'static/Inter-Medium.ttf', 'static/Inter-SemiBold.ttf', 'static/Inter-Bold.ttf', 'static/Inter-ExtraBold.ttf', 'static/Inter-Black.ttf', 'Inter-VariableFont_slnt,wght.ttf']
FONT: {}
FONT: {'Thin': '.cache/plugin/social/static/Inter-Thin.ttf'}
FONT: {'Thin': '.cache/plugin/social/static/Inter-Thin.ttf', 'ExtraLight': '.cache/plugin/social/static/Inter-ExtraLight.ttf'}
FONT: {'Thin': '.cache/plugin/social/static/Inter-Thin.ttf', 'ExtraLight': '.cache/plugin/social/static/Inter-ExtraLight.ttf', 'Light': '.cache/plugin/social/static/Inter-Light.ttf'}
FONT: {'Thin': '.cache/plugin/social/static/Inter-Thin.ttf', 'ExtraLight': '.cache/plugin/social/static/Inter-ExtraLight.ttf', 'Light': '.cache/plugin/social/static/Inter-Light.ttf', 'Regular': '.cache/plugin/social/static/Inter-Regular.ttf'}
FONT: {'Thin': '.cache/plugin/social/static/Inter-Thin.ttf', 'ExtraLight': '.cache/plugin/social/static/Inter-ExtraLight.ttf', 'Light': '.cache/plugin/social/static/Inter-Light.ttf', 'Regular': '.cache/plugin/social/static/Inter-Regular.ttf', 'Medium': '.cache/plugin/social/static/Inter-Medium.ttf'}
FONT: {'Thin': '.cache/plugin/social/static/Inter-Thin.ttf', 'ExtraLight': '.cache/plugin/social/static/Inter-ExtraLight.ttf', 'Light': '.cache/plugin/social/static/Inter-Light.ttf', 'Regular': '.cache/plugin/social/static/Inter-Regular.ttf', 'Medium': '.cache/plugin/social/static/Inter-Medium.ttf', 'SemiBold': '.cache/plugin/social/static/Inter-SemiBold.ttf'}
FONT: {'Thin': '.cache/plugin/social/static/Inter-Thin.ttf', 'ExtraLight': '.cache/plugin/social/static/Inter-ExtraLight.ttf', 'Light': '.cache/plugin/social/static/Inter-Light.ttf', 'Regular': '.cache/plugin/social/static/Inter-Regular.ttf', 'Medium': '.cache/plugin/social/static/Inter-Medium.ttf', 'SemiBold': '.cache/plugin/social/static/Inter-SemiBold.ttf', 'Bold': '.cache/plugin/social/static/Inter-Bold.ttf'}
FONT: {'Thin': '.cache/plugin/social/static/Inter-Thin.ttf', 'ExtraLight': '.cache/plugin/social/static/Inter-ExtraLight.ttf', 'Light': '.cache/plugin/social/static/Inter-Light.ttf', 'Regular': '.cache/plugin/social/static/Inter-Regular.ttf', 'Medium': '.cache/plugin/social/static/Inter-Medium.ttf', 'SemiBold': '.cache/plugin/social/static/Inter-SemiBold.ttf', 'Bold': '.cache/plugin/social/static/Inter-Bold.ttf', 'ExtraBold': '.cache/plugin/social/static/Inter-ExtraBold.ttf'}
FONT: {'Thin': '.cache/plugin/social/static/Inter-Thin.ttf', 'ExtraLight': '.cache/plugin/social/static/Inter-ExtraLight.ttf', 'Light': '.cache/plugin/social/static/Inter-Light.ttf', 'Regular': '.cache/plugin/social/static/Inter-Regular.ttf', 'Medium': '.cache/plugin/social/static/Inter-Medium.ttf', 'SemiBold': '.cache/plugin/social/static/Inter-SemiBold.ttf', 'Bold': '.cache/plugin/social/static/Inter-Bold.ttf', 'ExtraBold': '.cache/plugin/social/static/Inter-ExtraBold.ttf', 'Black': '.cache/plugin/social/static/Inter-Black.ttf'}
INFO     -  Cleaning site directory
INFO     -  Building documentation to directory: /Users/jawnsy/projects/work/prefect-repro 2/site
RENDER CARD: ['Profiles and Configuration'] - Cool description
TEXT: My Docs
TEXT: ['Profiles and Configuration']
Traceback (most recent call last):
  File "/opt/homebrew/Caskroom/miniconda/base/envs/prefect2-dev/bin/mkdocs", line 8, in <module>
    sys.exit(cli())
  File "/opt/homebrew/Caskroom/miniconda/base/envs/prefect2-dev/lib/python3.10/site-packages/click/core.py", line 1130, in __call__
    return self.main(*args, **kwargs)
  File "/opt/homebrew/Caskroom/miniconda/base/envs/prefect2-dev/lib/python3.10/site-packages/click/core.py", line 1055, in main
    rv = self.invoke(ctx)
  File "/opt/homebrew/Caskroom/miniconda/base/envs/prefect2-dev/lib/python3.10/site-packages/click/core.py", line 1657, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "/opt/homebrew/Caskroom/miniconda/base/envs/prefect2-dev/lib/python3.10/site-packages/click/core.py", line 1404, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "/opt/homebrew/Caskroom/miniconda/base/envs/prefect2-dev/lib/python3.10/site-packages/click/core.py", line 760, in invoke
    return __callback(*args, **kwargs)
  File "/opt/homebrew/Caskroom/miniconda/base/envs/prefect2-dev/lib/python3.10/site-packages/mkdocs/__main__.py", line 250, in build_command
    build.build(cfg, dirty=not clean)
  File "/opt/homebrew/Caskroom/miniconda/base/envs/prefect2-dev/lib/python3.10/site-packages/mkdocs/commands/build.py", line 332, in build
    config.plugins.run_event('post_build', config=config)
  File "/opt/homebrew/Caskroom/miniconda/base/envs/prefect2-dev/lib/python3.10/site-packages/mkdocs/plugins.py", line 522, in run_event
    result = method(**kwargs)
  File "/opt/homebrew/Caskroom/miniconda/base/envs/prefect2-dev/lib/python3.10/site-packages/material/plugins/social/plugin.py", line 173, in on_post_build
    promise.result()
  File "/opt/homebrew/Caskroom/miniconda/base/envs/prefect2-dev/lib/python3.10/concurrent/futures/_base.py", line 451, in result
    return self.__get_result()
  File "/opt/homebrew/Caskroom/miniconda/base/envs/prefect2-dev/lib/python3.10/concurrent/futures/_base.py", line 403, in __get_result
    raise self._exception
  File "/opt/homebrew/Caskroom/miniconda/base/envs/prefect2-dev/lib/python3.10/concurrent/futures/thread.py", line 58, in run
    result = self.fn(*self.args, **self.kwargs)
  File "/opt/homebrew/Caskroom/miniconda/base/envs/prefect2-dev/lib/python3.10/site-packages/material/plugins/social/plugin.py", line 180, in _cache_image
    image = render_function()
  File "/opt/homebrew/Caskroom/miniconda/base/envs/prefect2-dev/lib/python3.10/site-packages/material/plugins/social/plugin.py", line 160, in <lambda>
    render_function = lambda: self._render_card(site_name, title, description)
  File "/opt/homebrew/Caskroom/miniconda/base/envs/prefect2-dev/lib/python3.10/site-packages/material/plugins/social/plugin.py", line 210, in _render_card
    self._render_text((826, 328), font, title, 3, 30),
  File "/opt/homebrew/Caskroom/miniconda/base/envs/prefect2-dev/lib/python3.10/site-packages/material/plugins/social/plugin.py", line 245, in _render_text
    text = re.sub(r"(<[^>]+>)", "", text)
  File "/opt/homebrew/Caskroom/miniconda/base/envs/prefect2-dev/lib/python3.10/re.py", line 209, in sub
    return _compile(pattern, flags).sub(repl, string, count)
TypeError: expected string or bytes-like object

Output 2: KeyError['Regular']

For some reason, when checking the cache, the social plugin is only detecting Inter-VariableFont_slnt,wght.ttf

KeyError: 'Regular'
$ mkdocs build --clean --config-file mkdocs.yml
WARNING  -  The "social" plugin needs the "site_url" configuration option to be defined. It will likely not work correctly.
FONT: Inter
FONT FILES: ['Inter-VariableFont_slnt,wght.ttf', 'static']
FONT FILES AFTER: ['Inter-VariableFont_slnt,wght.ttf']
FONT: {}
INFO     -  Cleaning site directory
INFO     -  Building documentation to directory: /Users/jawnsy/projects/work/prefect-repro 2/site
RENDER CARD: ['Profiles and Configuration'] - Cool description
Traceback (most recent call last):
  File "/opt/homebrew/Caskroom/miniconda/base/envs/prefect2-dev/bin/mkdocs", line 8, in <module>
    sys.exit(cli())
  File "/opt/homebrew/Caskroom/miniconda/base/envs/prefect2-dev/lib/python3.10/site-packages/click/core.py", line 1130, in __call__
    return self.main(*args, **kwargs)
  File "/opt/homebrew/Caskroom/miniconda/base/envs/prefect2-dev/lib/python3.10/site-packages/click/core.py", line 1055, in main
    rv = self.invoke(ctx)
  File "/opt/homebrew/Caskroom/miniconda/base/envs/prefect2-dev/lib/python3.10/site-packages/click/core.py", line 1657, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "/opt/homebrew/Caskroom/miniconda/base/envs/prefect2-dev/lib/python3.10/site-packages/click/core.py", line 1404, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "/opt/homebrew/Caskroom/miniconda/base/envs/prefect2-dev/lib/python3.10/site-packages/click/core.py", line 760, in invoke
    return __callback(*args, **kwargs)
  File "/opt/homebrew/Caskroom/miniconda/base/envs/prefect2-dev/lib/python3.10/site-packages/mkdocs/__main__.py", line 250, in build_command
    build.build(cfg, dirty=not clean)
  File "/opt/homebrew/Caskroom/miniconda/base/envs/prefect2-dev/lib/python3.10/site-packages/mkdocs/commands/build.py", line 332, in build
    config.plugins.run_event('post_build', config=config)
  File "/opt/homebrew/Caskroom/miniconda/base/envs/prefect2-dev/lib/python3.10/site-packages/mkdocs/plugins.py", line 522, in run_event
    result = method(**kwargs)
  File "/opt/homebrew/Caskroom/miniconda/base/envs/prefect2-dev/lib/python3.10/site-packages/material/plugins/social/plugin.py", line 173, in on_post_build
    promise.result()
  File "/opt/homebrew/Caskroom/miniconda/base/envs/prefect2-dev/lib/python3.10/concurrent/futures/_base.py", line 451, in result
    return self.__get_result()
  File "/opt/homebrew/Caskroom/miniconda/base/envs/prefect2-dev/lib/python3.10/concurrent/futures/_base.py", line 403, in __get_result
    raise self._exception
  File "/opt/homebrew/Caskroom/miniconda/base/envs/prefect2-dev/lib/python3.10/concurrent/futures/thread.py", line 58, in run
    result = self.fn(*self.args, **self.kwargs)
  File "/opt/homebrew/Caskroom/miniconda/base/envs/prefect2-dev/lib/python3.10/site-packages/material/plugins/social/plugin.py", line 180, in _cache_image
    image = render_function()
  File "/opt/homebrew/Caskroom/miniconda/base/envs/prefect2-dev/lib/python3.10/site-packages/material/plugins/social/plugin.py", line 160, in <lambda>
    render_function = lambda: self._render_card(site_name, title, description)
  File "/opt/homebrew/Caskroom/miniconda/base/envs/prefect2-dev/lib/python3.10/site-packages/material/plugins/social/plugin.py", line 201, in _render_card
    font = self._get_font("Bold", 36)
  File "/opt/homebrew/Caskroom/miniconda/base/envs/prefect2-dev/lib/python3.10/site-packages/material/plugins/social/plugin.py", line 188, in _get_font
    return ImageFont.truetype(self.font[kind], size)
  File "/opt/homebrew/Caskroom/miniconda/base/envs/prefect2-dev/lib/python3.10/site-packages/material/plugins/social/plugin.py", line 420, in <lambda>
    return defaultdict(lambda: font["Regular"], font)
KeyError: 'Regular'

It may have something to do with the folder hierarchy:

.
├── .cache
│   └── plugin
│       └── social
│           ├── Inter-VariableFont_slnt,wght.ttf
│           ├── f91df300b8861983814686d5321985f8.png
│           └── static
│               ├── Inter-Black.ttf
│               ├── Inter-Bold.ttf
│               ├── Inter-ExtraBold.ttf
│               ├── Inter-ExtraLight.ttf
│               ├── Inter-Light.ttf
│               ├── Inter-Medium.ttf
│               ├── Inter-Regular.ttf
│               ├── Inter-SemiBold.ttf
│               └── Inter-Thin.ttf

The Inter-VariableFont_slnt,wght.ttf is at the top level, but the other variants are in the static subdirectory

Output 3: Successful build

Successful build after clearing .cache
$ mkdocs build --clean --config-file mkdocs.yml
WARNING  -  The "social" plugin needs the "site_url" configuration option to be defined. It will likely not work correctly.
FONT: Inter
FONT FILES: []
LOADING FONT FROM GOOGLE: Inter
FONT FILES AFTER: ['static/Inter-Thin.ttf', 'static/Inter-ExtraLight.ttf', 'static/Inter-Light.ttf', 'static/Inter-Regular.ttf', 'static/Inter-Medium.ttf', 'static/Inter-SemiBold.ttf', 'static/Inter-Bold.ttf', 'static/Inter-ExtraBold.ttf', 'static/Inter-Black.ttf', 'Inter-VariableFont_slnt,wght.ttf']
FONT: {}
FONT: {'Thin': '.cache/plugin/social/static/Inter-Thin.ttf'}
FONT: {'Thin': '.cache/plugin/social/static/Inter-Thin.ttf', 'ExtraLight': '.cache/plugin/social/static/Inter-ExtraLight.ttf'}
FONT: {'Thin': '.cache/plugin/social/static/Inter-Thin.ttf', 'ExtraLight': '.cache/plugin/social/static/Inter-ExtraLight.ttf', 'Light': '.cache/plugin/social/static/Inter-Light.ttf'}
FONT: {'Thin': '.cache/plugin/social/static/Inter-Thin.ttf', 'ExtraLight': '.cache/plugin/social/static/Inter-ExtraLight.ttf', 'Light': '.cache/plugin/social/static/Inter-Light.ttf', 'Regular': '.cache/plugin/social/static/Inter-Regular.ttf'}
FONT: {'Thin': '.cache/plugin/social/static/Inter-Thin.ttf', 'ExtraLight': '.cache/plugin/social/static/Inter-ExtraLight.ttf', 'Light': '.cache/plugin/social/static/Inter-Light.ttf', 'Regular': '.cache/plugin/social/static/Inter-Regular.ttf', 'Medium': '.cache/plugin/social/static/Inter-Medium.ttf'}
FONT: {'Thin': '.cache/plugin/social/static/Inter-Thin.ttf', 'ExtraLight': '.cache/plugin/social/static/Inter-ExtraLight.ttf', 'Light': '.cache/plugin/social/static/Inter-Light.ttf', 'Regular': '.cache/plugin/social/static/Inter-Regular.ttf', 'Medium': '.cache/plugin/social/static/Inter-Medium.ttf', 'SemiBold': '.cache/plugin/social/static/Inter-SemiBold.ttf'}
FONT: {'Thin': '.cache/plugin/social/static/Inter-Thin.ttf', 'ExtraLight': '.cache/plugin/social/static/Inter-ExtraLight.ttf', 'Light': '.cache/plugin/social/static/Inter-Light.ttf', 'Regular': '.cache/plugin/social/static/Inter-Regular.ttf', 'Medium': '.cache/plugin/social/static/Inter-Medium.ttf', 'SemiBold': '.cache/plugin/social/static/Inter-SemiBold.ttf', 'Bold': '.cache/plugin/social/static/Inter-Bold.ttf'}
FONT: {'Thin': '.cache/plugin/social/static/Inter-Thin.ttf', 'ExtraLight': '.cache/plugin/social/static/Inter-ExtraLight.ttf', 'Light': '.cache/plugin/social/static/Inter-Light.ttf', 'Regular': '.cache/plugin/social/static/Inter-Regular.ttf', 'Medium': '.cache/plugin/social/static/Inter-Medium.ttf', 'SemiBold': '.cache/plugin/social/static/Inter-SemiBold.ttf', 'Bold': '.cache/plugin/social/static/Inter-Bold.ttf', 'ExtraBold': '.cache/plugin/social/static/Inter-ExtraBold.ttf'}
FONT: {'Thin': '.cache/plugin/social/static/Inter-Thin.ttf', 'ExtraLight': '.cache/plugin/social/static/Inter-ExtraLight.ttf', 'Light': '.cache/plugin/social/static/Inter-Light.ttf', 'Regular': '.cache/plugin/social/static/Inter-Regular.ttf', 'Medium': '.cache/plugin/social/static/Inter-Medium.ttf', 'SemiBold': '.cache/plugin/social/static/Inter-SemiBold.ttf', 'Bold': '.cache/plugin/social/static/Inter-Bold.ttf', 'ExtraBold': '.cache/plugin/social/static/Inter-ExtraBold.ttf', 'Black': '.cache/plugin/social/static/Inter-Black.ttf'}
INFO     -  Cleaning site directory
INFO     -  Building documentation to directory: /Users/jawnsy/projects/work/prefect-repro 2/site
RENDER CARD: Profiles and Configuration - Cool description
TEXT: My Docs
TEXT: Profiles and Configuration
TEXT: Cool description
INFO     -  Documentation built in 1.57 seconds

Edit: redacted source code.

@squidfunk
Copy link
Owner

squidfunk commented Apr 25, 2023

Thanks for providing additional details! One thing that is important: you shared potentially private source code (the patched plugin.py). This is in violation with our fair use policy, which states that when using Insiders you should not share the source code. In fact, it counteracts our efforts in making this project sustainable 😉 For the social plugin, this is not a big deal, because it is currently the same in the community edition and Insiders, so no worries, but please keep this in mind when sharing original source code in future bug reports.

I'll investigate asap.

@jawnsy
Copy link
Author

jawnsy commented Apr 25, 2023

I apologize for sharing the social plugin code, I wasn't thinking. I appreciate your editing it out, and I'll keep that in mind for the future 😄 Thanks for looking into this, Martin!

@squidfunk squidfunk added needs investigation Issue must be investigated by the maintainers and removed needs reproduction Issue lacks a minimal reproduction .zip file labels Apr 28, 2023
@squidfunk
Copy link
Owner

Okay, so finally found some time to investigate.

Problem 1: Private fork – I'm not sure why no changes are shown, but it might be related to deleted files in the upstream repository. At some point, we restructured our actions, so maybe you have files in the repository that are not contained in upstream. A good idea might be to do the merge locally.

Problem 2: Cache behavior – this is related to the social plugin only checking the uppermost directory for fonts in the second run (files have been downloaded before). I've fixed this in cb48549 by using a glob. However, I consider this a bandaid. We're actively working on improving the social plugin, making it more flexible and resilient in future versions. For the time being, the mentioned commit fixes the issue.

@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 Apr 28, 2023
@squidfunk
Copy link
Owner

9.1.9 is out, including the changes referenced in this issue! 🚀

@squidfunk
Copy link
Owner

The new social plugin is out, and it manages fonts in a more flexible and stable way, not relying on directories or naming of files. This means, it doesn't suffer from the problems reported here.

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

2 participants