Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 33b6450

Browse files
committed
Issue #4072: Restore build_py_2to3. Add a distutils demo for
build_py_2to3.
1 parent aa30669 commit 33b6450

6 files changed

Lines changed: 52 additions & 12 deletions

File tree

Demo/distutils/test2to3/README

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
This project demonstrates how a distutils package
2+
can support Python 2.x and Python 3.x from a single
3+
source, using lib2to3.

Demo/distutils/test2to3/setup.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# -*- coding: iso-8859-1 -*-
2+
from distutils.core import setup
3+
4+
try:
5+
from distutils.command.build_py import build_py_2to3 as build_py
6+
except ImportError:
7+
from distutils.command.build_py import build_py
8+
9+
setup(
10+
name = "test2to3",
11+
version = "1.0",
12+
description = "2to3 distutils test package",
13+
author = "Martin v. Löwis",
14+
author_email = "[email protected]",
15+
license = "PSF license",
16+
packages = ["test2to3"],
17+
cmdclass = {'build_py':build_py}
18+
)
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
# empty
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
def hello():
2+
try:
3+
print "Hello, world"
4+
except IOError, e:
5+
print e.errno

Lib/distutils/command/build_py.py

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -384,6 +384,18 @@ def byte_compile(self, files):
384384
byte_compile(files, optimize=self.optimize,
385385
force=self.force, prefix=prefix, dry_run=self.dry_run)
386386

387+
from lib2to3.refactor import RefactoringTool, get_fixers_from_package
388+
class DistutilsRefactoringTool(RefactoringTool):
389+
def log_error(self, msg, *args, **kw):
390+
# XXX ignores kw
391+
log.error(msg, *args)
392+
393+
def log_message(self, msg, *args):
394+
log.info(msg, *args)
395+
396+
def log_debug(self, msg, *args):
397+
log.debug(msg, *args)
398+
387399
class build_py_2to3(build_py):
388400
def run(self):
389401
self.updated_files = []
@@ -396,18 +408,12 @@ def run(self):
396408
self.build_package_data()
397409

398410
# 2to3
399-
from lib2to3.refactor import RefactoringTool
400-
class Options:
401-
pass
402-
o = Options()
403-
o.doctests_only = False
404-
o.fix = []
405-
o.list_fixes = []
406-
o.print_function = False
407-
o.verbose = False
408-
o.write = True
409-
r = RefactoringTool(o)
410-
r.refactor_args(self.updated_files)
411+
fixers = get_fixers_from_package('lib2to3.fixes')
412+
options = dict(fix=[], list_fixes=[],
413+
print_function=False, verbose=False,
414+
write=True)
415+
r = DistutilsRefactoringTool(fixers, options)
416+
r.refactor(self.updated_files, write=True)
411417

412418
# Remaining base class code
413419
self.byte_compile(self.get_outputs(include_bytecode=0))

Misc/NEWS

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@ Core and Builtins
3131
Library
3232
-------
3333

34+
- Issue #4072: Restore build_py_2to3.
35+
3436
- Issue #4014: Don't claim that Python has an Alpha release status, in addition
3537
to claiming it is Mature.
3638

@@ -63,6 +65,11 @@ Build
6365

6466
- Issue #4018: Disable "for me" installations on Vista.
6567

68+
Tools/Demos
69+
-----------
70+
71+
- Issue #4072: Add a distutils demo for build_py_2to3.
72+
6673

6774
What's New in Python 3.0 release candidate 1
6875
============================================

0 commit comments

Comments
 (0)