Browse Source

teach plugins with dependencies to behave

Deniz Turgut 11 years ago
parent
commit
31ccbde072
86 changed files with 45 additions and 930 deletions
  1. 2 1
      .gitignore
  2. 1 1
      .travis.yml
  3. 4 3
      Contributing.rst
  4. 13 6
      assets/assets.py
  5. 2 6
      assets/test_assets.py
  6. 12 8
      github_activity/github_activity.py
  7. 11 3
      goodreads_activity/goodreads_activity.py
  8. 0 902
      pytestdebug.log
  9. 0 0
      test_data/Readme.rst
  10. 0 0
      test_data/content/2012-11-30_filename-metadata.rst
  11. 0 0
      test_data/content/another_super_article-fr.rst
  12. 0 0
      test_data/content/another_super_article.rst
  13. 0 0
      test_data/content/article2-fr.rst
  14. 0 0
      test_data/content/article2.rst
  15. 0 0
      test_data/content/cat1/article1.rst
  16. 0 0
      test_data/content/cat1/article2.rst
  17. 0 0
      test_data/content/cat1/article3.rst
  18. 0 0
      test_data/content/cat1/markdown-article.md
  19. 0 0
      test_data/content/draft_article.rst
  20. 0 0
      test_data/content/extra/robots.txt
  21. 0 0
      test_data/content/pages/hidden_page.rst
  22. 0 0
      test_data/content/pages/jinja2_template.html
  23. 0 0
      test_data/content/pages/override_url_saveas.rst
  24. 0 0
      test_data/content/pages/test_page.rst
  25. 0 0
      test_data/content/pictures/Fat_Cat.jpg
  26. 0 0
      test_data/content/pictures/Sushi.jpg
  27. 0 0
      test_data/content/pictures/Sushi_Macro.jpg
  28. 0 0
      test_data/content/super_article.rst
  29. 0 0
      test_data/content/unbelievable.rst
  30. 0 0
      test_data/content/unwanted_file
  31. 0 0
      test_data/pelican.conf.py
  32. 0 0
      test_data/themes/notmyidea/static/css/main.css
  33. 0 0
      test_data/themes/notmyidea/static/css/pygment.css
  34. 0 0
      test_data/themes/notmyidea/static/css/reset.css
  35. 0 0
      test_data/themes/notmyidea/static/css/typogrify.css
  36. 0 0
      test_data/themes/notmyidea/static/css/wide.css
  37. 0 0
      test_data/themes/notmyidea/static/images/icons/aboutme.png
  38. 0 0
      test_data/themes/notmyidea/static/images/icons/bitbucket.png
  39. 0 0
      test_data/themes/notmyidea/static/images/icons/delicious.png
  40. 0 0
      test_data/themes/notmyidea/static/images/icons/facebook.png
  41. 0 0
      test_data/themes/notmyidea/static/images/icons/github.png
  42. 0 0
      test_data/themes/notmyidea/static/images/icons/gitorious.png
  43. 0 0
      test_data/themes/notmyidea/static/images/icons/gittip.png
  44. 0 0
      test_data/themes/notmyidea/static/images/icons/google-groups.png
  45. 0 0
      test_data/themes/notmyidea/static/images/icons/google-plus.png
  46. 0 0
      test_data/themes/notmyidea/static/images/icons/hackernews.png
  47. 0 0
      test_data/themes/notmyidea/static/images/icons/lastfm.png
  48. 0 0
      test_data/themes/notmyidea/static/images/icons/linkedin.png
  49. 0 0
      test_data/themes/notmyidea/static/images/icons/reddit.png
  50. 0 0
      test_data/themes/notmyidea/static/images/icons/rss.png
  51. 0 0
      test_data/themes/notmyidea/static/images/icons/slideshare.png
  52. 0 0
      test_data/themes/notmyidea/static/images/icons/speakerdeck.png
  53. 0 0
      test_data/themes/notmyidea/static/images/icons/twitter.png
  54. 0 0
      test_data/themes/notmyidea/static/images/icons/vimeo.png
  55. 0 0
      test_data/themes/notmyidea/static/images/icons/youtube.png
  56. 0 0
      test_data/themes/notmyidea/templates/analytics.html
  57. 0 0
      test_data/themes/notmyidea/templates/archives.html
  58. 0 0
      test_data/themes/notmyidea/templates/article.html
  59. 0 0
      test_data/themes/notmyidea/templates/article_infos.html
  60. 0 0
      test_data/themes/notmyidea/templates/author.html
  61. 0 0
      test_data/themes/notmyidea/templates/authors.html
  62. 0 0
      test_data/themes/notmyidea/templates/base.html
  63. 0 0
      test_data/themes/notmyidea/templates/category.html
  64. 0 0
      test_data/themes/notmyidea/templates/comments.html
  65. 0 0
      test_data/themes/notmyidea/templates/disqus_script.html
  66. 0 0
      test_data/themes/notmyidea/templates/github.html
  67. 0 0
      test_data/themes/notmyidea/templates/index.html
  68. 0 0
      test_data/themes/notmyidea/templates/page.html
  69. 0 0
      test_data/themes/notmyidea/templates/piwik.html
  70. 0 0
      test_data/themes/notmyidea/templates/tag.html
  71. 0 0
      test_data/themes/notmyidea/templates/taglist.html
  72. 0 0
      test_data/themes/notmyidea/templates/translations.html
  73. 0 0
      test_data/themes/notmyidea/templates/twitter.html
  74. 0 0
      test_data/themes/simple/templates/archives.html
  75. 0 0
      test_data/themes/simple/templates/article.html
  76. 0 0
      test_data/themes/simple/templates/author.html
  77. 0 0
      test_data/themes/simple/templates/base.html
  78. 0 0
      test_data/themes/simple/templates/categories.html
  79. 0 0
      test_data/themes/simple/templates/category.html
  80. 0 0
      test_data/themes/simple/templates/gosquared.html
  81. 0 0
      test_data/themes/simple/templates/index.html
  82. 0 0
      test_data/themes/simple/templates/page.html
  83. 0 0
      test_data/themes/simple/templates/pagination.html
  84. 0 0
      test_data/themes/simple/templates/tag.html
  85. 0 0
      test_data/themes/simple/templates/tags.html
  86. 0 0
      test_data/themes/simple/templates/translations.html

+ 2 - 1
.gitignore

@@ -1 +1,2 @@
-*.pyc
+*.pyc
+*.log

+ 1 - 1
.travis.yml

@@ -10,4 +10,4 @@ install:
     - pip install -e git://github.com/getpelican/pelican.git#egg=pelican
     - pip install --use-mirrors Markdown
     - if [[ $TRAVIS_PYTHON_VERSION == '2.7' ]]; then pip install --use-mirrors webassets cssmin; fi
-script: nosetests tests
+script: nosetests

+ 4 - 3
Contributing.rst

@@ -9,7 +9,9 @@ request. Make sure that your plugin follows the structure below::
     my_plugin
        ├──  __init__.py
        ├──  my_plugin.py
+       ├──  test_my_plugin.py
        └──  Readme.rst / Readme.md
+      
 
 ``my_plugin.py`` is the actual plugin implementation. Include a brief
 explanation of what the plugin does as a module docstring. Leave any further
@@ -17,9 +19,8 @@ explanations and usage details to ``Readme`` file.
 
 ``__init__.py`` should contain a single line with ``from .my_plugin import *``.
 
-If you have tests for your plugin, place them in the ``tests`` folder with name
-``test_my_plugin.py``. You can use ``test_data`` folder inside, if you need content 
-or templates in your tests.
+Place tests for your plugin in the same folder with name ``test_my_plugin.py``. 
+You can use ``test_data`` main folder, if you need content or templates in your tests.
 
 **Note:** Plugins in the repository are licensed with *GNU AFFERO GENERAL PUBLIC LICENSE
 Version 3*. By submitting a pull request, you accept to release your 

+ 13 - 6
assets/assets.py

@@ -20,9 +20,14 @@ import os
 import logging
 
 from pelican import signals
-from webassets import Environment
-from webassets.ext.jinja2 import AssetsExtension
+logger = logging.getLogger(__name__)
 
+try:
+    import webassets
+    from webassets import Environment
+    from webassets.ext.jinja2 import AssetsExtension
+except ImportError:
+    webassets = None
 
 def add_jinja2_ext(pelican):
     """Add Webassets to Jinja2 extensions in Pelican settings."""
@@ -41,13 +46,15 @@ def create_assets_env(generator):
         for item in generator.settings['ASSET_CONFIG']:
             generator.env.assets_environment.config[item[0]] = item[1]
 
-    logger = logging.getLogger(__name__)
     if logging.getLevelName(logger.getEffectiveLevel()) == "DEBUG":
         generator.env.assets_environment.debug = True
 
 
 def register():
     """Plugin registration."""
-
-    signals.initialized.connect(add_jinja2_ext)
-    signals.generator_init.connect(create_assets_env)
+    if webassets:
+        signals.initialized.connect(add_jinja2_ext)
+        signals.generator_init.connect(create_assets_env)
+    else:
+        logger.warning('`assets` failed to load dependency `webassets`.'
+                       '`assets` plugin not loaded.')

+ 2 - 6
assets/test_assets.py

@@ -13,10 +13,6 @@ import subprocess
 from pelican import Pelican
 from pelican.settings import read_settings
 
-import pytest
-
-assets = pytest.importorskip("assets")
-
 CUR_DIR = os.path.dirname(__file__)
 THEME_DIR = os.path.join(CUR_DIR, 'test_data')
 CSS_REF = open(os.path.join(THEME_DIR, 'static', 'css',
@@ -62,10 +58,10 @@ class TestWebAssets(unittest.TestCase):
     """Base class for testing webassets."""
 
     def setUp(self, override=None):
-        
+        import assets
         self.temp_path = mkdtemp(prefix='pelicantests.')
         settings = {
-            'PATH': os.path.join(os.path.dirname(CUR_DIR), 'tests', 'content'),
+            'PATH': os.path.join(os.path.dirname(CUR_DIR), 'test_data', 'content'),
             'OUTPUT_PATH': self.temp_path,
             'PLUGINS': [assets],
             'THEME': THEME_DIR,

+ 12 - 8
github_activity/github_activity.py

@@ -11,6 +11,9 @@ A plugin to list your Github Activity
 
 from __future__ import unicode_literals, print_function
 
+import logging
+logger = logging.getLogger(__name__)
+
 from pelican import signals
 
 
@@ -19,12 +22,9 @@ class GitHubActivity():
         A class created to fetch github activity with feedparser
     """
     def __init__(self, generator):
-        try:
-            import feedparser
-            self.activities = feedparser.parse(
-                generator.settings['GITHUB_ACTIVITY_FEED'])
-        except ImportError:
-            raise Exception("Unable to find feedparser")
+        import feedparser
+        self.activities = feedparser.parse(
+            generator.settings['GITHUB_ACTIVITY_FEED'])
 
     def fetch(self):
         """
@@ -63,5 +63,9 @@ def register():
     """
         Plugin registration
     """
-    signals.article_generator_init.connect(feed_parser_initialization)
-    signals.article_generate_context.connect(fetch_github_activity)
+    try:
+        signals.article_generator_init.connect(feed_parser_initialization)
+        signals.article_generate_context.connect(fetch_github_activity)
+    except ImportError:
+        logger.warning('`github_activity` failed to load dependency `feedparser`.'
+                       '`github_activity` plugin not loaded.')

+ 11 - 3
goodreads_activity/goodreads_activity.py

@@ -9,12 +9,16 @@ Copyright (c) Talha Mansoor
 """
 
 from __future__ import unicode_literals
+
+import logging
+logger = logging.getLogger(__name__)
+
 from pelican import signals
-import feedparser
 
 
 class GoodreadsActivity():
     def __init__(self, generator):
+        import feedparser
         self.activities = feedparser.parse(
             generator.settings['GOODREADS_ACTIVITY_FEED'])
 
@@ -51,5 +55,9 @@ def initialize_feedparser(generator):
 
 
 def register():
-    signals.article_generator_init.connect(initialize_feedparser)
-    signals.article_generate_context.connect(fetch_goodreads_activity)
+    try:
+        signals.article_generator_init.connect(initialize_feedparser)
+        signals.article_generate_context.connect(fetch_goodreads_activity)
+    except ImportError:
+        logger.warning('`goodreads_activity` failed to load dependency `feedparser`.'
+                       '`goodreads_activity` plugin not loaded.')

File diff suppressed because it is too large
+ 0 - 902
pytestdebug.log


tests/Readme.rst → test_data/Readme.rst


tests/content/2012-11-30_filename-metadata.rst → test_data/content/2012-11-30_filename-metadata.rst


tests/content/another_super_article-fr.rst → test_data/content/another_super_article-fr.rst


tests/content/another_super_article.rst → test_data/content/another_super_article.rst


tests/content/article2-fr.rst → test_data/content/article2-fr.rst


tests/content/article2.rst → test_data/content/article2.rst


tests/content/cat1/article1.rst → test_data/content/cat1/article1.rst


tests/content/cat1/article2.rst → test_data/content/cat1/article2.rst


tests/content/cat1/article3.rst → test_data/content/cat1/article3.rst


tests/content/cat1/markdown-article.md → test_data/content/cat1/markdown-article.md


tests/content/draft_article.rst → test_data/content/draft_article.rst


tests/content/extra/robots.txt → test_data/content/extra/robots.txt


tests/content/pages/hidden_page.rst → test_data/content/pages/hidden_page.rst


tests/content/pages/jinja2_template.html → test_data/content/pages/jinja2_template.html


tests/content/pages/override_url_saveas.rst → test_data/content/pages/override_url_saveas.rst


tests/content/pages/test_page.rst → test_data/content/pages/test_page.rst


tests/content/pictures/Fat_Cat.jpg → test_data/content/pictures/Fat_Cat.jpg


tests/content/pictures/Sushi.jpg → test_data/content/pictures/Sushi.jpg


tests/content/pictures/Sushi_Macro.jpg → test_data/content/pictures/Sushi_Macro.jpg


tests/content/super_article.rst → test_data/content/super_article.rst


tests/content/unbelievable.rst → test_data/content/unbelievable.rst


tests/content/unwanted_file → test_data/content/unwanted_file


tests/pelican.conf.py → test_data/pelican.conf.py


tests/themes/notmyidea/static/css/main.css → test_data/themes/notmyidea/static/css/main.css


tests/themes/notmyidea/static/css/pygment.css → test_data/themes/notmyidea/static/css/pygment.css


tests/themes/notmyidea/static/css/reset.css → test_data/themes/notmyidea/static/css/reset.css


tests/themes/notmyidea/static/css/typogrify.css → test_data/themes/notmyidea/static/css/typogrify.css


tests/themes/notmyidea/static/css/wide.css → test_data/themes/notmyidea/static/css/wide.css


tests/themes/notmyidea/static/images/icons/aboutme.png → test_data/themes/notmyidea/static/images/icons/aboutme.png


tests/themes/notmyidea/static/images/icons/bitbucket.png → test_data/themes/notmyidea/static/images/icons/bitbucket.png


tests/themes/notmyidea/static/images/icons/delicious.png → test_data/themes/notmyidea/static/images/icons/delicious.png


tests/themes/notmyidea/static/images/icons/facebook.png → test_data/themes/notmyidea/static/images/icons/facebook.png


tests/themes/notmyidea/static/images/icons/github.png → test_data/themes/notmyidea/static/images/icons/github.png


tests/themes/notmyidea/static/images/icons/gitorious.png → test_data/themes/notmyidea/static/images/icons/gitorious.png


tests/themes/notmyidea/static/images/icons/gittip.png → test_data/themes/notmyidea/static/images/icons/gittip.png


tests/themes/notmyidea/static/images/icons/google-groups.png → test_data/themes/notmyidea/static/images/icons/google-groups.png


tests/themes/notmyidea/static/images/icons/google-plus.png → test_data/themes/notmyidea/static/images/icons/google-plus.png


tests/themes/notmyidea/static/images/icons/hackernews.png → test_data/themes/notmyidea/static/images/icons/hackernews.png


tests/themes/notmyidea/static/images/icons/lastfm.png → test_data/themes/notmyidea/static/images/icons/lastfm.png


tests/themes/notmyidea/static/images/icons/linkedin.png → test_data/themes/notmyidea/static/images/icons/linkedin.png


tests/themes/notmyidea/static/images/icons/reddit.png → test_data/themes/notmyidea/static/images/icons/reddit.png


tests/themes/notmyidea/static/images/icons/rss.png → test_data/themes/notmyidea/static/images/icons/rss.png


tests/themes/notmyidea/static/images/icons/slideshare.png → test_data/themes/notmyidea/static/images/icons/slideshare.png


tests/themes/notmyidea/static/images/icons/speakerdeck.png → test_data/themes/notmyidea/static/images/icons/speakerdeck.png


tests/themes/notmyidea/static/images/icons/twitter.png → test_data/themes/notmyidea/static/images/icons/twitter.png


tests/themes/notmyidea/static/images/icons/vimeo.png → test_data/themes/notmyidea/static/images/icons/vimeo.png


tests/themes/notmyidea/static/images/icons/youtube.png → test_data/themes/notmyidea/static/images/icons/youtube.png


tests/themes/notmyidea/templates/analytics.html → test_data/themes/notmyidea/templates/analytics.html


tests/themes/notmyidea/templates/archives.html → test_data/themes/notmyidea/templates/archives.html


tests/themes/notmyidea/templates/article.html → test_data/themes/notmyidea/templates/article.html


tests/themes/notmyidea/templates/article_infos.html → test_data/themes/notmyidea/templates/article_infos.html


tests/themes/notmyidea/templates/author.html → test_data/themes/notmyidea/templates/author.html


tests/themes/notmyidea/templates/authors.html → test_data/themes/notmyidea/templates/authors.html


tests/themes/notmyidea/templates/base.html → test_data/themes/notmyidea/templates/base.html


tests/themes/notmyidea/templates/category.html → test_data/themes/notmyidea/templates/category.html


tests/themes/notmyidea/templates/comments.html → test_data/themes/notmyidea/templates/comments.html


tests/themes/notmyidea/templates/disqus_script.html → test_data/themes/notmyidea/templates/disqus_script.html


tests/themes/notmyidea/templates/github.html → test_data/themes/notmyidea/templates/github.html


tests/themes/notmyidea/templates/index.html → test_data/themes/notmyidea/templates/index.html


tests/themes/notmyidea/templates/page.html → test_data/themes/notmyidea/templates/page.html


tests/themes/notmyidea/templates/piwik.html → test_data/themes/notmyidea/templates/piwik.html


tests/themes/notmyidea/templates/tag.html → test_data/themes/notmyidea/templates/tag.html


tests/themes/notmyidea/templates/taglist.html → test_data/themes/notmyidea/templates/taglist.html


tests/themes/notmyidea/templates/translations.html → test_data/themes/notmyidea/templates/translations.html


tests/themes/notmyidea/templates/twitter.html → test_data/themes/notmyidea/templates/twitter.html


tests/themes/simple/templates/archives.html → test_data/themes/simple/templates/archives.html


tests/themes/simple/templates/article.html → test_data/themes/simple/templates/article.html


tests/themes/simple/templates/author.html → test_data/themes/simple/templates/author.html


tests/themes/simple/templates/base.html → test_data/themes/simple/templates/base.html


tests/themes/simple/templates/categories.html → test_data/themes/simple/templates/categories.html


tests/themes/simple/templates/category.html → test_data/themes/simple/templates/category.html


tests/themes/simple/templates/gosquared.html → test_data/themes/simple/templates/gosquared.html


tests/themes/simple/templates/index.html → test_data/themes/simple/templates/index.html


tests/themes/simple/templates/page.html → test_data/themes/simple/templates/page.html


tests/themes/simple/templates/pagination.html → test_data/themes/simple/templates/pagination.html


tests/themes/simple/templates/tag.html → test_data/themes/simple/templates/tag.html


tests/themes/simple/templates/tags.html → test_data/themes/simple/templates/tags.html


tests/themes/simple/templates/translations.html → test_data/themes/simple/templates/translations.html