Commits

Georg Brandl committed 82998f3

Move default sqlalchemy engine creation to storage backend.

  • Participants
  • Parent commits 7739bc1

Comments (0)

Files changed (2)

File sphinx/websupport/__init__.py

             # SQLAlchemy backend.
             from sphinx.websupport.storage.sqlalchemystorage \
                 import SQLAlchemyStorage
-            from sqlalchemy import create_engine
-            db_path = path.join(self.datadir, 'db', 'websupport.db')
-            ensuredir(path.dirname(db_path))
-            uri = storage or 'sqlite:///%s' % db_path
-            engine = create_engine(uri)
-            self.storage = SQLAlchemyStorage(engine)
+            if not storage:
+                # no explicit DB path given; create default sqlite database
+                db_path = path.join(self.datadir, 'db', 'websupport.db')
+                ensuredir(path.dirname(db_path))
+                storage = 'sqlite:///' + db_path
+            self.storage = SQLAlchemyStorage(storage)
 
     def _init_templating(self):
         import sphinx

File sphinx/websupport/storage/sqlalchemystorage.py

     A :class:`.StorageBackend` using SQLAlchemy.
     """
 
-    def __init__(self, engine):
-        self.engine = engine
-        Base.metadata.bind = engine
+    def __init__(self, uri):
+        self.engine = sqlalchemy.create_engine(uri)
+        Base.metadata.bind = self.engine
         Base.metadata.create_all()
-        Session.configure(bind=engine)
+        Session.configure(bind=self.engine)
 
     def pre_build(self):
         self.build_session = Session()