]> git.ipfire.org Git - thirdparty/sqlalchemy/alembic.git/commitdiff
- will call this 0.6
authorMike Bayer <mike_mp@zzzcomputing.com>
Sat, 13 Apr 2013 00:10:56 +0000 (20:10 -0400)
committerMike Bayer <mike_mp@zzzcomputing.com>
Sat, 13 Apr 2013 00:10:56 +0000 (20:10 -0400)
- cleanup unused symbols in compat
- move any remaining conditional import switches out to compat
- pretty sure anything we use for a buffer will have flush()
- I can see that using the new io.* stuff means codecs isn't too
smooth here, but removed the double-wrap check in migration.py
which seems to be due to the bytesio setup in the test suite, simplified
this so that an encoding-writing test just writes to BytesIO
- removed all "from __future__ import with_statement"
- i think when we load_source(), that file might not be ascii
so we need to open as bytes
- make encoding an explcit argument in test suite write_script()
- sort the columns in autogenerate so that the autogen tests run
consistently on python3.3, seems to have a very random set ordering,
also loosen up an ordered check in test_op

15 files changed:
alembic/__init__.py
alembic/autogenerate.py
alembic/compat.py
alembic/config.py
alembic/ddl/impl.py
alembic/migration.py
alembic/script.py
alembic/util.py
tests/__init__.py
tests/test_mssql.py
tests/test_op.py
tests/test_oracle.py
tests/test_postgresql.py
tests/test_sql_script.py
tests/test_versioning.py

index 0625c43224a186852dc2dbd7a8e5acbd6f28490c..7467b27332ce62e822dcaca0e6c74ae9f1f97310 100644 (file)
@@ -1,6 +1,6 @@
 from os import path
 
-__version__ = '0.5.0'
+__version__ = '0.6.0'
 
 package_dir = path.abspath(path.dirname(__file__))
 
