From baeec62e07b68a00637d7cfa045199f2b2b8e49d Mon Sep 17 00:00:00 2001 From: Julian Berman Date: Wed, 1 Aug 2012 13:02:15 -0400 Subject: [PATCH 1/2] Ignore coverage.py --- .gitignore | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.gitignore b/.gitignore index 9274ba2d..9f9404ef 100644 --- a/.gitignore +++ b/.gitignore @@ -9,3 +9,5 @@ build dist tags .tox +.coverage +htmlcov From 7cb18a088ee37521bcdbd668a321f754bf83c28d Mon Sep 17 00:00:00 2001 From: Julian Berman Date: Wed, 1 Aug 2012 13:36:47 -0400 Subject: [PATCH 2/2] Reimplement settings loading to preserve __file__ --- pelican/settings.py | 32 ++++++++++++++++++++++---------- 1 file changed, 22 insertions(+), 10 deletions(-) diff --git a/pelican/settings.py b/pelican/settings.py index e9888f94..645a9809 100644 --- a/pelican/settings.py +++ b/pelican/settings.py @@ -1,4 +1,6 @@ # -*- coding: utf-8 -*- +import imp +import inspect import os import locale import logging @@ -84,21 +86,31 @@ def read_settings(filename=None): return configured_settings -def get_settings_from_file(filename, default_settings=None): - """Load a Python file into a dictionary. +def get_settings_from_module(module=None, default_settings=_DEFAULT_CONFIG): """ - if default_settings == None: - default_settings = _DEFAULT_CONFIG + Load settings from a module, returning a dict. + + """ + context = default_settings.copy() - if filename: - tempdict = {} - execfile(filename, tempdict) - for key in tempdict: - if key.isupper(): - context[key] = tempdict[key] + if module is not None: + context.update( + (k, v) for k, v in inspect.getmembers(module) if k.isupper() + ) return context +def get_settings_from_file(filename, default_settings=_DEFAULT_CONFIG): + """ + Load settings from a file path, returning a dict. + + """ + + name = os.path.basename(filename).rpartition(".")[0] + module = imp.load_source(name, filename) + return get_settings_from_module(module, default_settings=default_settings) + + def configure_settings(settings, default_settings=None, filename=None): """Provide optimizations, error checking, and warnings for loaded settings""" if default_settings is None: