示例#1
0
    def run_env(self):
        """Run the script environment.

        This basically runs the ``env.py`` script present
        in the migration environment.   It is called exclusively
        by the command functions in :mod:`alembic.command`.


        """
        util.load_python_file(self.dir, 'env.py')
示例#2
0
文件: script.py 项目: 13917547121/me
    def run_env(self):
        """Run the script environment.

        This basically runs the ``env.py`` script present
        in the migration environment.   It is called exclusively
        by the command functions in :mod:`alembic.command`.


        """
        util.load_python_file(self.dir, 'env.py')
示例#3
0
def staging_env(create=True, template="generic", sourceless=False):
    from alembic import command, script
    cfg = _testing_config()
    if create:
        path = os.path.join(staging_directory, 'scripts')
        if os.path.exists(path):
            shutil.rmtree(path)
        command.init(cfg, path)
        if sourceless:
            try:
                # do an import so that a .pyc/.pyo is generated.
                util.load_python_file(path, 'env.py')
            except AttributeError:
                # we don't have the migration context set up yet
                # so running the .env py throws this exception.
                # theoretically we could be using py_compiler here to
                # generate .pyc/.pyo without importing but not really
                # worth it.
                pass
            make_sourceless(os.path.join(path, "env.py"))

    sc = script.ScriptDirectory.from_config(cfg)
    return sc
示例#4
0
def staging_env(create=True, template="generic", sourceless=False):
    from alembic import command, script
    cfg = _testing_config()
    if create:
        path = os.path.join(staging_directory, 'scripts')
        if os.path.exists(path):
            shutil.rmtree(path)
        command.init(cfg, path)
        if sourceless:
            try:
                # do an import so that a .pyc/.pyo is generated.
                util.load_python_file(path, 'env.py')
            except AttributeError:
                # we don't have the migration context set up yet
                # so running the .env py throws this exception.
                # theoretically we could be using py_compiler here to
                # generate .pyc/.pyo without importing but not really
                # worth it.
                pass
            make_sourceless(os.path.join(path, "env.py"))

    sc = script.ScriptDirectory.from_config(cfg)
    return sc
示例#5
0
文件: script.py 项目: 13917547121/me
 def _from_filename(cls, dir_, filename):
     if not _rev_file.match(filename):
         return None
     module = util.load_python_file(dir_, filename)
     if not hasattr(module, "revision"):
         # attempt to get the revision id from the script name,
         # this for legacy only
         m = _legacy_rev.match(filename)
         if not m:
             raise util.CommandError(
                     "Could not determine revision id from filename %s. "
                     "Be sure the 'revision' variable is "
                     "declared inside the script (please see 'Upgrading "
                     "from Alembic 0.1 to 0.2' in the documentation)."
                     % filename)
         else:
             revision = m.group(1)
     else:
         revision = module.revision
     return Script(module, revision, os.path.join(dir_, filename))
示例#6
0
 def _from_filename(cls, dir_, filename):
     if not _rev_file.match(filename):
         return None
     module = util.load_python_file(dir_, filename)
     if not hasattr(module, "revision"):
         # attempt to get the revision id from the script name,
         # this for legacy only
         m = _legacy_rev.match(filename)
         if not m:
             raise util.CommandError(
                 "Could not determine revision id from filename %s. "
                 "Be sure the 'revision' variable is "
                 "declared inside the script (please see 'Upgrading "
                 "from Alembic 0.1 to 0.2' in the documentation)." %
                 filename)
         else:
             revision = m.group(1)
     else:
         revision = module.revision
     return Script(module, revision, os.path.join(dir_, filename))
示例#7
0
 def run_env(self):
     dir_, filename = self.env_py_location.rsplit(os.path.sep, 1)
     load_python_file(dir_, filename)
示例#8
0
 def run_env(self) -> None:
     dir_, filename = self.env_py_location.rsplit(os.path.sep, 1)
     load_python_file(dir_, filename)