From: layday Date: Mon, 3 Feb 2020 14:40:49 +0000 (-0500) Subject: Move use of ``__file__`` to be local to template access X-Git-Tag: rel_1_4_0~5 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=b3ce609f5d39fa485e39f78dfd3ed6c2b4d9d474;p=thirdparty%2Fsqlalchemy%2Falembic.git Move use of ``__file__`` to be local to template access 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 --- diff --git a/alembic/__init__.py b/alembic/__init__.py index a63c0220..4d4fbaa2 100644 --- a/alembic/__init__.py +++ b/alembic/__init__.py @@ -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 diff --git a/alembic/config.py b/alembic/config.py index 48c41cb8..f2c6ef90 100644 --- a/alembic/config.py +++ b/alembic/config.py @@ -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 index 00000000..12c433e9 --- /dev/null +++ b/docs/build/unreleased/648_file.rst @@ -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.