def test_deprecated_extra_templates_paths(self): settings = self.settings settings['EXTRA_TEMPLATES_PATHS'] = ['/foo/bar', '/ha'] configure_settings(settings) self.assertEqual(settings['THEME_TEMPLATES_OVERRIDES'], ['/foo/bar', '/ha']) self.assertNotIn('EXTRA_TEMPLATES_PATHS', settings)
def test_default_encoding(self): # Test that the default locale is set if not specified in settings # Reset locale to Python's default locale locale.setlocale(locale.LC_ALL, str('C')) self.assertEqual(self.settings['LOCALE'], DEFAULT_CONFIG['LOCALE']) configure_settings(self.settings) self.assertEqual(locale.getlocale(), locale.getdefaultlocale())
def test_default_encoding(self): # test that the default locale is set if # locale is not specified in the settings # reset locale to python default locale.setlocale(locale.LC_ALL, str("C")) self.assertEqual(self.settings["LOCALE"], DEFAULT_CONFIG["LOCALE"]) configure_settings(self.settings) self.assertEqual(locale.getlocale(), locale.getdefaultlocale())
def test_theme_settings_exceptions(self): settings = self.settings # Check that theme lookup in "pelican/themes" functions as expected settings['THEME'] = os.path.split(settings['THEME'])[1] configure_settings(settings) self.assertEqual(settings['THEME'], DEFAULT_THEME) # Check that non-existent theme raises exception settings['THEME'] = 'foo' self.assertRaises(Exception, configure_settings, settings)
def test_configure_settings(self): # Manipulations to settings should be applied correctly. settings = {"SITEURL": "http://blog.notmyidea.org/", "LOCALE": "", "PATH": os.curdir, "THEME": DEFAULT_THEME} configure_settings(settings) # SITEURL should not have a trailing slash self.assertEqual(settings["SITEURL"], "http://blog.notmyidea.org") # FEED_DOMAIN, if undefined, should default to SITEURL self.assertEqual(settings["FEED_DOMAIN"], "http://blog.notmyidea.org") settings["FEED_DOMAIN"] = "http://feeds.example.com" configure_settings(settings) self.assertEqual(settings["FEED_DOMAIN"], "http://feeds.example.com")
def test_path_settings_safety(self): """Don't let people setting the static path listings to strs""" settings = { "STATIC_PATHS": "foo/bar", "THEME_STATIC_PATHS": "bar/baz", # These 4 settings are required to run configure_settings "PATH": ".", "THEME": DEFAULT_THEME, "SITEURL": "http://blog.notmyidea.org/", "LOCALE": "", } configure_settings(settings) self.assertEqual(settings["STATIC_PATHS"], DEFAULT_CONFIG["STATIC_PATHS"]) self.assertEqual(settings["THEME_STATIC_PATHS"], DEFAULT_CONFIG["THEME_STATIC_PATHS"])
def test_deprecated_dir_setting(self): settings = self.settings settings['ARTICLE_DIR'] = 'foo' settings['PAGE_DIR'] = 'bar' configure_settings(settings) self.assertEqual(settings['ARTICLE_PATHS'], ['foo']) self.assertEqual(settings['PAGE_PATHS'], ['bar']) with self.assertRaises(KeyError): settings['ARTICLE_DIR'] settings['PAGE_DIR']
def test_ok_on_custom_data(self): settings = get_settings(filenames={}) settings["PATH"] = join(CUR_DIR, "test_data") settings["PLUGINS"] = ["pelican-ipynb.markup"] # to also parse .ipynb files configure_settings(settings) pelican_mock = PelicanMock(settings) pelican_init(pelican_mock) Pelican.init_plugins(pelican_mock) with TemporaryDirectory() as tmpdirname: generator = _build_article_generator(settings, tmpdirname) process_rst_and_summaries([generator]) for article in generator.articles: if article.source_path.endswith(".rst"): self.assertIn("mathjaxscript_pelican", article.content) generator.generate_output(Writer(tmpdirname, settings=settings))
def test_static_path_settings_safety(self): # Disallow static paths from being strings settings = {'STATIC_PATHS': 'foo/bar', 'THEME_STATIC_PATHS': 'bar/baz', # These 4 settings are required to run configure_settings 'PATH': '.', 'THEME': DEFAULT_THEME, 'SITEURL': 'http://blog.notmyidea.org/', 'LOCALE': '', } configure_settings(settings) self.assertEqual(settings['STATIC_PATHS'], DEFAULT_CONFIG['STATIC_PATHS']) self.assertEqual(settings['THEME_STATIC_PATHS'], DEFAULT_CONFIG['THEME_STATIC_PATHS'])
def test_path_settings_safety(self): """Don't let people setting the static path listings to strs""" settings = {'STATIC_PATHS': 'foo/bar', 'THEME_STATIC_PATHS': 'bar/baz', # These 4 settings are required to run configure_settings 'PATH': '.', 'THEME': DEFAULT_THEME, 'SITEURL': 'http://blog.notmyidea.org/', 'LOCALE': '', } configure_settings(settings) self.assertEqual(settings['STATIC_PATHS'], DEFAULT_CONFIG['STATIC_PATHS']) self.assertEqual(settings['THEME_STATIC_PATHS'], DEFAULT_CONFIG['THEME_STATIC_PATHS'])
def test_path_settings_safety(self): """Don't let people setting the static path listings to strs""" settings = { 'STATIC_PATHS': 'foo/bar', 'THEME_STATIC_PATHS': 'bar/baz', # These 4 settings are required to run configure_settings 'PATH': '.', 'THEME': DEFAULT_THEME, 'SITEURL': 'http://blog.notmyidea.org/', 'LOCALE': '', } configure_settings(settings) self.assertEqual(settings['STATIC_PATHS'], DEFAULT_CONFIG['STATIC_PATHS']) self.assertEqual(settings['THEME_STATIC_PATHS'], DEFAULT_CONFIG['THEME_STATIC_PATHS'])
def create_next_subsite(pelican_obj): '''Create the next subsite using the lang-specific config If there are no more subsites in the generation queue, update all the generators (interlink translations and removed content, add variables and translations to template context). Otherwise get the language and overrides for next the subsite in the queue and apply overrides. Then generate the subsite using a PELICAN_CLASS instance and its run method. Finally, restore the previous locale. ''' global _MAIN_SETTINGS if len(_SUBSITE_QUEUE) == 0: _LOGGER.debug( 'i18n: Updating cross-site links and context of all generators.') update_generators() _MAIN_SETTINGS = None # to initialize next time else: with temporary_locale(): settings = _MAIN_SETTINGS.copy() lang, overrides = _SUBSITE_QUEUE.popitem() settings.update(overrides) settings = configure_settings(settings) # to set LOCALE, etc. cls = get_pelican_cls(settings) new_pelican_obj = cls(settings) _LOGGER.debug(("Generating i18n subsite for language '{}' " "using class {}").format(lang, cls)) new_pelican_obj.run()
def create_lang_subsites(pelican_obj): """For each language create a subsite using the lang-specific config for each generated lang append language subpath to SITEURL and OUTPUT_PATH and set DEFAULT_LANG to the language code to change perception of what is translated and set DELETE_OUTPUT_DIRECTORY to False to prevent deleting output from previous runs Then generate the subsite using a PELICAN_CLASS instance and its run method. """ global _main_site_generated if _main_site_generated: # make sure this is only called once return else: _main_site_generated = True orig_settings = pelican_obj.settings for lang, overrides in orig_settings.get('I18N_SUBSITES', {}).items(): settings = orig_settings.copy() settings.update(overrides) settings['SITEURL'] = _lang_siteurls[lang] settings['OUTPUT_PATH'] = os.path.join(orig_settings['OUTPUT_PATH'], lang, '') settings['DEFAULT_LANG'] = lang # to change what is perceived as translations settings['DELETE_OUTPUT_DIRECTORY'] = False # prevent deletion of previous runs settings = configure_settings(settings) # to set LOCALE, etc. cls = settings['PELICAN_CLASS'] if isinstance(cls, six.string_types): module, cls_name = cls.rsplit('.', 1) module = __import__(module) cls = getattr(module, cls_name) pelican_obj = cls(settings) logger.debug("Generating i18n subsite for lang '{}' using class '{}'".format(lang, str(cls))) pelican_obj.run() _main_site_generated = False # for autoreload mode
def test_static_path_settings_safety(self): # Disallow static paths from being strings settings = { 'STATIC_PATHS': 'foo/bar', 'THEME_STATIC_PATHS': 'bar/baz', # These 4 settings are required to run configure_settings 'PATH': '.', 'THEME': DEFAULT_THEME, 'SITEURL': 'http://blog.notmyidea.org/', 'LOCALE': '', } configure_settings(settings) self.assertEqual(settings['STATIC_PATHS'], DEFAULT_CONFIG['STATIC_PATHS']) self.assertEqual(settings['THEME_STATIC_PATHS'], DEFAULT_CONFIG['THEME_STATIC_PATHS'])
def test_configure_settings(self): #Manipulations to settings should be applied correctly. settings = { 'SITEURL': 'http://blog.notmyidea.org/', 'LOCALE': '', 'PATH': os.curdir, 'THEME': DEFAULT_THEME, } configure_settings(settings) # SITEURL should not have a trailing slash self.assertEqual(settings['SITEURL'], 'http://blog.notmyidea.org') # FEED_DOMAIN, if undefined, should default to SITEURL self.assertEqual(settings['FEED_DOMAIN'], 'http://blog.notmyidea.org') settings['FEED_DOMAIN'] = 'http://feeds.example.com' configure_settings(settings) self.assertEqual(settings['FEED_DOMAIN'], 'http://feeds.example.com')
def test_deprecated_paginated_direct_templates(self): settings = self.settings settings['PAGINATED_DIRECT_TEMPLATES'] = ['index', 'archives'] settings['PAGINATED_TEMPLATES'] = {'index': 10, 'category': None} settings = configure_settings(settings) self.assertEqual(settings['PAGINATED_TEMPLATES'], { 'index': 10, 'category': None, 'archives': None }) self.assertNotIn('PAGINATED_DIRECT_TEMPLATES', settings)
def test_configure_settings(self): # Manipulations to settings should be applied correctly. settings = { 'SITEURL': 'http://blog.notmyidea.org/', 'LOCALE': '', 'PATH': os.curdir, 'THEME': DEFAULT_THEME, } configure_settings(settings) # SITEURL should not have a trailing slash self.assertEqual(settings['SITEURL'], 'http://blog.notmyidea.org') # FEED_DOMAIN, if undefined, should default to SITEURL self.assertEqual(settings['FEED_DOMAIN'], 'http://blog.notmyidea.org') settings['FEED_DOMAIN'] = 'http://com.koobecaf.www' configure_settings(settings) # Determine if 'FEED_DOMAIN' will default to 'SITEURL' if not undefined self.assertNotEqual(settings['FEED_DOMAIN'], 'http://blog.notmyidea.org') self.assertEqual(settings['FEED_DOMAIN'], 'http://com.koobecaf.www')
def subsites(pelican_obj): # Copy the main site's settings basesettings = pelican_obj.settings.copy() baseoutput = basesettings["OUTPUT_PATH"] basesite = basesettings["SITEURL"] # Run through the list of subsites for subsite in basesettings["SUBSITES"]: logging.debug('Subsite {}: Started.'.format( subsite.replace('_', '').capitalize())) # Turn the settings file into a dictionary and make the relative paths # absolute newsettings = relativise_path( get_settings_from_file(subsite + "/settings.py", basesettings), subsite + "/settings.py") # Ensure that the output is a subdirectory of the main site newsettings["OUTPUT_PATH"] = baseoutput + \ "/" + newsettings["SUBSITE_PATH"] # Ensure that the subsite knows its url newsettings["SITEURL"] = basesite + \ "/" + newsettings["SUBSITE_PATH"] newsettings["BASEURL"] = basesite # Pelican magic settings checker settings = configure_settings(newsettings) # This is a bit hacky. It removes the plugin to signal mapping. For # reason even in a new pelican object the signals are still mapped # to the old plugins. # iterate through module's attributes for name, val in signals.__dict__.items(): if hasattr(val, 'receivers'): val.receivers = {} # Set up a pelican class cls = basesettings['PELICAN_CLASS'] # I think this is some python2/3 compatibility thing # I'm scared to remove. if isinstance(cls, six.string_types): module, cls_name = cls.rsplit('.', 1) module = __import__(module) cls = getattr(module, cls_name) # Create a new pelican instance for the subsite and run! new_pelican_obj = cls(settings) new_pelican_obj.run() for name, val in signals.__dict__.items(): if hasattr(val, 'receivers'): val.receivers = {} logging.debug('Subsite {}: Completed.'.format( subsite.replace('_', '').capitalize()))
def get_settings(src, dst, theme_path, local_settings): """Generate Pelican settings dict and normalize certain options""" settings = copy.deepcopy(DEFAULT_CONFIG) settings.update(local_settings) settings['PATH'] = norm_content_path(src, settings['PATH']) settings['OUTPUT_PATH'] = dst settings['PLUGIN_PATH'] = KEZ_PLUGIN_PATH settings['PLUGINS'] = KEZ_PLUGINS settings['DELETE_OUTPUT_DIRECTORY'] = False global PYGMENTS_RST_OPTIONS PYGMENTS_RST_OPTIONS = settings.get('PYGMENTS_RST_OPTIONS', None) settings['PELICAN_CLASS'] = 'pelican.Pelican' #updated = {} #for key, val in settings.items(): # if key in STATIC_PATH_SETTINGS: # updated[key] = norm_path_setting(src, val) #settings.update(updated) return configure_settings(settings)
def mkpelican(): """runs pelican build""" def fullthemepath(tpath): """joins theme path""" return path.join(PELIC_PATH, tpath) psettings = get_settings_from_file(PELIC_CONFIG) psettings["PATH"] = PELIC_CONTENT psettings["OUTPUT_PATH"] = PELIC_OUTPUT psettings["THEME"] = fullthemepath(psettings["THEME"]) message( "running something similar to 'pelican -t %s -s %s %s -o %s'" % (psettings["THEME"], PELIC_CONFIG, PELIC_CONTENT, PELIC_OUTPUT), shout=True, ) pinst = Pelican(configure_settings(psettings)) pinst.run()
def subsites(pelican_obj): # Copy the main site's settings basesettings = pelican_obj.settings.copy() baseoutput = basesettings["OUTPUT_PATH"] basesite = basesettings["SITEURL"] # Run through the list of subsites for subsite in basesettings["SUBSITES"]: logging.debug('Subsite {}: Started.'.format(subsite.replace('_', '').capitalize())) # Turn the settings file into a dictionary and make the relative paths # absolute newsettings = relativise_path( get_settings_from_file(subsite + "/settings.py", basesettings), subsite + "/settings.py") # Ensure that the output is a subdirectory of the main site newsettings["OUTPUT_PATH"] = baseoutput + \ "/" + newsettings["SUBSITE_PATH"] # Ensure that the subsite knows its url newsettings["SITEURL"] = basesite + \ "/" + newsettings["SUBSITE_PATH"] newsettings["BASEURL"] = basesite # Pelican magic settings checker settings = configure_settings(newsettings) # This is a bit hacky. It removes the plugin to signal mapping. For # reason even in a new pelican object the signals are still mapped # to the old plugins. # iterate through module's attributes for name, val in signals.__dict__.items(): if hasattr(val, 'receivers'): val.receivers = {} # Set up a pelican class cls = basesettings['PELICAN_CLASS'] # I think this is some python2/3 compatibility thing # I'm scared to remove. if isinstance(cls, six.string_types): module, cls_name = cls.rsplit('.', 1) module = __import__(module) cls = getattr(module, cls_name) # Create a new pelican instance for the subsite and run! new_pelican_obj = cls(settings) new_pelican_obj.run() for name, val in signals.__dict__.items(): if hasattr(val, 'receivers'): val.receivers = {} logging.debug('Subsite {}: Completed.'.format(subsite.replace('_', '').capitalize()))
def test_configure_settings(self): """Manipulations to settings should be applied correctly.""" # SITEURL should not have a trailing slash settings = {'SITEURL': 'http://blog.notmyidea.org/', 'LOCALE': ''} configure_settings(settings) self.assertEqual(settings['SITEURL'], 'http://blog.notmyidea.org') # FEED_DOMAIN, if undefined, should default to SITEURL settings = {'SITEURL': 'http://blog.notmyidea.org', 'LOCALE': ''} configure_settings(settings) self.assertEqual(settings['FEED_DOMAIN'], 'http://blog.notmyidea.org') settings = {'FEED_DOMAIN': 'http://feeds.example.com', 'LOCALE': ''} configure_settings(settings) self.assertEqual(settings['FEED_DOMAIN'], 'http://feeds.example.com')
def create_lang_subsites(pelican_obj): """For each language create a subsite using the lang-specific config for each generated lang append language subpath to SITEURL and OUTPUT_PATH and set DEFAULT_LANG to the language code to change perception of what is translated and set DELETE_OUTPUT_DIRECTORY to False to prevent deleting output from previous runs Then generate the subsite using a PELICAN_CLASS instance and its run method. """ global _main_site_generated if _main_site_generated: # make sure this is only called once return else: _main_site_generated = True orig_settings = pelican_obj.settings for lang, overrides in orig_settings.get('I18N_SUBSITES', {}).items(): settings = orig_settings.copy() settings.update(overrides) settings['SITEURL'] = _lang_siteurls[lang] settings['OUTPUT_PATH'] = os.path.join(orig_settings['OUTPUT_PATH'], lang, '') settings[ 'DEFAULT_LANG'] = lang # to change what is perceived as translations settings[ 'DELETE_OUTPUT_DIRECTORY'] = False # prevent deletion of previous runs settings = configure_settings(settings) # to set LOCALE, etc. cls = settings['PELICAN_CLASS'] if isinstance(cls, six.string_types): module, cls_name = cls.rsplit('.', 1) module = __import__(module) cls = getattr(module, cls_name) pelican_obj = cls(settings) logger.debug( "Generating i18n subsite for lang '{}' using class '{}'".format( lang, str(cls))) pelican_obj.run() _main_site_generated = False # for autoreload mode
def initialize_settings(settings): # This initializes settings according to pelican return configure_settings(combine(DEFAULT_CONFIG, settings))