-
Notifications
You must be signed in to change notification settings - Fork 57
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
838bcde
commit 709af45
Showing
3 changed files
with
19 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,17 @@ | ||
import os | ||
import pkgutil | ||
def init(): | ||
""" | ||
Some ORMs, e.g. Django, may require initialization to be performed, but only at some certain | ||
point, e.g. after some variables are set and so on, this function provides an ability to run | ||
this initialization for all supported ORMs automatically but only when needed by the caller | ||
""" | ||
import os | ||
import pkgutil | ||
|
||
# Some ORMs, e.g Django, requires some setup to be performed before one can use them | ||
for _, name, is_pkg in pkgutil.iter_modules([os.path.dirname(__file__)]): | ||
if is_pkg: | ||
try: | ||
__import__(name, level=0) # try to import globally and see if ORM is installed | ||
except ImportError: | ||
pass | ||
else: | ||
__import__(name, globals(), level=1) # if yes, run Architect's init code for this ORM | ||
for _, name, is_pkg in pkgutil.iter_modules([os.path.dirname(__file__)]): | ||
if is_pkg: | ||
try: | ||
__import__(name, level=0) # try to import globally and see if ORM is installed | ||
except ImportError: | ||
pass | ||
else: | ||
getattr(__import__(name, globals(), level=1), 'init', lambda: None)() # if yes, run init() for this ORM |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,4 @@ | ||
import os | ||
|
||
if 'DJANGO_SETTINGS_MODULE' in os.environ: | ||
def init(): | ||
try: | ||
import django | ||
django.setup() | ||
|