From e729a868b91a11eabf88b5c420351a80b43a07fd Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Sun, 25 Nov 2018 21:53:57 +0000 Subject: [PATCH 1/2] Minimum Python version check correction Fixes Recent breakage when using -builtin and %import --- Source/Modules/python.cxx | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/Source/Modules/python.cxx b/Source/Modules/python.cxx index 19798b5f8..b31d9ce8f 100755 --- a/Source/Modules/python.cxx +++ b/Source/Modules/python.cxx @@ -731,7 +731,7 @@ public: * globals()[attr] = getattr(_foo, attr) * */ - Printf(default_import_code, "# pull in all the attributes from %s\n", module); + Printf(default_import_code, "\n# Pull in all the attributes from %s\n", module); Printv(default_import_code, "if __name__.rpartition('.')[0] != '':\n", NULL); Printv(default_import_code, tab4, "if _swig_python_version_info >= (2, 7, 0):\n", NULL); Printv(default_import_code, tab8, "try:\n", NULL); @@ -900,13 +900,14 @@ public: Swig_banner_target_lang(f_shadow_py, "#"); if (Len(f_shadow_begin) > 0) Printv(f_shadow_py, "\n", f_shadow_begin, "\n", NIL); - if (Len(f_shadow_after_begin) > 0) - Printv(f_shadow_py, f_shadow_after_begin, "\n", NIL); Printv(f_shadow_py, "\nfrom sys import version_info as _swig_python_version_info\n", NULL); Printv(f_shadow_py, "if _swig_python_version_info < (2, 7, 0):\n", NULL); Printv(f_shadow_py, tab4, "raise RuntimeError('Python 2.7 or later required')\n\n", NULL); + if (Len(f_shadow_after_begin) > 0) + Printv(f_shadow_py, f_shadow_after_begin, "\n", NIL); + if (moduleimport) { Replaceall(moduleimport, "$module", module); Printv(f_shadow_py, moduleimport, "\n", NIL); From 865dc1e71c3d2f3e35197d2cdd188c4b878cbb7d Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Sun, 25 Nov 2018 22:18:43 +0000 Subject: [PATCH 2/2] Remove Python 2.6 and earlier import code --- Source/Modules/python.cxx | 18 ++++++------------ 1 file changed, 6 insertions(+), 12 deletions(-) diff --git a/Source/Modules/python.cxx b/Source/Modules/python.cxx index b31d9ce8f..1c43383a6 100755 --- a/Source/Modules/python.cxx +++ b/Source/Modules/python.cxx @@ -733,13 +733,10 @@ public: */ Printf(default_import_code, "\n# Pull in all the attributes from %s\n", module); Printv(default_import_code, "if __name__.rpartition('.')[0] != '':\n", NULL); - Printv(default_import_code, tab4, "if _swig_python_version_info >= (2, 7, 0):\n", NULL); - Printv(default_import_code, tab8, "try:\n", NULL); - Printf(default_import_code, tab8 tab4 "from .%s import *\n", module); - Printv(default_import_code, tab8 "except ImportError:\n", NULL); - Printf(default_import_code, tab8 tab4 "from %s import *\n", module); - Printv(default_import_code, tab4, "else:\n", NULL); - Printf(default_import_code, tab8 "from %s import *\n", module); + Printv(default_import_code, tab4, "try:\n", NULL); + Printf(default_import_code, tab4 tab4 "from .%s import *\n", module); + Printv(default_import_code, tab4 "except ImportError:\n", NULL); + Printf(default_import_code, tab4 tab4 "from %s import *\n", module); Printv(default_import_code, "else:\n", NULL); Printf(default_import_code, tab4 "from %s import *\n", module); } @@ -1122,12 +1119,9 @@ public: Printf(out, "import %s%s%s%s\n", apkg, *Char(apkg) ? "." : "", pfx, mod); Delete(apkg); } else { - Printf(out, "if _swig_python_version_info >= (2, 7, 0):\n"); if (py3_rlen1) - Printf(out, tab4 "from . import %.*s\n", py3_rlen1, rpkg); - Printf(out, tab4 "from .%s import %s%s\n", rpkg, pfx, mod); - Printf(out, "else:\n"); - Printf(out, tab4 "import %s%s%s%s\n", rpkg, *Char(rpkg) ? "." : "", pfx, mod); + Printf(out, "from . import %.*s\n", py3_rlen1, rpkg); + Printf(out, "from .%s import %s%s\n", rpkg, pfx, mod); Delete(rpkg); } return out;