From: Mike Bayer Date: Sun, 14 Apr 2013 23:03:48 +0000 (-0400) Subject: - fix version number in docs here X-Git-Tag: rel_0_6_0~17 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=2a2a7b543b9bc3ec9541572c583da2d94891ae47;p=thirdparty%2Fsqlalchemy%2Falembic.git - fix version number in docs here - add py3.3 compat, other compat to remove all warnings --- diff --git a/alembic/compat.py b/alembic/compat.py index 5c9a1ced..ffc2d990 100644 --- a/alembic/compat.py +++ b/alembic/compat.py @@ -4,6 +4,7 @@ if sys.version_info < (2, 6): raise NotImplementedError("Python 2.6 or greater is required.") py3k = sys.version_info >= (3, 0) +py33 = sys.version_info >= (3, 3) if py3k: import builtins as compat_builtins @@ -19,12 +20,27 @@ else: text_type = unicode callable = callable - -try: +if py3k: + from configparser import ConfigParser as SafeConfigParser import configparser -except ImportError: +else: + from ConfigParser import SafeConfigParser import ConfigParser as configparser +if py33: + from importlib import machinery + def load_module(module_id, path): + return machinery.SourceFileLoader(module_id, path).load_module() +else: + import imp + def load_module(module_id, path): + fp = open(path, 'rb') + try: + return imp.load_source(module_id, path, fp) + finally: + fp.close() + + try: exec_ = getattr(compat_builtins, 'exec') except AttributeError: diff --git a/alembic/config.py b/alembic/config.py index df20fc6e..c1ad7ecc 100644 --- a/alembic/config.py +++ b/alembic/config.py @@ -1,5 +1,5 @@ from argparse import ArgumentParser -from .compat import configparser +from .compat import SafeConfigParser import inspect import os import sys @@ -91,7 +91,7 @@ class Config(object): here = os.path.abspath(os.path.dirname(self.config_file_name)) else: here = "" - file_config = configparser.SafeConfigParser({'here': here}) + file_config = SafeConfigParser({'here': here}) if self.config_file_name: file_config.read([self.config_file_name]) else: diff --git a/alembic/util.py b/alembic/util.py index edaf0ba3..3c227b74 100644 --- a/alembic/util.py +++ b/alembic/util.py @@ -1,7 +1,6 @@ import sys import os import textwrap -import imp import warnings import re import inspect @@ -11,7 +10,7 @@ from mako.template import Template from sqlalchemy.engine import url from sqlalchemy import __version__ -from .compat import callable, exec_ +from .compat import callable, exec_, load_module class CommandError(Exception): pass @@ -175,8 +174,7 @@ def load_python_file(dir_, filename): module_id = re.sub(r'\W', "_", filename) path = os.path.join(dir_, filename) - with open(path, 'rb') as f: - module = imp.load_source(module_id, path, f) + module = load_module(module_id, path) del sys.modules[module_id] return module @@ -246,9 +244,6 @@ class immutabledict(dict): return "immutabledict(%s)" % dict.__repr__(self) - - - def _with_legacy_names(translations): def decorate(fn): diff --git a/docs/build/tutorial.rst b/docs/build/tutorial.rst index 29818d17..4b76f298 100644 --- a/docs/build/tutorial.rst +++ b/docs/build/tutorial.rst @@ -421,12 +421,10 @@ View all revisions from 1975 to the head:: $ alembic history -r1975ea: -.. versionadded:: 0.6.1 ``alembic revision`` now accepts the ``-r`` argument to +.. versionadded:: 0.6.0 ``alembic revision`` now accepts the ``-r`` argument to specify specific ranges based on version numbers, symbols, or relative deltas. - - Downgrading =========== diff --git a/tests/test_revision_create.py b/tests/test_revision_create.py index fd9a7ed7..a74346e8 100644 --- a/tests/test_revision_create.py +++ b/tests/test_revision_create.py @@ -151,6 +151,7 @@ down_revision = ${repr(down_revision)} command.revision(self.cfg, message="some rev") script = ScriptDirectory.from_config(self.cfg) rev = script.get_revision('head') - text = open(rev.path).read() + with open(rev.path) as f: + text = f.read() assert "somearg: somevalue" in text