Skip to content

Commit f8502d6

Browse files
committed
no longer lazy-loading SQL
1 parent b92f423 commit f8502d6

File tree

2 files changed

+3
-26
lines changed

2 files changed

+3
-26
lines changed

setup.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
"Topic :: Software Development :: Libraries :: Python Modules"
1111
],
1212
description="CS50 library for Python",
13-
install_requires=["Flask", "SQLAlchemy", "sqlparse", "termcolor"],
13+
install_requires=["Flask>=1.0", "SQLAlchemy", "sqlparse", "termcolor"],
1414
keywords="cs50",
1515
name="cs50",
1616
package_dir={"": "src"},

src/cs50/__init__.py

+2-25
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,6 @@
11
import os
22
import sys
33

4-
5-
class CustomImporter(object):
6-
"""
7-
Import cs50.SQL lazily so that rest of library can be used without SQLAlchemy installed.
8-
9-
https://docs.python.org/3/library/imp.html
10-
http://xion.org.pl/2012/05/06/hacking-python-imports/
11-
http://dangerontheranger.blogspot.com/2012/07/how-to-use-sysmetapath-with-python.html
12-
"""
13-
14-
def find_module(self, fullname, path=None):
15-
if fullname == "cs50.SQL":
16-
return self
17-
return None
18-
19-
def load_module(self, name):
20-
if name in sys.modules:
21-
return sys.modules[name]
22-
from .sql import SQL
23-
sys.modules[name] = SQL
24-
return SQL
25-
26-
274
try:
285

296
# Save student's sys.path
@@ -42,8 +19,8 @@ def load_module(self, name):
4219
# Replace Flask's logger
4320
from . import flask
4421

45-
# Lazily load CS50.SQL
46-
sys.meta_path.append(CustomImporter())
22+
# Wrap SQLAlchemy
23+
from .sql import SQL
4724

4825
finally:
4926

0 commit comments

Comments
 (0)