Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
allow alternative extensions to .py
  • Loading branch information
bckohan committed Jun 10, 2020
commit 6a8f7b4bc0a139cadaa91a5523b88399efc5499c
9 changes: 6 additions & 3 deletions split_settings/tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@
import inspect
import os
import sys
from importlib.util import module_from_spec, spec_from_file_location
from importlib.util import module_from_spec, spec_from_loader
from importlib.machinery import SourceFileLoader


__all__ = ('optional', 'include') # noqa: WPS410

Expand Down Expand Up @@ -114,8 +116,9 @@ def include(*args: str, **kwargs) -> None: # noqa: WPS210, WPS231, C901
rel_path[:rel_path.rfind('.')].replace('/', '.'),
)

spec = spec_from_file_location(
module_name, included_file,
spec = spec_from_loader(
module_name,
SourceFileLoader(os.path.basename(included_file).split('.')[0], included_file),
)
module = module_from_spec(spec)
sys.modules[module_name] = module
Expand Down
2 changes: 1 addition & 1 deletion tests/test_split_settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ def test_alt_ext(alt_ext):
assert alt_ext.NO_EXT_INCLUDED
assert alt_ext.DOT_CONF_INCLUDED
assert alt_ext.DOUBLE_EXT_INCLUDED
assert alt_ext.OPTIONAl_INCLUDED
assert alt_ext.OPTIONAL_INCLUDED


def test_override(merged, monkeypatch):
Expand Down