Skip to content

Commit

Permalink
Fix tests by making pkgindex loading optional
Browse files Browse the repository at this point in the history
Signed-off-by: Chris Warrick <kwpolska@gmail.com>
  • Loading branch information
Kwpolska committed Jan 8, 2017
1 parent db6798f commit 0e979a4
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 2 deletions.
2 changes: 1 addition & 1 deletion v7/pkgindex/pkgindex.py
Expand Up @@ -6,7 +6,7 @@

from __future__ import unicode_literals

from nikola.plugin_categories import ConfigPlugin
from nikola.plugin_categories import ConfigPlugin


class PackageIndex(ConfigPlugin):
Expand Down
10 changes: 9 additions & 1 deletion v7/pkgindex_compiler/pkgindex_compiler.py
Expand Up @@ -163,14 +163,22 @@ class CompilePackageIndexEntries(PageCompiler):
name = "pkgindex_compiler"
friendly_name = "pkgindex_compiler"
markdown_compiler = None
pi_enabled = False

def set_site(self, site):
"""Set site for the compiler."""
self.config = site.config['PKGINDEX_CONFIG']
# Workaround for plugins site (which includes those plugins, and makes
# tests fail)
if 'PKGINDEX_CONFIG' in self.config:
self.config = site.config['PKGINDEX_CONFIG']
self.pi_enabled = True
super(CompilePackageIndexEntries, self).set_site(site)

def read_metadata(self, post, file_metadata_regexp=None, unslugify_titles=False, lang=None):
"""Read the metadata from a post, and return a metadata dict."""
if not self.pi_enabled:
raise Exception("PKGINDEX_CONFIG not found")

pkg_dir = os.path.split(post.source_path)[0]
top_dir = os.path.dirname(pkg_dir)
metadata = {'slug': os.path.basename(pkg_dir)}
Expand Down
2 changes: 2 additions & 0 deletions v7/pkgindex_scan/pkgindex_scan.py
Expand Up @@ -46,6 +46,8 @@ class PackageIndexScanner(PostScanner):

def scan(self):
"""Scan posts in a package index."""
if 'PKGINDEX_CONFIG' not in self.site.config:
return []
config = self.site.config['PKGINDEX_CONFIG']
plugin_compiler = self.site.get_compiler('sample' + config['extension'])
if not self.site.quiet:
Expand Down
2 changes: 2 additions & 0 deletions v7/pkgindex_zip/pkgindex_zip.py
Expand Up @@ -59,6 +59,8 @@ class PackageIndexZip(Task):
name = "pkgindex_zip"

def gen_tasks(self):
if 'PKGINDEX_CONFIG' not in self.site.config:
return
self.kw = {
'output_folder': self.site.config['OUTPUT_FOLDER'],
'filters': self.site.config['FILTERS'],
Expand Down

0 comments on commit 0e979a4

Please sign in to comment.