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
=== modified file 'setup.py'
--- setup.py 2010-05-27 02:00:27 +0000
+++ setup.py 2010-06-22 04:17:23 +0000
@@ -125,9 +125,10 @@
125 f = file(batch_path, "w")125 f = file(batch_path, "w")
126 f.write(batch_str)126 f.write(batch_str)
127 f.close()127 f.close()
128 print "Created:", batch_path128 print("Created: %s" % batch_path)
129 except Exception, e:129 except Exception:
130 print "ERROR: Unable to create %s: %s" % (batch_path, e)130 e = sys.exc_info()[1]
131 print("ERROR: Unable to create %s: %s" % (batch_path, e))
131132
132 def _quoted_path(self, path):133 def _quoted_path(self, path):
133 if ' ' in path:134 if ' ' in path:
@@ -171,18 +172,18 @@
171 from Pyrex.Distutils import build_ext172 from Pyrex.Distutils import build_ext
172 from Pyrex.Compiler.Version import version as pyrex_version173 from Pyrex.Compiler.Version import version as pyrex_version
173 except ImportError:174 except ImportError:
174 print "No Pyrex, trying Cython..."175 print("No Pyrex, trying Cython...")
175 from Cython.Distutils import build_ext176 from Cython.Distutils import build_ext
176 from Cython.Compiler.Version import version as pyrex_version177 from Cython.Compiler.Version import version as pyrex_version
177except ImportError:178except ImportError:
178 have_pyrex = False179 have_pyrex = False
179 # try to build the extension from the prior generated source.180 # try to build the extension from the prior generated source.
180 print181 print("")
181 print ("The python package 'Pyrex' is not available."182 print("The python package 'Pyrex' is not available."
182 " If the .c files are available,")183 " If the .c files are available,")
183 print ("they will be built,"184 print("they will be built,"
184 " but modifying the .pyx files will not rebuild them.")185 " but modifying the .pyx files will not rebuild them.")
185 print186 print("")
186 from distutils.command.build_ext import build_ext187 from distutils.command.build_ext import build_ext
187else:188else:
188 have_pyrex = True189 have_pyrex = True
@@ -204,7 +205,8 @@
204 def run(self):205 def run(self):
205 try:206 try:
206 build_ext.run(self)207 build_ext.run(self)
207 except DistutilsPlatformError, e:208 except DistutilsPlatformError:
209 e = sys.exc_info()[1]
208 if not self.allow_python_fallback:210 if not self.allow_python_fallback:
209 log.warn('\n Cannot build extensions.\n'211 log.warn('\n Cannot build extensions.\n'
210 ' Use "build_ext --allow-python-fallback" to use'212 ' Use "build_ext --allow-python-fallback" to use'
@@ -289,11 +291,11 @@
289 # which is NULL safe with PY_DECREF which is not.)291 # which is NULL safe with PY_DECREF which is not.)
290 # <https://bugs.edge.launchpad.net/bzr/+bug/449372>292 # <https://bugs.edge.launchpad.net/bzr/+bug/449372>
291 # <https://bugs.edge.launchpad.net/bzr/+bug/276868>293 # <https://bugs.edge.launchpad.net/bzr/+bug/276868>
292 print 'Cannot build extension "bzrlib._dirstate_helpers_pyx" using'294 print('Cannot build extension "bzrlib._dirstate_helpers_pyx" using')
293 print 'your version of pyrex "%s". Please upgrade your pyrex' % (295 print('your version of pyrex "%s". Please upgrade your pyrex' % (
294 pyrex_version,)296 pyrex_version,))
295 print 'install. For now, the non-compiled (python) version will'297 print('install. For now, the non-compiled (python) version will')
296 print 'be used instead.'298 print('be used instead.')
297 else:299 else:
298 add_pyrex_extension('bzrlib._dirstate_helpers_pyx')300 add_pyrex_extension('bzrlib._dirstate_helpers_pyx')
299 add_pyrex_extension('bzrlib._readdir_pyx')301 add_pyrex_extension('bzrlib._readdir_pyx')
@@ -301,12 +303,12 @@
301ext_modules.append(Extension('bzrlib._patiencediff_c',303ext_modules.append(Extension('bzrlib._patiencediff_c',
302 ['bzrlib/_patiencediff_c.c']))304 ['bzrlib/_patiencediff_c.c']))
303if have_pyrex and pyrex_version_info < (0, 9, 6, 3):305if have_pyrex and pyrex_version_info < (0, 9, 6, 3):
304 print306 print("")
305 print 'Your Pyrex/Cython version %s is too old to build the simple_set' % (307 print('Your Pyrex/Cython version %s is too old to build the simple_set' % (
306 pyrex_version)308 pyrex_version))
307 print 'and static_tuple extensions.'309 print('and static_tuple extensions.')
308 print 'Please upgrade to at least Pyrex 0.9.6.3'310 print('Please upgrade to at least Pyrex 0.9.6.3')
309 print311 print("")
310 # TODO: Should this be a fatal error?312 # TODO: Should this be a fatal error?
311else:313else:
312 # We only need 0.9.6.3 to build _simple_set_pyx, but static_tuple depends314 # We only need 0.9.6.3 to build _simple_set_pyx, but static_tuple depends
@@ -318,10 +320,10 @@
318320
319321
320if unavailable_files:322if unavailable_files:
321 print 'C extension(s) not found:'323 print('C extension(s) not found:')
322 print ' %s' % ('\n '.join(unavailable_files),)324 print(' %s' % ('\n '.join(unavailable_files),))
323 print 'The python versions will be used instead.'325 print('The python versions will be used instead.')
324 print326 print("")
325327
326328
327def get_tbzr_py2exe_info(includes, excludes, packages, console_targets,329def get_tbzr_py2exe_info(includes, excludes, packages, console_targets,
@@ -677,8 +679,8 @@
677 # print this warning to stderr as output is redirected, so it is seen679 # print this warning to stderr as output is redirected, so it is seen
678 # at build time. Also to stdout so it appears in the log680 # at build time. Also to stdout so it appears in the log
679 for f in (sys.stderr, sys.stdout):681 for f in (sys.stderr, sys.stdout):
680 print >> f, \682 f.write("Skipping TBZR binaries - "
681 "Skipping TBZR binaries - please set TBZR to a directory to enable"683 "please set TBZR to a directory to enable\n")
682684
683 # MSWSOCK.dll is a system-specific library, which py2exe accidentally pulls685 # MSWSOCK.dll is a system-specific library, which py2exe accidentally pulls
684 # in on Vista.686 # in on Vista.
@@ -691,14 +693,14 @@
691 "optimize": 2,693 "optimize": 2,
692 },694 },
693 }695 }
694696 if __name__ == '__main__':
695 setup(options=options_list,697 setup(options=options_list,
696 console=console_targets,698 console=console_targets,
697 windows=gui_targets,699 windows=gui_targets,
698 zipfile='lib/library.zip',700 zipfile='lib/library.zip',
699 data_files=data_files,701 data_files=data_files,
700 cmdclass={'install_data': install_data_with_bytecompile},702 cmdclass={'install_data': install_data_with_bytecompile},
701 )703 )
702704
703else:705else:
704 # ad-hoc for easy_install706 # ad-hoc for easy_install
@@ -732,4 +734,5 @@
732 ARGS.update(BZRLIB)734 ARGS.update(BZRLIB)
733 ARGS.update(PKG_DATA)735 ARGS.update(PKG_DATA)
734736
735 setup(**ARGS)737 if __name__ == '__main__':
738 setup(**ARGS)