From: Mike Bayer Date: Sat, 13 Apr 2013 00:10:56 +0000 (-0400) Subject: - will call this 0.6 X-Git-Tag: rel_0_6_0~21 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=d77b1d838d20d9b57154ce9bbb0c2e5a24c48cb0;p=thirdparty%2Fsqlalchemy%2Falembic.git - will call this 0.6 - 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 --- diff --git a/alembic/__init__.py b/alembic/__init__.py index 0625c432..7467b273 100644 --- a/alembic/__init__.py +++ b/alembic/__init__.py @@ -1,6 +1,6 @@ from os import path -__version__ = '0.5.0' +__version__ = '0.6.0' package_dir = path.abspath(path.dirname(__file__)) diff --git a/alembic/autogenerate.py b/alembic/autogenerate.py index 348079a0..6aaf2c58 100644 --- a/alembic/autogenerate.py +++ b/alembic/autogenerate.py @@ -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( diff --git a/alembic/compat.py b/alembic/compat.py index b994eb58..5c9a1ced 100644 --- a/alembic/compat.py +++ b/alembic/compat.py @@ -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 diff --git a/alembic/config.py b/alembic/config.py index e6b09d2e..5658e960 100644 --- a/alembic/config.py +++ b/alembic/config.py @@ -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 diff --git a/alembic/ddl/impl.py b/alembic/ddl/impl.py index a7b6429d..2bb672c9 100644 --- a/alembic/ddl/impl.py +++ b/alembic/ddl/impl.py @@ -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): diff --git a/alembic/migration.py b/alembic/migration.py index 28ee622d..cdd244a4 100644 --- a/alembic/migration.py +++ b/alembic/migration.py @@ -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'] diff --git a/alembic/script.py b/alembic/script.py index 53dbb2e5..229407b1 100644 --- a/alembic/script.py +++ b/alembic/script.py @@ -1,5 +1,3 @@ -from __future__ import with_statement - import datetime import os import re diff --git a/alembic/util.py b/alembic/util.py index 708f19f6..edaf0ba3 100644 --- a/alembic/util.py +++ b/alembic/util.py @@ -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 diff --git a/tests/__init__.py b/tests/__init__.py index b838f384..6c36fcb8 100644 --- a/tests/__init__.py +++ b/tests/__init__.py @@ -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) diff --git a/tests/test_mssql.py b/tests/test_mssql.py index 398d2288..a320d4aa 100644 --- a/tests/test_mssql.py +++ b/tests/test_mssql.py @@ -1,5 +1,4 @@ """Test op functions against MSSQL.""" -from __future__ import with_statement from unittest import TestCase diff --git a/tests/test_op.py b/tests/test_op.py index 9d6a2d21..e7845ee4 100644 --- a/tests/test_op.py +++ b/tests/test_op.py @@ -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" ) diff --git a/tests/test_oracle.py b/tests/test_oracle.py index ae9677d2..d443a71f 100644 --- a/tests/test_oracle.py +++ b/tests/test_oracle.py @@ -1,5 +1,4 @@ """Test op functions against ORACLE.""" -from __future__ import with_statement from unittest import TestCase diff --git a/tests/test_postgresql.py b/tests/test_postgresql.py index 3c0bb398..047ac92d 100644 --- a/tests/test_postgresql.py +++ b/tests/test_postgresql.py @@ -1,5 +1,3 @@ -from __future__ import with_statement - from unittest import TestCase from sqlalchemy import DateTime, MetaData, Table, Column, text, Integer, String diff --git a/tests/test_sql_script.py b/tests/test_sql_script.py index d3511513..31b74d8a 100644 --- a/tests/test_sql_script.py +++ b/tests/test_sql_script.py @@ -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() diff --git a/tests/test_versioning.py b/tests/test_versioning.py index 84dd777b..91163c9d 100644 --- a/tests/test_versioning.py +++ b/tests/test_versioning.py @@ -1,5 +1,3 @@ -from __future__ import with_statement - import os import unittest