From 978a6af9e78db44b9db25cb08c7f9d98c24bbc03 Mon Sep 17 00:00:00 2001 From: Laurence Rowe Date: Fri, 29 Mar 2019 18:00:10 -0700 Subject: [PATCH] Avoid DeprecationWarning: 'U' mode is deprecated Python 3.7 began warning about open's 'U' mode. Universal newline mode (newline=None) is default in Python 3 so avoid specifying it on Python 3. --- src/zc/buildout/easy_install.py | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/src/zc/buildout/easy_install.py b/src/zc/buildout/easy_install.py index 5eca9181e..259c6d9f6 100644 --- a/src/zc/buildout/easy_install.py +++ b/src/zc/buildout/easy_install.py @@ -1467,15 +1467,20 @@ def _pyscript(path, dest, rsetup, initialization=''): generated.append(dest) return generated +if sys.version_info[0] < 3: + universal_newline_option = ", 'U'" +else: + universal_newline_option = '' + py_script_template = script_header + '''\ -%(relative_paths_setup)s +%%(relative_paths_setup)s import sys sys.path[0:0] = [ - %(path)s + %%(path)s ] -%(initialization)s +%%(initialization)s _interactive = True if len(sys.argv) > 1: @@ -1496,13 +1501,13 @@ def _pyscript(path, dest, rsetup, initialization=''): sys.argv[:] = _args __file__ = _args[0] del _options, _args - with open(__file__, 'U') as __file__f: + with open(__file__%s) as __file__f: exec(compile(__file__f.read(), __file__, "exec")) if _interactive: del _interactive __import__("code").interact(banner="", local=globals()) -''' +''' % universal_newline_option runsetup_template = """ import sys @@ -1516,9 +1521,9 @@ def _pyscript(path, dest, rsetup, initialization=''): os.chdir(%%(setupdir)r) sys.argv[0] = %%(setup)r -with open(%%(setup)r, 'U') as f: +with open(%%(setup)r%s) as f: exec(compile(f.read(), %%(setup)r, 'exec')) -""" % setuptools_path +""" % (setuptools_path, universal_newline_option) class VersionConflict(zc.buildout.UserError):