index 348079a05d3041b3b546305eb6475768f12019ce..6aaf2c589b27d882042293d12a0b7fd9e3c0afc4 100644 (file)
@@ -240,7 +240,7 @@ def _compare_columns(schema, tname, conn_table, metadata_table,
     name = '%s.%s' % (schema, tname) if schema else tname
     metadata_cols_by_name = dict((c.name, c) for c in metadata_table.c)
     conn_col_names = set(conn_table)
-    metadata_col_names = set(metadata_cols_by_name)
+    metadata_col_names = OrderedSet(sorted(metadata_cols_by_name))
 
     for cname in metadata_col_names.difference(conn_col_names):
         diffs.append(
index b994eb5856033b67717d4896092cd00b6ced910c..5c9a1ced5eea66bf4d7261d76bb8de97049a94a4 100644 (file)
@@ -1,31 +1,37 @@
 import sys
 
+if sys.version_info < (2, 6):
+    raise NotImplementedError("Python 2.6 or greater is required.")
 
 py3k = sys.version_info >= (3, 0)
-py3kwarning = getattr(sys, 'py3kwarning', False) or py3k
-py26 = sys.version_info >= (2, 6)
-jython = sys.platform.startswith('java')
-win32 = sys.platform.startswith('win')
-pypy = hasattr(sys, 'pypy_version_info')
 
 if py3k:
     import builtins as compat_builtins
     string_types = str,
     binary_type = bytes
     text_type = str
+    def callable(fn):
+        return hasattr(fn, '__call__')
 else:
     import __builtin__ as compat_builtins
     string_types = basestring,
     binary_type = str
     text_type = unicode
-
-if py3kwarning:
-    def callable(fn):
-        return hasattr(fn, '__call__')
-else:
     callable = callable
 
 
+try:
+    import configparser
+except ImportError:
+    import ConfigParser as configparser
+
+try:
+    exec_ = getattr(compat_builtins, 'exec')
+except AttributeError:
+    # Python 2
+    def exec_(func_text, globals_, lcl):
+        exec('exec func_text in globals_, lcl')
+
 ################################################
 # cross-compatible metaclass implementation
 # Copyright (c) 2010-2012 Benjamin Peterson
index e6b09d2e57cb991ad700adfa26729f5f7032cac1..5658e960b9bc83c1997b43d4c3f434b20754fd72 100644 (file)
@@ -1,8 +1,5 @@
 from argparse import ArgumentParser
-try:
-    import configparser
-except ImportError:
-    import ConfigParser as configparser
+from .compat import configparser
 import inspect
 import os
 import sys
index a7b6429df027fb3b6e2fe426411713b4ff3a998a..2bb672c937d8654f4940521d6e71c93c712d9ee1 100644 (file)
@@ -1,14 +1,9 @@
-try:
-    import builtins
-except ImportError:
-    import __builtin__ as builtins
-
 from sqlalchemy.sql.expression import _BindParamClause
 from sqlalchemy.ext.compiler import compiles
 from sqlalchemy import schema, text
 from sqlalchemy import types as sqltypes
 
-from ..compat import callable, string_types, text_type, with_metaclass
+from ..compat import string_types, text_type, with_metaclass
 from .. import util
 from . import base
 
@@ -55,10 +50,8 @@ class DefaultImpl(with_metaclass(ImplMeta)):
         return _impls[dialect.name]
 
     def static_output(self, text):
-        text_ = text_type(text + '\n\n')
-        self.output_buffer.write(text_)
-        if callable(getattr(self.output_buffer, 'flush', None)):
-            self.output_buffer.flush()
+        self.output_buffer.write(text_type(text + "\n\n"))
+        self.output_buffer.flush()
 
     @property
     def bind(self):
index 28ee622ded3f6376d836486e5ed2b764d49c4f8c..cdd244a4220a6eff463aca0fea5ff2017b3d61e6 100644 (file)
@@ -72,8 +72,8 @@ class MigrationContext(object):
         self._migrations_fn = opts.get('fn')
         self.as_sql = as_sql
         self.output_buffer = opts.get("output_buffer", sys.stdout)
-        if (opts.get('output_encoding') and
-            not isinstance(self.output_buffer, io.TextIOBase)):
+
+        if opts.get('output_encoding'):
             self.output_buffer = io.TextIOWrapper(
                                     self.output_buffer,
                                     opts['output_encoding']
index 53dbb2e5b889e334e1794cc0846af61aa741ea25..229407b17374140b01ae0cffcff9adf93b5bd59f 100644 (file)
@@ -1,5 +1,3 @@
-from __future__ import with_statement
-
 import datetime
 import os
 import re
index 708f19f65df276f62c6e441ef042f9b7f6c4564c..edaf0ba30a446e058a1c287d52259376ac3bff71 100644 (file)
@@ -1,9 +1,3 @@
-from __future__ import with_statement
-
-try:
-    import builtins
-except ImportError:
-    import __builtin__ as builtins
 import sys
 import os
 import textwrap
@@ -17,7 +11,7 @@ from mako.template import Template
 from sqlalchemy.engine import url
 from sqlalchemy import __version__
 
-from .compat import callable
+from .compat import callable, exec_
 
 class CommandError(Exception):
     pass
@@ -120,12 +114,6 @@ def create_module_class_proxy(cls, globals_, locals_):
             'doc': fn.__doc__,
         })
         lcl = {}
-        try:
-            exec_ = getattr(builtins, 'exec')
-        except AttributeError:
-            # Python 2
-            def exec_(func_text, globals_, lcl):
-                exec('exec func_text in globals_, lcl')
         exec_(func_text, globals_, lcl)
         return lcl[name]
 
@@ -187,7 +175,7 @@ def load_python_file(dir_, filename):
 
     module_id = re.sub(r'\W', "_", filename)
     path = os.path.join(dir_, filename)
-    with open(path, 'r') as f:
+    with open(path, 'rb') as f:
         module = imp.load_source(module_id, path, f)
     del sys.modules[module_id]
     return module
index b838f38484e6ae06be90715f8dade7b253cbf959..6c36fcb83bbe70cffbe8c41d5468717d0b40ec83 100644 (file)
@@ -1,18 +1,10 @@
-from __future__ import with_statement
-
-try:
-    import builtins
-except ImportError:
-    import __builtin__ as builtins
-try:
-    import configparser
-except ImportError:
-    import ConfigParser as configparser
+
 import io
 import os
 import re
 import shutil
 import textwrap
+from alembic.compat import configparser
 
 from nose import SkipTest
 from sqlalchemy.engine import default
@@ -63,7 +55,7 @@ def db_for_dialect(name):
         except ImportError as er1:
             raise SkipTest("Can't import DBAPI: %s" % er1)
         try:
-            conn = eng.connect()
+            eng.connect()
         except SQLAlchemyError as er2:
             raise SkipTest("Can't connect to database: %s" % er2)
         _engs[name] = eng
@@ -105,23 +97,20 @@ def assert_compiled(element, assert_string, dialect=None):
 
 def capture_context_buffer(**kw):
     if kw.pop('bytes_io', False):
-        raw = io.BytesIO()
-        encoding = kw.get('output_encoding', 'utf-8')
-        buf = io.TextIOWrapper(raw, encoding)
+        buf = io.BytesIO()
     else:
-        raw = buf = io.StringIO()
+        buf = io.StringIO()
 
     class capture(object):
         def __enter__(self):
             EnvironmentContext._default_opts = {
-                'dialect_name':"sqlite",
-                'output_buffer':buf
+                'dialect_name': "sqlite",
+                'output_buffer': buf
             }
             EnvironmentContext._default_opts.update(kw)
-            return raw
+            return buf
 
         def __exit__(self, *arg, **kwarg):
-            #print(buf.getvalue())
             EnvironmentContext._default_opts = None
 
     return capture()
@@ -317,13 +306,15 @@ def clear_staging_env():
     shutil.rmtree(staging_directory, True)
 
 
-def write_script(scriptdir, rev_id, content):
+def write_script(scriptdir, rev_id, content, encoding='ascii'):
     old = scriptdir._revision_map[rev_id]
     path = old.path
-    if not hasattr(builtins, 'unicode') and isinstance(content, bytes):
-        content = content.decode()
-    with open(path, 'w') as fp:
-        fp.write(textwrap.dedent(content))
+
+    content = textwrap.dedent(content)
+    if encoding:
+        content = content.encode(encoding)
+    with open(path, 'wb') as fp:
+        fp.write(content)
     pyc_path = util.pyc_file_from_path(path)
     if os.access(pyc_path, os.F_OK):
         os.unlink(pyc_path)
index 398d22884b0d0606a58919c7fdf935994ecd969d..a320d4aafd7e14e988f17cb59bd015ea97145db8 100644 (file)
@@ -1,5 +1,4 @@
 """Test op functions against MSSQL."""
-from __future__ import with_statement
 
 from unittest import TestCase
 
index 9d6a2d211d7c01e612de4ff42b7a093210484840..e7845ee48977def62652d7db91c4951fac15dfe8 100644 (file)
@@ -637,7 +637,7 @@ def test_naming_changes():
 
     assert_raises_message(
         TypeError,
-        "Unknown arguments: badarg2, badarg1",
+        r"Unknown arguments: badarg\d, badarg\d",
         op.alter_column, "t", "c", badarg1="x", badarg2="y"
     )
 
index ae9677d20b5a5928cb010d5ada135ae5bae1ecee..d443a71fc4d1eeb32d1e0b5bf291ce83cb337261 100644 (file)
@@ -1,5 +1,4 @@
 """Test op functions against ORACLE."""
-from __future__ import with_statement
 
 from unittest import TestCase
 
index 3c0bb3985c85ba37588d47a3a73d08575cdff76a..047ac92dc74e5cbc976d12b9e657ebff4a2025bc 100644 (file)
@@ -1,5 +1,3 @@
-from __future__ import with_statement
-
 from unittest import TestCase
 
 from sqlalchemy import DateTime, MetaData, Table, Column, text, Integer, String
index d351151376b441a862e3611770adbe6c639e72f7..31b74d8afd6e4b03557408dcb8398c9f8e73cd47 100644 (file)
@@ -105,7 +105,7 @@ def upgrade():
 def downgrade():
     op.execute("drôle de petite voix m’a réveillé")
 
-""" % a).encode('utf-8'))
+""" % a), encoding='utf-8')
 
     def tearDown(self):
         clear_staging_env()
index 84dd777bdfe454c24e2003d2c9c18ad72693002e..91163c9d0f303cc23bb3ee5232e743052c6368df 100644 (file)
@@ -1,5 +1,3 @@
-from __future__ import with_statement
-
 import os
 import unittest