From 7cd6518b586dc023ed9b1034f2e7ca1e45d884cc Mon Sep 17 00:00:00 2001 From: Ronald Oussoren Date: Sun, 3 Apr 2022 14:44:01 +0200 Subject: [PATCH] Fix some incompatibilies with python 2.7 Issue #406 --- doc/changelog.rst | 9 +++++++++ py2app/apptemplate/lib/site.py | 19 +++++++------------ py2app/recipes/qt5.py | 9 ++++++--- py2app/recipes/qt6.py | 4 +++- 4 files changed, 25 insertions(+), 16 deletions(-) diff --git a/doc/changelog.rst b/doc/changelog.rst index 21bfcc9..ee36074 100644 --- a/doc/changelog.rst +++ b/doc/changelog.rst @@ -4,6 +4,15 @@ Release history py2app 0.28 ----------- +* #406: Fix incompatibility with python 2.7 + + py2app 0.24 accidently broke compatibility with Python 2.7, and + this release fixes this. + + This is the last release with Python 2.7 support, the next + release will contain package metadata that ensures it can + only be installed on Python 3. + * #413: Find dist-info in included pythonXX.zip By default the ``working_set`` of pkg_resources does not contain diff --git a/py2app/apptemplate/lib/site.py b/py2app/apptemplate/lib/site.py index 7999a25..c765f9e 100644 --- a/py2app/apptemplate/lib/site.py +++ b/py2app/apptemplate/lib/site.py @@ -23,13 +23,7 @@ USER_SITE = None USER_BASE = None - -def _import_os(): - global os - import os # noqa: E402 - - -_import_os() +import os try: basestring @@ -197,12 +191,13 @@ def getusersitepackages(): if hasattr(sys, "setdefaultencoding"): del sys.setdefaultencoding -import builtins # noqa: E402 -import _sitebuiltins # noqa: E402 +if sys.version_info[0] == 3: + import builtins # noqa: E402 + import _sitebuiltins # noqa: E402 -builtins.help = _sitebuiltins._Helper() -builtins.quit = _sitebuiltins.Quitter('quit', 'Ctrl-D (i.e. EOF)') -builtins.exit = _sitebuiltins.Quitter('exit', 'Ctrl-D (i.e. EOF)') + builtins.help = _sitebuiltins._Helper() + builtins.quit = _sitebuiltins.Quitter('quit', 'Ctrl-D (i.e. EOF)') + builtins.exit = _sitebuiltins.Quitter('exit', 'Ctrl-D (i.e. EOF)') # Prefixes for site-packages; add additional prefixes like /usr/local here PREFIXES = [sys.prefix, sys.exec_prefix] diff --git a/py2app/recipes/qt5.py b/py2app/recipes/qt5.py index 1f9bc8f..969d696 100644 --- a/py2app/recipes/qt5.py +++ b/py2app/recipes/qt5.py @@ -53,12 +53,15 @@ def check(cmd, mf): extra = {} if sys.version[0] != 2: - return { + result = { "packages": ["PyQt5"], "expected_missing_imports": {"copy_reg", "cStringIO", "StringIO"}, - **extra, } + result.update(extra) + return result else: - return {"packages": ["PyQt5"], **extra} + result = {"packages": ["PyQt5"]} + result.update(extra) + return result return None diff --git a/py2app/recipes/qt6.py b/py2app/recipes/qt6.py index 0acc521..8387ee6 100644 --- a/py2app/recipes/qt6.py +++ b/py2app/recipes/qt6.py @@ -51,6 +51,8 @@ def check(cmd, mf): except ImportError: mf.import_hook("sip", m, level=1) - return {"packages": ["PyQt6"], **extra} + reslt = {"packages": ["PyQt6"] } + result.update(extra) + return result return None