]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
Don't import provision.py unconditionally
authorMike Bayer <mike_mp@zzzcomputing.com>
Tue, 3 Mar 2020 21:03:39 +0000 (16:03 -0500)
committermike bayer <mike_mp@zzzcomputing.com>
Wed, 4 Mar 2020 02:23:32 +0000 (02:23 +0000)
Removed the imports for provision.py from each dialect
and instead added a call in the central provision.py to
a new dialect level method load_provisioning().  The
provisioning registry works in the same way, so an existing
dialect that is using the provision.py system right now
by importing it as part of the package will still continue to
function.  However, to avoid pulling in the testing package when
the dialect is used in a non-testing context, the new hook may be
used.   Also removed a module-level dependency
of the testing framework on the orm package.

Revised an internal change to the test system added as a result of
:ticket:`5085` where a testing-related module per dialect would be loaded
unconditionally upon making use of that dialect, pulling in SQLAlchemy's
testing framework as well as the ORM into the module import space.   This
would only impact initial startup time and memory to a modest extent,
however it's best that these additional modules aren't reverse-dependent on
straight Core usage.

Fixes: #5180
Change-Id: I6355601da5f6f44d85a2bbc3acb5928559942b9c
(cherry picked from commit 598f2f7e557073f29563d4d567f43931fc03013f)

doc/build/changelog/unreleased_13/5180.rst [new file with mode: 0644]
lib/sqlalchemy/dialects/mssql/__init__.py
lib/sqlalchemy/dialects/mysql/__init__.py
lib/sqlalchemy/dialects/oracle/__init__.py
lib/sqlalchemy/dialects/postgresql/__init__.py
lib/sqlalchemy/dialects/sqlite/__init__.py
lib/sqlalchemy/engine/default.py
lib/sqlalchemy/engine/interfaces.py
lib/sqlalchemy/testing/assertions.py
lib/sqlalchemy/testing/provision.py

diff --git a/doc/build/changelog/unreleased_13/5180.rst b/doc/build/changelog/unreleased_13/5180.rst
new file mode 100644 (file)
index 0000000..85ac9a6
--- /dev/null
@@ -0,0 +1,11 @@
+.. change::
+    :tags: bug, performance
+    :tickets: 5180
+
+    Revised an internal change to the test system added as a result of
+    :ticket:`5085` where a testing-related module per dialect would be loaded
+    unconditionally upon making use of that dialect, pulling in SQLAlchemy's
+    testing framework as well as the ORM into the module import space.   This
+    would only impact initial startup time and memory to a modest extent,
+    however it's best that these additional modules aren't reverse-dependent on
+    straight Core usage.
index 0de9a74547969615054991436cf7fa67efe0d71e..d8d577a658463a5fd336b557c7e3addf35557abd 100644 (file)
@@ -8,7 +8,6 @@
 from . import adodbapi  # noqa
 from . import base  # noqa
 from . import mxodbc  # noqa
-from . import provision  # noqa
 from . import pymssql  # noqa
 from . import pyodbc  # noqa
 from . import zxjdbc  # noqa
index 59bcab4b87668c6a56f1b53b57c38c5db272a447..c9f3b43b47907f4fb3e129bd391b0272d97723b0 100644 (file)
@@ -11,7 +11,6 @@ from . import gaerdbms  # noqa
 from . import mysqlconnector  # noqa
 from . import mysqldb  # noqa
 from . import oursql  # noqa
-from . import provision  # noqa
 from . import pymysql  # noqa
 from . import pyodbc  # noqa
 from . import zxjdbc  # noqa
index 19b8fac557407a5904db1de5c0a3dbd9047e49e1..849dd6924a6591192f32dc89b16636b7cce0627e 100644 (file)
@@ -7,7 +7,6 @@
 
 from . import base  # noqa
 from . import cx_oracle  # noqa
-from . import provision  # noqa
 from . import zxjdbc  # noqa
 from .base import BFILE
 from .base import BINARY_DOUBLE
