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

Error with custom_fences fence_mermaid_custom function #113

Open
GeneralZero opened this issue Nov 20, 2024 · 8 comments
Open

Error with custom_fences fence_mermaid_custom function #113

GeneralZero opened this issue Nov 20, 2024 · 8 comments
Labels
environment Enviropnment issue (libraries, etc.) resolved The question was resolved useful tip Contains a useful tip to solve the issue

Comments

@GeneralZero
Copy link

I am trying to build my documentation with mkdocs. And keep running in to this error.

Looking into the plugin.py script the _activate_custom_loader function doesn't exist.

DEBUG   -  Building page Mobile/Android/Safety Net.md
DEBUG   -  Running `page_context` event from plugin 'material/search'
DEBUG   -  Running `post_page` event from plugin 'mermaid2'
INFO    -  MERMAID2  - Found superfences config: {'preserve_tabs': True, 'custom_fences': [{'name': 'math', 'class': 'arithmatex', 'format': functools.partial(<function _fence_generic_format at 0x7bc1f9c11c60>, tag='div')}, {'name': 'latex', 'class': 'arithmatex', 'format': functools.partial(<function _fence_generic_format at 0x7bc1f9c11c60>, tag='div'), 'kwds': {'mode': 'generic', 'tag': 'pre'}}, {'name': 'mermaid', 'class': 'mermaid', 'format': functools.partial(<function fence_mermaid at 0x7bc1f99d72e0>, custom=True)}, {'name': 'tree', 'class': 'tree', 'format': <function fence_div_format at 0x7bc1f99e4400>}, {'name': 'ghostscript', 'class': 'tree', 'format': <function fence_div_format at 0x7bc1f99e4400>}, {'name': 'table', 'class': 'table', 'format': <function fence_table_format at 0x7bc1f99e6160>}]}
ERROR   -  Error building page 'Mobile/Android/Safety Net.md': 'functools.partial' object has no attribute '__name__'
Traceback (most recent call last):
  File "/usr/local/lib/python3.13/site-packages/mermaid2/plugin.py", line 159, in activate_custom_loader
    return self._activate_custom_loader
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
AttributeError: 'MarkdownMermaidPlugin' object has no attribute '_activate_custom_loader'. Did you mean: 'activate_custom_loader'?

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/local/bin/mkdocs", line 8, in <module>
    sys.exit(cli())
             ~~~^^
  File "/usr/local/lib/python3.13/site-packages/click/core.py", line 1157, in __call__
    return self.main(*args, **kwargs)
           ~~~~~~~~~^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.13/site-packages/click/core.py", line 1078, in main
    rv = self.invoke(ctx)
  File "/usr/local/lib/python3.13/site-packages/click/core.py", line 1688, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
                           ~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^
  File "/usr/local/lib/python3.13/site-packages/click/core.py", line 1434, in invoke
    return ctx.invoke(self.callback, **ctx.params)
           ~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.13/site-packages/click/core.py", line 783, in invoke
    return __callback(*args, **kwargs)
  File "/usr/local/lib/python3.13/site-packages/mkdocs/__main__.py", line 288, in build_command
    build.build(cfg, dirty=not clean)
    ~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.13/site-packages/mkdocs/commands/build.py", line 337, in build
    _build_page(
    ~~~~~~~~~~~^
        file.page, config, doc_files, nav, env, dirty, excluded=file.inclusion.is_excluded()
        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    )
    ^
  File "/usr/local/lib/python3.13/site-packages/mkdocs/commands/build.py", line 226, in _build_page
    output = config.plugins.on_post_page(output, page=page, config=config)
  File "/usr/local/lib/python3.13/site-packages/mkdocs/plugins.py", line 646, in on_post_page
    return self.run_event('post_page', output, page=page, config=config)
           ~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.13/site-packages/mkdocs/plugins.py", line 566, in run_event
    result = method(item, **kwargs)
  File "/usr/local/lib/python3.13/site-packages/mermaid2/plugin.py", line 233, in on_post_page
    if self.activate_custom_loader:
       ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.13/site-packages/mermaid2/plugin.py", line 181, in activate_custom_loader
    if format_fn.__name__ == CUSTOM_FENCE_FN:
       ^^^^^^^^^^^^^^^^^^
AttributeError: 'functools.partial' object has no attribute '__name__'. Did you mean: '__ne__'?
The command '/bin/sh -c PYTHONPATH=/opt/MemoryViewer mkdocs build -v' returned a non-zero code: 1
Copy link

Thank you for your contribution! This is very appreciated.

@fralau
Copy link
Owner

fralau commented Nov 20, 2024

Thanks.

It's perfectly expected that it raises an AttributeError on line 159, on first execution. What's odd is that the except clause doesn't catch it and I can't find fault with the code. 🤔

It might be a side effect of something else? Any specificity on your installation?

It would be useful to have minimal reproducible example (complete with mkdocs.yml).

@property
def activate_custom_loader(self) -> bool:
"""
Predicate: activate the custom loader for superfences?
The rule is to activate:
1. superfences extension is activated
2. it specifies 'fence_mermaid_custom' as
as format function (instead of fence_mermaid)
"""
try:
return self._activate_custom_loader
except AttributeError:
# first call:
# superfences_installed = ('pymdownx.superfences' in
# self.full_config['markdown_extensions'])
# custom_loader = self.config['custom_loader']
# self._activate_custom_loader = (superfences_installed and
# custom_loader)
# return self._activate_custom_loader
self._activate_custom_loader = False
superfences_installed = (SUPERFENCES_EXTENSION in
self.full_config['markdown_extensions'])
if superfences_installed:

@GeneralZero
Copy link
Author

So while trying to make a minimal reproducible example it seems to have fixed itself. The only thing that I changed is purging the docker cache. So that was my solution in case someone runs into the same problem in the future.

@fralau fralau added useful tip Contains a useful tip to solve the issue environment Enviropnment issue (libraries, etc.) resolved The question was resolved labels Nov 21, 2024
@fralau
Copy link
Owner

fralau commented Nov 21, 2024

Thanks for the info! I labelled this issue "useful tip" to keep track of it.

@mbeacom
Copy link

mbeacom commented Nov 22, 2024

@fralau

Encountering the same error while running using the docker workflow with podman.

Dockerfile/Containerfile:

FROM squidfunk/mkdocs-material:9

RUN pip install --no-cache-dir mkdocs-mermaid2-plugin

fairly minimal mkdocs.yml

site_name: "Test Site"
site_description: "A test site."
site_author: "Test author"

theme:
  name: "material"
  features:
    - search.suggest
    - search.highlight
    - search.share
    - navigation.tracking
    - navigation.tabs
    - navigation.path
    - toc.integrate
    - toc.follow

markdown_extensions:
  - toc
  - footnotes
  - codehilite
  - admonition
  - def_list
  - pymdownx.superfences:
      custom_fences:
        - name: mermaid
          class: mermaid
          format: !!python/name:mermaid2.fence_mermaid_custom
          
plugins:
  - search
  - mermaid2

mermaid diagram example

# Model

```mermaid
erDiagram
  THING {
    string id PK
    string thingyId
    string[] stuffs
  }

  THINGY {
    string id PK
    string[] stuffys
  }

  THINGY ||--o{ THING : owns
```

@fralau
Copy link
Owner

fralau commented Nov 23, 2024

Thanks. Still having the same error at mermaid2/plugin.py, line 159?

@GeneralZero
Copy link
Author

Yep now its back and clearing the cache didn't work. So don't know exactly what is happening.

@GeneralZero
Copy link
Author

GeneralZero commented Dec 5, 2024

I think I narrowed it down. Here is my minimum build yaml and the markdown file mermaid2 block. It seems to interact with another superfences plugin pymdownx.arithmatex.

mkdocs.yaml:

site_name: Memory
site_description: Notes I've collected over the years
site_author: GeneralZero

docs_dir: /opt/MemoryViewer/memory

theme:
  name: material
dev_addr: '127.0.0.1:8000'

repo_url: https://github.com/generalzero/
repo_name: Github

use_directory_urls: true

plugins:
  - mermaid2:
      arguments:
         theme: 'dark'


  - pymdownx.superfences:
      preserve_tabs: true
      custom_fences:
        - name: math
          class: arithmatex
          format: !!python/object/apply:pymdownx.arithmatex.arithmatex_fenced_format {which: "generic"}
        - name: latex
          class: arithmatex
          format: !!python/object/apply:pymdownx.arithmatex.arithmatex_fenced_format {which: "generic"}
        - name: mermaid
          class: mermaid
          format: !!python/name:mermaid2.fence_mermaid_custom #fence_mermaid_custom
sequenceDiagram
Client App ->> Google Play Services : SafetyNet Attestation API receives a call from your app. This call includes a nonce.
Google Play Services ->> Google : SafetyNet Attestation service evaluates the runtime environment and requests a signed attestation of the assessment results from Google's servers.
Google ->> Google Play Services : Google's servers send the signed attestation to the SafetyNet Attestation service on the device.
Google Play Services ->> Client App : SafetyNet Attestation service returns this signed attestation to your app.
Client App ->> Client Server : Your app forwards the signed attestation to your server.
Client Server ->> Client App : This server validates the response and uses it for anti-abuse decisions. Your server communicates its findings to your app.
Loading

@GeneralZero GeneralZero reopened this Dec 5, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
environment Enviropnment issue (libraries, etc.) resolved The question was resolved useful tip Contains a useful tip to solve the issue
Projects
None yet
Development

No branches or pull requests

3 participants