getpelican / pelican-plugins

Collection of plugins for the Pelican static site generator
Other
1.38k stars 849 forks source link

AttributeError: module 'pelican_youtube' has no attribute 'register' #645

Open Nagasaki45 opened 8 years ago

Nagasaki45 commented 8 years ago

I'm unable to add the pelican_youtube plugin to pelicanconf.py. I'm getting the following traceback when trying to build the site:

Traceback (most recent call last):
  File "/home/nagasaki45/miniconda3/envs/pelican-check/bin/pelican", line 11, in <module>
    sys.exit(main())
  File "/home/nagasaki45/miniconda3/envs/pelican-check/lib/python3.5/site-packages/pelican/__init__.py", line 386, in main
    pelican, settings = get_instance(args)
  File "/home/nagasaki45/miniconda3/envs/pelican-check/lib/python3.5/site-packages/pelican/__init__.py", line 380, in get_instance
    return cls(settings), settings
  File "/home/nagasaki45/miniconda3/envs/pelican-check/lib/python3.5/site-packages/pelican/__init__.py", line 57, in __init__
    self.init_plugins()
  File "/home/nagasaki45/miniconda3/envs/pelican-check/lib/python3.5/site-packages/pelican/__init__.py", line 84, in init_plugins
    plugin.register()
AttributeError: module 'pelican_youtube' has no attribute 'register'

Steps to reproduce:

  1. Create a new pelican project with pelican-quickstart.
  2. Clone the pelican-plugins repo (recursively) to ./pelican-plugins.
  3. Add the following lines to pelicanconf.py:
PLUGIN_PATHS = ['pelican-plugins']
PLUGINS = ['pelican_youtube']
  1. Build the site using pelican content -o output -s pelicanconf.py.
  2. Notice the failure above.

The issue is caused by the pelican_youtube folder not being a valid python module (/package) with register attribute.

Nagasaki45 commented 8 years ago

I found a possible fix, which is quite ugly in my opinion. I created a pelican_youtube.py module in the pelican-plugins dir with the following content:

import sys
import os

PLUGINS_DIR = os.path.dirname(__file__)
sys.path.append(os.path.join(PLUGINS_DIR, 'pelican_youtube', 'pelican_youtube'))

from youtube import register
justinmayer commented 6 years ago

@Nagasaki45 / @lincolnfrias: Would you consider submitting a PR to address the issue(s) discussed here?

Nagasaki45 commented 6 years ago

@justinmayer, do you have an idea that is less hacky than the one I suggested above? If not I will send a PR with the hack.

scheunemann commented 5 years ago

The issue is that pelican_youtube follows the structure of python package. I think it should be considered to search in <plugin_name>/<plugin_name> if there is not init in the first level, for now, it can be used with:

PLUGIN_PATHS = ['<path/to/pelican-plugins>/pelican_youtube']
PLUGINS = ['pelican_youtube']

or with installing it via pip install pelican-youtube

PLUGINS = ['pelican_youtube']

I am facing a similar issue and therefore haven't pushed my plugin to the pelican-plugins repo.