index bd3f58530ab48c37e618d0c8e808054170b5f81d..80875916a0dca6c966c3fda9bd93b297eda041c4 100644 (file)
@@ -7,7 +7,6 @@
 
 from . import base
 from . import pg8000  # noqa
-from . import provision  # noqa
 from . import psycopg2  # noqa
 from . import psycopg2cffi  # noqa
 from . import pygresql  # noqa
index c35cb9251cca1aa406a7eefefd03a0981195250e..142131f631bddeed30951f5caca9a58d763414ff 100644 (file)
@@ -6,7 +6,6 @@
 # the MIT License: http://www.opensource.org/licenses/mit-license.php
 
 from . import base  # noqa
-from . import provision  # noqa
 from . import pysqlcipher  # noqa
 from . import pysqlite  # noqa
 from .base import BLOB
index 577493d5f0f019d38ff49f4c47c9e3a7b3679e40..6760dd0f40fcf6833005af3ea4b0577969b5694f 100644 (file)
@@ -294,6 +294,14 @@ class DefaultDialect(interfaces.Dialect):
     def get_pool_class(cls, url):
         return getattr(cls, "poolclass", pool.QueuePool)
 
+    @classmethod
+    def load_provisioning(cls):
+        package = ".".join(cls.__module__.split(".")[0:-1])
+        try:
+            __import__(package + ".provision")
+        except ImportError:
+            pass
+
     def initialize(self, connection):
         try:
             self.server_version_info = self._get_server_version_info(
index bf684663ec63187c2cc41b8df725f452b19a12a4..3c21c981a99645b7e2b8446f57a90700104e6205 100644 (file)
@@ -869,6 +869,35 @@ class Dialect(object):
         """
         return cls
 
+    @classmethod
+    def load_provisioning(cls):
+        """set up the provision.py module for this dialect.
+
+        For dialects that include a provision.py module that sets up
+        provisioning followers, this method should initiate that process.
+
+        A typical implementation would be::
+
+            @classmethod
+            def load_provisioning(cls):
+                __import__("mydialect.provision")
+
+        The default method assumes a module named ``provision.py`` inside
+        the owning package of the current dialect, based on the ``__module__``
+        attribute::
+
+            @classmethod
+            def load_provisioning(cls):
+                package = ".".join(cls.__module__.split(".")[0:-1])
+                try:
+                    __import__(package + ".provision")
+                except ImportError:
+                    pass
+
+        .. versionadded:: 1.3.14
+
+        """
+
     @classmethod
     def engine_created(cls, engine):
         """A convenience hook called before returning the final :class:`.Engine`.
index f53ec1ba46aaff10c594bd9589c179a24679f07d..56ebb6933253e934090cf9d1c2bde8438d1e4746 100644 (file)
@@ -19,7 +19,6 @@ from . import util as testutil
 from .exclusions import db_spec
 from .util import fail
 from .. import exc as sa_exc
-from .. import orm
 from .. import pool
 from .. import schema
 from .. import types as sqltypes
@@ -413,6 +412,8 @@ class AssertsCompiledSQL(object):
         if literal_binds:
             compile_kwargs["literal_binds"] = True
 
+        from sqlalchemy import orm
+
         if isinstance(clause, orm.Query):
             context = clause._compile_context()
             context.statement.use_labels = True
index 6e2e1ccf50f76933492e1da3a6c7c771724154be..543d91a533f2e247d944afed870ea9a99741fc2c 100644 (file)
@@ -6,7 +6,6 @@ from . import engines
 from ..engine import url as sa_url
 from ..util import compat
 
-
 log = logging.getLogger(__name__)
 
 FOLLOWER_IDENT = None
@@ -51,7 +50,9 @@ def setup_config(db_url, options, file_config, follower_ident):
     # load the dialect, which should also have it set up its provision
     # hooks
 
-    sa_url.make_url(db_url).get_dialect()
+    dialect = sa_url.make_url(db_url).get_dialect()
+    dialect.load_provisioning()
+
     if follower_ident:
         db_url = follower_url_from_main(db_url, follower_ident)
     db_opts = {}