]> git.ipfire.org Git - thirdparty/sqlalchemy/alembic.git/commitdiff
- fix version number in docs here
authorMike Bayer <mike_mp@zzzcomputing.com>
Sun, 14 Apr 2013 23:03:48 +0000 (19:03 -0400)
committerMike Bayer <mike_mp@zzzcomputing.com>
Sun, 14 Apr 2013 23:03:48 +0000 (19:03 -0400)
- add py3.3 compat, other compat to remove all warnings

alembic/compat.py
alembic/config.py
alembic/util.py
docs/build/tutorial.rst
tests/test_revision_create.py

index 5c9a1ced5eea66bf4d7261d76bb8de97049a94a4..ffc2d9900167efcedb440f1f9c1a08d3702d471d 100644 (file)
@@ -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:
index df20fc6e21fa16304ecda817d03822b0087d683d..c1ad7ecca4db6f19a5f034f5fbdcc019d101d6f2 100644 (file)
@@ -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:
index edaf0ba30a446e058a1c287d52259376ac3bff71..3c227b74e406eb5eb9b619f52e06e2591d554e42 100644 (file)
@@ -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):
 
index 29818d171deead2025a8aa1c0e4dde4cc82a46f7..4b76f2985809e7147aeb8d12e8ad25a0fb32cd32 100644 (file)
@@ -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
 ===========
 
index fd9a7ed74aeb4eb06e52a7491a94df1657479031..a74346e85555d631f24c7c521db636d9de6947aa 100644 (file)
@@ -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