From a5c9907d40b4846175106c098bc0aef9801c786b Mon Sep 17 00:00:00 2001 From: Mike Bayer Date: Sun, 28 Apr 2013 15:01:26 -0400 Subject: [PATCH] don't need 2to3 --- README.py3k | 50 ++----------------------------------- sa2to3.py | 72 ----------------------------------------------------- setup.py | 72 +++++++++++++++-------------------------------------- 3 files changed, 22 insertions(+), 172 deletions(-) delete mode 100644 sa2to3.py diff --git a/README.py3k b/README.py3k index 1cf9c3588f..2afaeb6880 100644 --- a/README.py3k +++ b/README.py3k @@ -2,51 +2,5 @@ PYTHON 3 SUPPORT ================= -Current Python 3k support in SQLAlchemy is provided by a customized -2to3 script which wraps Python's 2to3 tool. - -Installing Distribute ---------------------- - -Distribute should be installed with the Python3 installation. The -distribute bootloader is included. - -Running as a user with permission to modify the Python distribution, -install Distribute: - - python3 distribute_setup.py - - -Installing SQLAlchemy in Python 3 ---------------------------------- - -Once Distribute is installed, SQLAlchemy can be installed directly. -The 2to3 process will kick in which takes several minutes: - - python3 setup.py install - -Converting Tests, Examples, Source to Python 3 ----------------------------------------------- - -To convert all files in the source distribution, run -SQLAlchemys "sa2to3.py" script, which monkeypatches a preprocessor -onto the 2to3 tool: - - python3 sa2to3.py --no-diffs -w lib test examples - -The above will rewrite all files in-place in Python 3 format. - -Running Tests -------------- - -To run unit tests in Py3k, Nose 1.0 is required, or a development -version of Nose that supports Python 3. The tests are run -using ./sqla_nose.py as described in README.unittests. - -Current 3k Issues ------------------ - -Current bugs and tickets related to Py3k are on the Py3k milestone in trac: - -http://www.sqlalchemy.org/trac/query?status=new&status=assigned&status=reopened&milestone=py3k - +As of SQLAlchemy 0.9, SQLAlchemy installs and runs with +Python 3 directly, with no code changes. diff --git a/sa2to3.py b/sa2to3.py deleted file mode 100644 index 8c09540a1a..0000000000 --- a/sa2to3.py +++ /dev/null @@ -1,72 +0,0 @@ -"""SQLAlchemy 2to3 tool. - -This tool monkeypatches a preprocessor onto -lib2to3.refactor.RefactoringTool, so that conditional -sections can replace non-fixable Python 2 code sections -for the appropriate Python 3 version before 2to3 is run. - -""" - -from lib2to3 import main, refactor - -import re - -py3k_pattern = re.compile(r'\s*# Py3K') -comment_pattern = re.compile(r'(\s*)#(?! ?Py2K)(.*)') -py2k_pattern = re.compile(r'\s*# Py2K') -end_py2k_pattern = re.compile(r'\s*# end Py2K') - -def preprocess(data): - lines = data.split('\n') - def consume_normal(): - while lines: - line = lines.pop(0) - if py3k_pattern.match(line): - for line in consume_py3k(): - yield line - elif py2k_pattern.match(line): - for line in consume_py2k(): - yield line - else: - yield line - - def consume_py3k(): - yield "# start Py3K" - while lines: - line = lines.pop(0) - m = comment_pattern.match(line) - if m: - yield "%s%s" % m.group(1, 2) - else: - # pushback - lines.insert(0, line) - break - yield "# end Py3K" - - def consume_py2k(): - yield "# start Py2K" - while lines: - line = lines.pop(0) - if not end_py2k_pattern.match(line): - yield "#%s" % line - else: - break - yield "# end Py2K" - - return "\n".join(consume_normal()) - -old_refactor_string = refactor.RefactoringTool.refactor_string - -def refactor_string(self, data, name): - newdata = preprocess(data) - tree = old_refactor_string(self, newdata, name) - if tree: - if newdata != data: - tree.was_changed = True - return tree - -if __name__ == '__main__': - refactor.RefactoringTool.refactor_string = refactor_string - main.main("lib2to3.fixes") - - diff --git a/setup.py b/setup.py index 2950a12d40..97212b55e0 100644 --- a/setup.py +++ b/setup.py @@ -17,26 +17,16 @@ except ImportError: has_setuptools = False from distutils.core import setup, Extension Feature = None - try: # Python 3 - from distutils.command.build_py import build_py_2to3 as build_py - except ImportError: # Python 2 - from distutils.command.build_py import build_py cmdclass = {} pypy = hasattr(sys, 'pypy_version_info') jython = sys.platform.startswith('java') py3k = False extra = {} -if sys.version_info < (2, 4): - raise Exception("SQLAlchemy requires Python 2.4 or higher.") +if sys.version_info < (2, 6): + raise Exception("SQLAlchemy requires Python 2.6 or higher.") elif sys.version_info >= (3, 0): py3k = True - if has_setuptools: - extra.update( - use_2to3=True, - ) - else: - cmdclass['build_py'] = build_py ext_modules = [ Extension('sqlalchemy.cprocessors', @@ -48,7 +38,7 @@ ext_modules = [ ] ext_errors = (CCompilerError, DistutilsExecError, DistutilsPlatformError) -if sys.platform == 'win32' and sys.version_info > (2, 6): +if sys.platform == 'win32': # 2.6's distutils.msvc9compiler can raise an IOError when failing to # find the compiler ext_errors += (IOError,) @@ -90,8 +80,7 @@ def find_packages(location): packages = [] for pkg in ['sqlalchemy']: for _dir, subdirectories, files in ( - os.walk(os.path.join(location, pkg)) - ): + os.walk(os.path.join(location, pkg))): if '__init__.py' in files: tokens = _dir.split(os.sep)[len(location.split(os.sep)):] packages.append(".".join(tokens)) @@ -121,20 +110,20 @@ def run_setup(with_cext): kwargs['ext_modules'] = ext_modules setup(name="SQLAlchemy", - version=VERSION, - description="Database Abstraction Library", - author="Mike Bayer", - author_email="mike_mp@zzzcomputing.com", - url="http://www.sqlalchemy.org", - packages=find_packages('lib'), - package_dir={'': 'lib'}, - license="MIT License", - cmdclass=cmdclass, - - tests_require=['nose >= 0.11'], - test_suite="sqla_nose", - long_description=readme, - classifiers=[ + version=VERSION, + description="Database Abstraction Library", + author="Mike Bayer", + author_email="mike_mp@zzzcomputing.com", + url="http://www.sqlalchemy.org", + packages=find_packages('lib'), + package_dir={'': 'lib'}, + license="MIT License", + cmdclass=cmdclass, + + tests_require=['nose >= 0.11'], + test_suite="sqla_nose", + long_description=readme, + classifiers=[ "Development Status :: 5 - Production/Stable", "Intended Audience :: Developers", "License :: OSI Approved :: MIT License", @@ -149,28 +138,8 @@ def run_setup(with_cext): **kwargs ) -def monkeypatch2to3(): - from sa2to3 import refactor_string - from lib2to3.refactor import RefactoringTool - RefactoringTool.old_refactor_string = RefactoringTool.refactor_string - RefactoringTool.refactor_string = refactor_string - -def unmonkeypatch2to3(): - from lib2to3.refactor import RefactoringTool - if hasattr(RefactoringTool, 'old_refactor_string'): - RefactoringTool.refactor_string = RefactoringTool.old_refactor_string - if pypy or jython or py3k: - if py3k: - # monkeypatch our preprocessor onto the 2to3 tool. - monkeypatch2to3() - try: - run_setup(False) - finally: - if py3k: - # unmonkeypatch to not stomp other setup.py's that are compiled - # and exec'd and which also require 2to3 fixing - unmonkeypatch2to3() + run_setup(False) status_msgs( "WARNING: C extensions are not supported on " + "this Python platform, speedups are not enabled.", @@ -179,8 +148,7 @@ if pypy or jython or py3k: else: try: run_setup(True) - except BuildFailed: - exc = sys.exc_info()[1] # work around py 2/3 different syntax + except BuildFailed as exc: status_msgs( exc.cause, "WARNING: The C extension could not be compiled, " + -- 2.47.3