plugins icon indicating copy to clipboard operation
plugins copied to clipboard

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

Open CarstenGrohmann opened this issue 2 years ago • 0 comments

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.

https://github.com/getnikola/plugins/blob/126d38c6e850589d8812f7c5c45121c65ef047b1/v8/commonmark/commonmark.py#L34-L37

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

CarstenGrohmann avatar Jan 26 '24 21:01 CarstenGrohmann