Skip to content

Commit 06360a0

Browse files
benspauldingacdha
authored andcommitted
Prefer stdlib importlib over Django's included version
The app_loading module had to shuffle things a bit. When it was importing the function it raised a [RuntimeError][]. Simply importing the module resolved that. [RuntimeError]: https://gist.github.com/benspaulding/f36eaf483573f8e5f777
1 parent 1ef5638 commit 06360a0

File tree

4 files changed

+14
-6
lines changed

4 files changed

+14
-6
lines changed

haystack/templatetags/highlight.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,10 @@
55
from django import template
66
from django.conf import settings
77
from django.core.exceptions import ImproperlyConfigured
8-
from django.utils import importlib, six
8+
from django.utils import six
9+
10+
from haystack.utils import importlib
11+
912

1013
register = template.Library()
1114

haystack/utils/__init__.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,12 @@
1111
from haystack.utils.highlighting import Highlighter
1212

1313
try:
14-
from django.utils import importlib
15-
except ImportError:
14+
# Introduced in Python 2.7
1615
import importlib
16+
except ImportError:
17+
# Deprecated in Django 1.8; removed in Django 1.9 (both of which require
18+
# at least Python 2.7)
19+
from django.utils import importlib
1720

1821
IDENTIFIER_REGEX = re.compile('^[\w\d_]+\.[\w\d_]+\.\d+$')
1922

haystack/utils/app_loading.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,9 @@
55
from django.conf import settings
66
from django.core.exceptions import ImproperlyConfigured
77
from django.db.models.loading import get_app, get_model, get_models
8-
from django.utils.importlib import import_module
8+
9+
from haystack.utils import importlib
10+
911

1012
__all__ = ['haystack_get_models', 'haystack_load_apps']
1113

@@ -56,7 +58,7 @@ def is_app_or_model(label):
5658

5759
def haystack_get_app_modules():
5860
"""Return the Python module for each installed app"""
59-
return [import_module(i) for i in settings.INSTALLED_APPS]
61+
return [importlib.import_module(i) for i in settings.INSTALLED_APPS]
6062

6163
def haystack_load_apps():
6264
# Do all, in an INSTALLED_APPS sorted order.

haystack/utils/loading.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,11 @@
88

99
from django.conf import settings
1010
from django.core.exceptions import ImproperlyConfigured
11-
from django.utils import importlib
1211
from django.utils.datastructures import SortedDict
1312
from django.utils.module_loading import module_has_submodule
1413

1514
from haystack.exceptions import NotHandled, SearchFieldError
15+
from haystack.utils import importlib
1616
from haystack.utils.app_loading import haystack_get_app_modules
1717

1818

0 commit comments

Comments
 (0)