mirror of
https://github.com/getpelican/pelican.git
synced 2025-10-15 20:28:56 +02:00
Reimplement settings loading to preserve __file__
This commit is contained in:
parent
baeec62e07
commit
7cb18a088e
1 changed files with 22 additions and 10 deletions
|
|
@ -1,4 +1,6 @@
|
||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
|
import imp
|
||||||
|
import inspect
|
||||||
import os
|
import os
|
||||||
import locale
|
import locale
|
||||||
import logging
|
import logging
|
||||||
|
|
@ -84,21 +86,31 @@ def read_settings(filename=None):
|
||||||
return configured_settings
|
return configured_settings
|
||||||
|
|
||||||
|
|
||||||
def get_settings_from_file(filename, default_settings=None):
|
def get_settings_from_module(module=None, default_settings=_DEFAULT_CONFIG):
|
||||||
"""Load a Python file into a dictionary.
|
|
||||||
"""
|
"""
|
||||||
if default_settings == None:
|
Load settings from a module, returning a dict.
|
||||||
default_settings = _DEFAULT_CONFIG
|
|
||||||
|
"""
|
||||||
|
|
||||||
context = default_settings.copy()
|
context = default_settings.copy()
|
||||||
if filename:
|
if module is not None:
|
||||||
tempdict = {}
|
context.update(
|
||||||
execfile(filename, tempdict)
|
(k, v) for k, v in inspect.getmembers(module) if k.isupper()
|
||||||
for key in tempdict:
|
)
|
||||||
if key.isupper():
|
|
||||||
context[key] = tempdict[key]
|
|
||||||
return context
|
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):
|
def configure_settings(settings, default_settings=None, filename=None):
|
||||||
"""Provide optimizations, error checking, and warnings for loaded settings"""
|
"""Provide optimizations, error checking, and warnings for loaded settings"""
|
||||||
if default_settings is None:
|
if default_settings is None:
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue