Skip to content
This repository was archived by the owner on Aug 17, 2023. It is now read-only.

Commit 13dbeeb

Browse files
committed
Minor cleanup in django.templates.utils
1 parent 05be260 commit 13dbeeb

File tree

1 file changed

+10
-19
lines changed

1 file changed

+10
-19
lines changed

hamlpy/template/utils.py

+10-19
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,24 @@
11
from __future__ import unicode_literals
22

33
import imp
4+
5+
from django.template import loaders
46
from os import listdir
57
from os.path import dirname, splitext
68

7-
try:
8-
from django.template import loaders
9-
_django_available = True
10-
except ImportError as e:
11-
_django_available = False
12-
139
MODULE_EXTENSIONS = tuple([suffix[0] for suffix in imp.get_suffixes()])
1410

11+
1512
def get_django_template_loaders():
16-
if not _django_available:
17-
return []
18-
return [(loader.__name__.rsplit('.',1)[1], loader)
19-
for loader in get_submodules(loaders)
20-
if hasattr(loader, 'Loader')]
21-
13+
return [(loader.__name__.rsplit('.', 1)[1], loader) for loader in get_submodules(loaders) if hasattr(loader, 'Loader')]
14+
15+
2216
def get_submodules(package):
23-
submodules = ("%s.%s" % (package.__name__, module)
24-
for module in package_contents(package))
25-
return [__import__(module, {}, {}, [module.rsplit(".", 1)[-1]])
26-
for module in submodules]
17+
submodules = ("%s.%s" % (package.__name__, module) for module in package_contents(package))
18+
return [__import__(module, {}, {}, [module.rsplit(".", 1)[-1]]) for module in submodules]
19+
2720

2821
def package_contents(package):
2922
package_path = dirname(loaders.__file__)
30-
contents = set([splitext(module)[0]
31-
for module in listdir(package_path)
32-
if module.endswith(MODULE_EXTENSIONS)])
23+
contents = set([splitext(module)[0] for module in listdir(package_path) if module.endswith(MODULE_EXTENSIONS)])
3324
return contents

0 commit comments

Comments
 (0)