]> git.ipfire.org Git - thirdparty/sqlalchemy/alembic.git/commitdiff
Move use of ``__file__`` to be local to template access
authorlayday <layday@protonmail.com>
Mon, 3 Feb 2020 14:40:49 +0000 (09:40 -0500)
committerMike Bayer <mike_mp@zzzcomputing.com>
Mon, 3 Feb 2020 17:17:30 +0000 (12:17 -0500)
Moved the use of the ``__file__`` attribute at the base of the Alembic
package into the one place that it is specifically needed, which is when
the config attempts to locate the template directory. This helps to allow
Alembic to be fully importable in environments that are using Python
memory-only import schemes.  Pull request courtesy layday.

Partially-fixes: #648
Closes: #651
Pull-request: https://github.com/sqlalchemy/alembic/pull/651
Pull-request-sha: c30299dbc3499c59e81602d91deb3b03166b4583

Change-Id: I2607031d80c418ce4d7e779eeb42c57a53a72ce0

alembic/__init__.py
alembic/config.py
docs/build/unreleased/648_file.rst [new file with mode: 0644]

index a63c0220b11cff9522a52442879a4ee70ab37394..4d4fbaa2134dd6067f48eddbec92437534bab4ff 100644 (file)
@@ -1,4 +1,3 @@
-from os import path
 import sys
 
 from . import context  # noqa
@@ -8,7 +7,5 @@ from .runtime import migration
 
 __version__ = '1.3.4'
 
-package_dir = path.abspath(path.dirname(__file__))
-
 sys.modules["alembic.migration"] = migration
 sys.modules["alembic.environment"] = environment
index 48c41cb861c0ffbd27973020f0aaae56323984eb..f2c6ef9084a4e12e72329fa858bd50024d4f0897 100644 (file)
@@ -4,7 +4,6 @@ import os
 import sys
 
 from . import command
-from . import package_dir
 from . import util
 from .util import compat
 from .util.compat import SafeConfigParser
@@ -210,6 +209,9 @@ class Config(object):
         commands.
 
         """
+        import alembic
+
+        package_dir = os.path.abspath(os.path.dirname(alembic.__file__))
         return os.path.join(package_dir, "templates")
 
     def get_section(self, name, default=None):
diff --git a/docs/build/unreleased/648_file.rst b/docs/build/unreleased/648_file.rst
new file mode 100644 (file)
index 0000000..12c433e
--- /dev/null
@@ -0,0 +1,9 @@
+.. change::
+    :tags: usecase, environment
+    :tickets: 648
+
+    Moved the use of the ``__file__`` attribute at the base of the Alembic
+    package into the one place that it is specifically needed, which is when
+    the config attempts to locate the template directory. This helps to allow
+    Alembic to be fully importable in environments that are using Python
+    memory-only import schemes.  Pull request courtesy layday.