Skip to content
Permalink
Browse files
Make print_compilers simpler
  • Loading branch information
ralsina committed Aug 15, 2015
1 parent 473fd1b commit b36cca263253541a0fb6f3b147d8e7276140aceb
Showing with 47 additions and 30 deletions.
  1. +5 −3 nikola/nikola.py
  2. +42 −27 nikola/plugins/command/new_post.py
@@ -735,20 +735,22 @@ def __init__(self, **config):
# And put them in "bad compilers"
pp_exts = set([os.path.splitext(x[0])[1] for x in self.config['post_pages']])
self.config['COMPILERS'] = {}
self.disabled_compilers = set([])
self.disabled_compilers = {}
bad_compilers = set([])
for k, v in compilers.items():
if pp_exts.intersection(v):
self.config['COMPILERS'][k] = sorted(list(v))
else:
self.disabled_compilers.add(k)
bad_compilers.add(k)

self.plugin_manager.getPluginLocator().setPluginPlaces(places)
self.plugin_manager.locatePlugins()
bad_candidates = set([])
for p in self.plugin_manager._candidates:
# Remove compilers we don't use
if p[-1].name in self.disabled_compilers:
if p[-1].name in bad_compilers:
bad_candidates.add(p)
self.disabled_compilers[p[-1].name] = p
utils.LOGGER.debug('Not loading unneeded compiler {}', p[-1].name)
# Remove blacklisted plugins
if p[-1].name in self.config['DISABLED_PLUGINS']:
@@ -408,7 +408,6 @@ def filter_post_pages(self, compiler, is_post):
compilers = self.site.config['COMPILERS']
post_pages = self.site.config['post_pages']
compiler_objs = self.site.compilers
compilers_raw = self.site.config['_COMPILERS_RAW']

# First throw away all the post_pages with the wrong is_post
filtered = [entry for entry in post_pages if entry[3] == is_post]
@@ -431,9 +430,9 @@ def filter_post_pages(self, compiler, is_post):
if not filtered:
type_name = "post" if is_post else "page"
LOGGER.error("Can't find a way, using your configuration, to create "
"a {0} in format {1}. You may want to tweak "
"COMPILERS or {2}S in conf.py".format(
type_name, compiler, type_name.upper()))
"a {0} in format {1}. You may want to tweak "
"COMPILERS or {2}S in conf.py".format(
type_name, compiler, type_name.upper()))
LOGGER.info("Read more: {0}".format(COMPILERS_DOC_LINK))

return False
@@ -451,33 +450,49 @@ def print_compilers(self):
# Entries are in format: (name, extensions, used_in_post_pages)

compilers_raw = self.site.config['_COMPILERS_RAW']
post_pages = self.site.config['post_pages']
compiler_objs = self.site.compilers

parsed_compilers = {'used': [], 'unused': [], 'disabled': []}

for compiler_name, compiler_obj in compiler_objs.items():
fname = compiler_obj.friendly_name or compiler_name
if compiler_name not in compilers_raw:
parsed_compilers['disabled'].append((compiler_name, fname, (), False))
used_compilers = []
unused_compilers = []
disabled_compilers = []

for name, plugin in self.site.compilers.items():
if name in compilers_raw:
used_compilers.append([
name,
plugin.friendly_name or name,
compilers_raw[name],
True
])
else:
disabled_compilers.append([
name,
plugin.friendly_name or name,
(),
False
])

for name in self.site.disabled_compilers:
if name in compilers_raw:
unused_compilers.append([
name,
name,
compilers_raw[name],
False
])
else:
# stolen from filter_post_pages
extensions = compilers_raw[compiler_name]
filtered = [entry for entry in post_pages if any(
[ext in entry[0] for ext in extensions])]
if filtered:
parsed_compilers['used'].append((compiler_name, fname, extensions, True))
else:
parsed_compilers['unused'].append((compiler_name, fname, extensions, False))

# Sort compilers alphabetically by name, just so it’s prettier (and
# deterministic)
parsed_compilers['used'].sort(key=operator.itemgetter(0))
parsed_compilers['unused'].sort(key=operator.itemgetter(0))
parsed_compilers['disabled'].sort(key=operator.itemgetter(0))
disabled_compilers.append([
name,
name,
(),
False
])

used_compilers.sort(key=operator.itemgetter(0))
unused_compilers.sort(key=operator.itemgetter(0))
disabled_compilers.sort(key=operator.itemgetter(0))

# We also group the compilers by status for readability.
parsed_list = parsed_compilers['used'] + parsed_compilers['unused'] + parsed_compilers['disabled']
parsed_list = used_compilers + unused_compilers + disabled_compilers

print("Available input formats:\n")

0 comments on commit b36cca2

Please sign in to comment.