pep8
This commit is contained in:
@@ -32,16 +32,16 @@ except ImportError:
|
||||
|
||||
|
||||
# Global vars
|
||||
_MAIN_SETTINGS = None # settings dict of the main Pelican instance
|
||||
_MAIN_LANG = None # lang of the main Pelican instance
|
||||
_MAIN_SITEURL = None # siteurl of the main Pelican instance
|
||||
_MAIN_STATIC_FILES = None # list of Static instances the main Pelican instance
|
||||
_SUBSITE_QUEUE = {} # map: lang -> settings overrides
|
||||
_SITE_DB = OrderedDict() # OrderedDict: lang -> siteurl
|
||||
_MAIN_SETTINGS = None # settings dict of the main Pelican instance
|
||||
_MAIN_LANG = None # lang of the main Pelican instance
|
||||
_MAIN_SITEURL = None # siteurl of the main Pelican instance
|
||||
_MAIN_STATIC_FILES = None # list of Static instances the main Pelican
|
||||
_SUBSITE_QUEUE = {} # map: lang -> settings overrides
|
||||
_SITE_DB = OrderedDict() # OrderedDict: lang -> siteurl
|
||||
_SITES_RELPATH_DB = {} # map: (lang, base_lang) -> relpath
|
||||
# map: generator -> list of removed contents that need interlinking
|
||||
_GENERATOR_DB = {}
|
||||
_NATIVE_CONTENT_URL_DB = {} # map: source_path -> content in its native lang
|
||||
_NATIVE_CONTENT_URL_DB = {} # map: source_path -> content in its native lang
|
||||
_LOGGER = logging.getLogger(__name__)
|
||||
|
||||
|
||||
@@ -254,12 +254,16 @@ def filter_contents_translations(generator):
|
||||
hiding_func = inspector.hiding_function()
|
||||
untrans_policy = inspector.untranslated_policy(default='hide')
|
||||
for (contents, other_contents) in inspector.contents_list_pairs():
|
||||
for content in other_contents: # save any hidden native content first
|
||||
if content.lang == current_lang: # in native lang
|
||||
# save any hidden native content first
|
||||
for content in other_contents:
|
||||
# in native lang
|
||||
if content.lang == current_lang:
|
||||
# save the native URL attr formatted in the current locale
|
||||
_NATIVE_CONTENT_URL_DB[content.source_path] = content.url
|
||||
for content in contents[:]: # copy for removing in loop
|
||||
if content.lang == current_lang: # in native lang
|
||||
# copy for removing in loop
|
||||
for content in contents[:]:
|
||||
# in native lang
|
||||
if content.lang == current_lang:
|
||||
# save the native URL attr formatted in the current locale
|
||||
_NATIVE_CONTENT_URL_DB[content.source_path] = content.url
|
||||
elif content.lang in langs_with_sites and untrans_policy != 'keep':
|
||||
@@ -276,7 +280,8 @@ def install_templates_translations(generator):
|
||||
Only if the 'jinja2.ext.i18n' jinja2 extension is enabled
|
||||
the translations for the current DEFAULT_LANG are installed.
|
||||
'''
|
||||
if 'JINJA_ENVIRONMENT' in generator.settings: # pelican 3.7+
|
||||
# pelican 3.7+
|
||||
if 'JINJA_ENVIRONMENT' in generator.settings:
|
||||
jinja_extensions = generator.settings['JINJA_ENVIRONMENT'].get(
|
||||
'extensions', [])
|
||||
else:
|
||||
@@ -357,16 +362,19 @@ def interlink_removed_content(generator):
|
||||
|
||||
def interlink_static_files(generator):
|
||||
'''Add links to static files in the main site if necessary'''
|
||||
# customized STATIC_PATHS
|
||||
if generator.settings['STATIC_PATHS'] != []:
|
||||
return # customized STATIC_PATHS
|
||||
try: # minimize attr lookup
|
||||
return
|
||||
# minimize attr lookup
|
||||
try:
|
||||
static_content = generator.context['static_content']
|
||||
except KeyError:
|
||||
static_content = generator.context['filenames']
|
||||
relpath = relpath_to_site(generator.settings['DEFAULT_LANG'], _MAIN_LANG)
|
||||
for staticfile in _MAIN_STATIC_FILES:
|
||||
if staticfile.get_relative_source_path() not in static_content:
|
||||
staticfile = copy(staticfile) # prevent override in main site
|
||||
# prevent override in main site
|
||||
staticfile = copy(staticfile)
|
||||
staticfile.override_url = posixpath.join(relpath, staticfile.url)
|
||||
try:
|
||||
generator.add_source_path(staticfile, static=True)
|
||||
|
||||
@@ -42,12 +42,12 @@ class TestSettingsManipulation(unittest.TestCase):
|
||||
self.settings['PELICAN_CLASS'] = object
|
||||
cls = i18ns.get_pelican_cls(self.settings)
|
||||
self.assertIs(cls, object)
|
||||
|
||||
|
||||
def test_get_pelican_cls_str(self):
|
||||
'''Test that we get correct class given by string'''
|
||||
cls = i18ns.get_pelican_cls(self.settings)
|
||||
self.assertIs(cls, Pelican)
|
||||
|
||||
|
||||
|
||||
class TestSitesRelpath(unittest.TestCase):
|
||||
'''Test relative path between sites generation'''
|
||||
@@ -72,7 +72,7 @@ class TestSitesRelpath(unittest.TestCase):
|
||||
self.assertEqual(i18ns.relpath_to_site('en', 'de'), 'de')
|
||||
self.assertEqual(i18ns.relpath_to_site('de', 'en'), '..')
|
||||
|
||||
|
||||
|
||||
class TestRegistration(unittest.TestCase):
|
||||
'''Test plugin registration'''
|
||||
|
||||
@@ -91,7 +91,7 @@ class TestRegistration(unittest.TestCase):
|
||||
self.assertIn(id(handler), sig.receivers)
|
||||
# clean up
|
||||
sig.disconnect(handler)
|
||||
|
||||
|
||||
|
||||
class TestFullRun(unittest.TestCase):
|
||||
'''Test running Pelican with the Plugin'''
|
||||
|
||||
Reference in New Issue
Block a user