From 458b8faf282cfca5d4692083321ca4109414b4b3 Mon Sep 17 00:00:00 2001 From: Ronald Oussoren Date: Sun, 3 Apr 2022 11:53:30 +0200 Subject: [PATCH] Fix incompatibility with recent versions of setuptools Fixes #412 --- doc/changelog.rst | 5 +++++ py2app/recipes/setuptools.py | 34 ++++++++++++++++++++-------------- 2 files changed, 25 insertions(+), 14 deletions(-) diff --git a/doc/changelog.rst b/doc/changelog.rst index 543f333..01ca9a9 100644 --- a/doc/changelog.rst +++ b/doc/changelog.rst @@ -7,6 +7,11 @@ py2app 0.28 * Fix hard crash in "rtree" recipe when the package contents doesn't match the recipe expectations. +* #412: Fix incompatibility with setuptools 60.8.1 + + The setuptools recipe did not recoginize all vendored dependencies + in ``pkg_resources`` and that breaks app bundles that use ``pkg_resoures``. + * PR #388: Add builtin definitions for 'quit' and 'exit' in site.py PR by mcclary diff --git a/py2app/recipes/setuptools.py b/py2app/recipes/setuptools.py index b4b19d7..7c223a0 100644 --- a/py2app/recipes/setuptools.py +++ b/py2app/recipes/setuptools.py @@ -17,23 +17,29 @@ def check(cmd, mf): } if os.path.exists(vendor_dir): - for nm in os.listdir(vendor_dir): - if nm in ("__pycache__", "__init__.py"): continue - if nm.endswith(".py"): - mf.import_hook("pkg_resources._vendor." + (nm[:-3]), m, ["*"]) - expected_missing_imports.add("pkg_resources.extern." + (nm[:3])) - elif os.path.isdir(os.path.join(vendor_dir)): - mf.import_hook("pkg_resources._vendor." + nm, m, ["*"]) - expected_missing_imports.add("pkg_resources.extern." + nm) + for topdir, dirs, files in os.walk(vendor_dir): + for fn in files: + if fn in ("__pycache__", "__init__.py"): continue + + relnm = os.path.relpath(os.path.join(topdir, fn), vendor_dir) + if relnm.endswith(".py"): + relnm = relnm[:-3] + relnm = relnm.replace("/", ".") + + if fn.endswith(".py"): + mf.import_hook("pkg_resources._vendor." + relnm, m, ["*"]) + expected_missing_imports.add("pkg_resources.extern." + relnm) + for dn in dirs: + if not os.path.exists(os.path.join(topdir, dn, "__init__.py")): + continue + relnm = os.path.relpath(os.path.join(topdir, dn), vendor_dir) + relnm = relnm.replace("/", ".") + + mf.import_hook("pkg_resources._vendor." + relnm, m, ["*"]) + expected_missing_imports.add("pkg_resources.extern." + relnm) mf.import_hook("pkg_resources._vendor", m) - #for node in mf.nodes(): - # if node.name and node.name.startswith("pkg_resources.extern"): - # suffix = node.name[len("pkg_resources.extern."):] - # mf.import_hook("pkg_resources._vendor." + suffix, node, ["*"]) - - if sys.version[0] != 2: expected_missing_imports.add("__builtin__")