mirror of
https://github.com/getpelican/pelican.git
synced 2026-08-30 22:04:05 +02:00
Merge ecaed490ea into 3c69dc68d2
This commit is contained in:
commit
ac2cf1fce7
3 changed files with 14 additions and 0 deletions
3
RELEASE.md
Normal file
3
RELEASE.md
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
Release type: patch
|
||||
|
||||
Raise a clear error when the specified settings file does not exist
|
||||
|
|
@ -17,6 +17,8 @@ from pelican.paginator import PaginationRule
|
|||
|
||||
def load_source(name: str, path: str) -> ModuleType:
|
||||
spec = importlib.util.spec_from_file_location(name, path)
|
||||
if spec is None or spec.loader is None:
|
||||
raise ImportError(f"Cannot import settings from {path}")
|
||||
mod = importlib.util.module_from_spec(spec)
|
||||
sys.modules[name] = mod
|
||||
spec.loader.exec_module(mod)
|
||||
|
|
@ -242,6 +244,8 @@ def get_settings_from_module(module: ModuleType | None = None) -> Settings:
|
|||
def get_settings_from_file(path: str) -> Settings:
|
||||
"""Loads settings from a file path, returning a dict."""
|
||||
|
||||
if not os.path.isfile(path):
|
||||
raise FileNotFoundError(f"Settings file not found: {path}")
|
||||
name, ext = os.path.splitext(os.path.basename(path))
|
||||
module = load_source(name, path)
|
||||
return get_settings_from_module(module)
|
||||
|
|
|
|||
|
|
@ -184,6 +184,13 @@ class TestSettingsConfiguration(unittest.TestCase):
|
|||
locale.setlocale(locale.LC_TIME, "")
|
||||
self.assertEqual(lc_time, locale.getlocale(locale.LC_TIME))
|
||||
|
||||
def test_read_settings_missing_file(self):
|
||||
missing = join(self.PATH, "no_such_conf.py")
|
||||
with self.assertRaises(FileNotFoundError):
|
||||
read_settings(missing)
|
||||
with self.assertRaises(FileNotFoundError):
|
||||
read_settings(join(self.PATH, "no_such_conf"))
|
||||
|
||||
def test_invalid_settings_throw_exception(self):
|
||||
# Test that the path name is valid
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue