Skip to content

[commonmark] AttributeError: module 'commonmark' has no attribute 'Parser' #434

@CarstenGrohmann

Description

@CarstenGrohmann

Hi,

After updating my Nikola installation to v8.3.0 the locally installed commonmark plugin fails.

$ nikola --version
[2024-01-26 22:06:19] ERROR: PluginManager: Plugin commonmark from /.../carstengrohmann.de/plugins/commonmark/commonmark.plugin (/.../carstengrohmann.de/plugins/commonmark/commonmark.py) threw an exception while creating the instance
Traceback (most recent call last):
  File "/usr/lib/python3.11/site-packages/nikola/plugin_manager.py", line 215, in load_plugins
    plugin_object = plugin_class()
                    ^^^^^^^^^^^^^^
  File "/.../carstengrohmann.de/plugins/commonmark/commonmark.py", line 57, in __init__
    self.parser = commonmark.Parser()
                  ^^^^^^^^^^^^^^^^^
AttributeError: module 'commonmark' has no attribute 'Parser'
[2024-01-26 22:06:19] WARNING: PluginManager: Some plugins failed to load. Please review the above warning messages.
[2024-01-26 22:06:19] WARNING: PluginManager: You may need to update some plugins (from plugins.getnikola.com) or to fix their .plugin files.
[2024-01-26 22:06:19] WARNING: PluginManager: Waiting 2 seconds before continuing.
Nikola v8.3.0

I can well imagine that with the new Plugin Manager the search path of the modules has changed and the plugin imports itself.

try:
import commonmark
except ImportError:
commonmark = None # NOQA

This would explain the difference between the following tests with import commonmark && commonmark.Parser, if the command is executed once in the plugin directory and once outside.

$ pwd
/.../carstengrohmann.de/plugins/commonmark

$ ll
insgesamt 24
-rw-r--r-- 1 carsten carsten 1452 19. Okt 22:46 README.md
drwxr-xr-x 2 carsten carsten   40 20. Okt 20:28 __pycache__
-rw-r--r-- 1 carsten carsten  277 19. Okt 22:46 commonmark.plugin
-rw-r--r-- 1 carsten carsten 4184 19. Okt 22:46 commonmark.py
-rw-r--r-- 1 carsten carsten  495 19. Okt 22:46 conf.py.sample
-rw-r--r-- 1 carsten carsten   18 19. Okt 22:46 requirements.txt

$ python
Python 3.11.6 (main, Nov 14 2023, 09:36:21) [GCC 13.2.1 20230801] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import commonmark
>>> commonmark.Parser
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
AttributeError: module 'commonmark' has no attribute 'Parser'
$ pwd
/.../carstengrohmann.de/plugins

$ ll
insgesamt 4
-rw-r--r-- 1 carsten carsten  25 25. Mai 2014  __init__.py
drwxr-xr-x 3 carsten carsten 134 20. Okt 20:28 commonmark
drwxr-xr-x 3 carsten carsten  18 25. Mai 2014  compile

$ python
Python 3.11.6 (main, Nov 14 2023, 09:36:21) [GCC 13.2.1 20230801] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import commonmark
>>> commonmark.Parser
<class 'commonmark.blocks.Parser'>

What do you think about this issue?

Regards,
Carsten

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions