Merge lp:~lifeless/bzr/py3 into lp:bzr

Proposed by Robert Collins
Status: Merged
Approved by: John A Meinel
Approved revision: no longer in the revision history of the source branch.
Merged at revision: 5314
Proposed branch: lp:~lifeless/bzr/py3
Merge into: lp:bzr
Diff against target: 145 lines (+40/-37)
1 file modified
setup.py (+40/-37)
To merge this branch: bzr merge lp:~lifeless/bzr/py3
Reviewer Review Type Date Requested Status
John A Meinel Needs Fixing
Review via email: mp+28113@code.launchpad.net

Commit message

Make setup.py python 3.1 compatible.

Description of the change

Make setup.py importable under python3.1.

To post a comment you must log in.
lp:~lifeless/bzr/py3 updated
5312. By Canonical.com Patch Queue Manager <email address hidden>

(lifeless) Return self from the new context managers so that new objects
 used with with statements are usable. (Robert Collins)

Revision history for this message
John A Meinel (jameinel) wrote :

This isn't completely correct yet. For example:

8 - print "Created:", batch_path
9 - except Exception, e:
10 - print "ERROR: Unable to create %s: %s" % (batch_path, e)
11 + print("Created:", batch_path)
12 + except Exception:
13 + e = sys.exc_info()[1]
14 + print("ERROR: Unable to create %s: %s" % (batch_path, e))

In python2.6 this will print:

('Created:', 'the-batch-path')

You need to you use the %s form:

print("Created: %s" % (batch_path,))

I don't really like that the code is even uglier (setup.py is pretty messy to start with). I'm not really sure the benefit of making it 3.x compatible, given that the rest of the code isn't, but I guess you have to start somewhere.

review: Needs Fixing
Revision history for this message
Robert Collins (lifeless) wrote :

sent to pqm by email

lp:~lifeless/bzr/py3 updated
5313. By Canonical.com Patch Queue Manager <email address hidden>

(lifeless) Cleanup add.py. (Robert Collins)

5314. By Canonical.com Patch Queue Manager <email address hidden>

(lifeless) Make setup.py python 3.1 compatible. (Robert Collins)

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'setup.py'
2--- setup.py 2010-05-27 02:00:27 +0000
3+++ setup.py 2010-06-22 04:17:23 +0000
4@@ -125,9 +125,10 @@
5 f = file(batch_path, "w")
6 f.write(batch_str)
7 f.close()
8- print "Created:", batch_path
9- except Exception, e:
10- print "ERROR: Unable to create %s: %s" % (batch_path, e)
11+ print("Created: %s" % batch_path)
12+ except Exception:
13+ e = sys.exc_info()[1]
14+ print("ERROR: Unable to create %s: %s" % (batch_path, e))
15
16 def _quoted_path(self, path):
17 if ' ' in path:
18@@ -171,18 +172,18 @@
19 from Pyrex.Distutils import build_ext
20 from Pyrex.Compiler.Version import version as pyrex_version
21 except ImportError:
22- print "No Pyrex, trying Cython..."
23+ print("No Pyrex, trying Cython...")
24 from Cython.Distutils import build_ext
25 from Cython.Compiler.Version import version as pyrex_version
26 except ImportError:
27 have_pyrex = False
28 # try to build the extension from the prior generated source.
29- print
30- print ("The python package 'Pyrex' is not available."
31- " If the .c files are available,")
32- print ("they will be built,"
33- " but modifying the .pyx files will not rebuild them.")
34- print
35+ print("")
36+ print("The python package 'Pyrex' is not available."
37+ " If the .c files are available,")
38+ print("they will be built,"
39+ " but modifying the .pyx files will not rebuild them.")
40+ print("")
41 from distutils.command.build_ext import build_ext
42 else:
43 have_pyrex = True
44@@ -204,7 +205,8 @@
45 def run(self):
46 try:
47 build_ext.run(self)
48- except DistutilsPlatformError, e:
49+ except DistutilsPlatformError:
50+ e = sys.exc_info()[1]
51 if not self.allow_python_fallback:
52 log.warn('\n Cannot build extensions.\n'
53 ' Use "build_ext --allow-python-fallback" to use'
54@@ -289,11 +291,11 @@
55 # which is NULL safe with PY_DECREF which is not.)
56 # <https://bugs.edge.launchpad.net/bzr/+bug/449372>
57 # <https://bugs.edge.launchpad.net/bzr/+bug/276868>
58- print 'Cannot build extension "bzrlib._dirstate_helpers_pyx" using'
59- print 'your version of pyrex "%s". Please upgrade your pyrex' % (
60- pyrex_version,)
61- print 'install. For now, the non-compiled (python) version will'
62- print 'be used instead.'
63+ print('Cannot build extension "bzrlib._dirstate_helpers_pyx" using')
64+ print('your version of pyrex "%s". Please upgrade your pyrex' % (
65+ pyrex_version,))
66+ print('install. For now, the non-compiled (python) version will')
67+ print('be used instead.')
68 else:
69 add_pyrex_extension('bzrlib._dirstate_helpers_pyx')
70 add_pyrex_extension('bzrlib._readdir_pyx')
71@@ -301,12 +303,12 @@
72 ext_modules.append(Extension('bzrlib._patiencediff_c',
73 ['bzrlib/_patiencediff_c.c']))
74 if have_pyrex and pyrex_version_info < (0, 9, 6, 3):
75- print
76- print 'Your Pyrex/Cython version %s is too old to build the simple_set' % (
77- pyrex_version)
78- print 'and static_tuple extensions.'
79- print 'Please upgrade to at least Pyrex 0.9.6.3'
80- print
81+ print("")
82+ print('Your Pyrex/Cython version %s is too old to build the simple_set' % (
83+ pyrex_version))
84+ print('and static_tuple extensions.')
85+ print('Please upgrade to at least Pyrex 0.9.6.3')
86+ print("")
87 # TODO: Should this be a fatal error?
88 else:
89 # We only need 0.9.6.3 to build _simple_set_pyx, but static_tuple depends
90@@ -318,10 +320,10 @@
91
92
93 if unavailable_files:
94- print 'C extension(s) not found:'
95- print ' %s' % ('\n '.join(unavailable_files),)
96- print 'The python versions will be used instead.'
97- print
98+ print('C extension(s) not found:')
99+ print(' %s' % ('\n '.join(unavailable_files),))
100+ print('The python versions will be used instead.')
101+ print("")
102
103
104 def get_tbzr_py2exe_info(includes, excludes, packages, console_targets,
105@@ -677,8 +679,8 @@
106 # print this warning to stderr as output is redirected, so it is seen
107 # at build time. Also to stdout so it appears in the log
108 for f in (sys.stderr, sys.stdout):
109- print >> f, \
110- "Skipping TBZR binaries - please set TBZR to a directory to enable"
111+ f.write("Skipping TBZR binaries - "
112+ "please set TBZR to a directory to enable\n")
113
114 # MSWSOCK.dll is a system-specific library, which py2exe accidentally pulls
115 # in on Vista.
116@@ -691,14 +693,14 @@
117 "optimize": 2,
118 },
119 }
120-
121- setup(options=options_list,
122- console=console_targets,
123- windows=gui_targets,
124- zipfile='lib/library.zip',
125- data_files=data_files,
126- cmdclass={'install_data': install_data_with_bytecompile},
127- )
128+ if __name__ == '__main__':
129+ setup(options=options_list,
130+ console=console_targets,
131+ windows=gui_targets,
132+ zipfile='lib/library.zip',
133+ data_files=data_files,
134+ cmdclass={'install_data': install_data_with_bytecompile},
135+ )
136
137 else:
138 # ad-hoc for easy_install
139@@ -732,4 +734,5 @@
140 ARGS.update(BZRLIB)
141 ARGS.update(PKG_DATA)
142
143- setup(**ARGS)
144+ if __name__ == '__main__':
145+ setup(**ARGS)