Repository: pyinstaller/pyinstaller

Issue:
Setuptools 60.7.0 breaks the executable
Building with setuptools==60.7.0 I get this error.
There is no `jaraco` module (seems like this is the author of `setuptools)
```
(simulator_venv) ➜  agent git:(feature/SB-22361-improve-socket-error-handling) ✗ dist/sbsimulator/sbsimulator
Traceback (most recent call last):
  File "PyInstaller/hooks/rthooks/pyi_rth_pkgres.py", line 16, in <module>
  File "/Users/arossert/Shared/Bitbucket/agent/simulator_venv/lib/python3.8/site-packages/pkg_resources/__init__.py", line 74, in <module>
    from pkg_resources.extern.jaraco.text import (
  File "/Users/arossert/Shared/Bitbucket/agent/simulator_venv/lib/python3.8/site-packages/pkg_resources/extern/__init__.py", line 52, in create_module
    return self.load_module(spec.name)
  File "/Users/arossert/Shared/Bitbucket/agent/simulator_venv/lib/python3.8/site-packages/pkg_resources/extern/__init__.py", line 44, in load_module
    raise ImportError(
ImportError: The 'jaraco' package is required; normally this is bundled with this package so if you get this warning, consult the packager of your distribution.
[23421] Failed to execute script 'pyi_rth_pkgres' due to unhandled exception!
```

PyInstaller: 4.8
OS: Linux/Mac (not tested on Windows)
Python: 3.8.10


Discussion:
Duplicate of #6564. But let's keep both open for now in an attempt to avoid even more duplicates...

Resolving patch:
diff --git a/PyInstaller/hooks/hook-pkg_resources.py b/PyInstaller/hooks/hook-pkg_resources.py
--- a/PyInstaller/hooks/hook-pkg_resources.py
+++ b/PyInstaller/hooks/hook-pkg_resources.py
@@ -9,7 +9,7 @@
 # SPDX-License-Identifier: (GPL-2.0-or-later WITH Bootloader-exception)
 #-----------------------------------------------------------------------------
 
-from PyInstaller.utils.hooks import collect_submodules
+from PyInstaller.utils.hooks import collect_submodules, is_module_satisfies
 
 # pkg_resources keeps vendored modules in its _vendor subpackage, and does sys.meta_path based import magic to expose
 # them as pkg_resources.extern.*
@@ -28,3 +28,24 @@
 hiddenimports += collect_submodules('packaging')
 
 hiddenimports += ['pkg_resources.markers']
+
+# As of v60.7, setuptools vendored jaraco and has pkg_resources use it. Currently, the pkg_resources._vendor.jaraco
+# namespace package cannot be automatically scanned due to limited support for pure namespace packages in our hook
+# utilities.
+#
+# In setuptools 60.7.0, the vendored jaraco.text package included "Lorem Ipsum.txt" data file, which also has to be
+# collected. However, the presence of the data file (and the resulting directory hierarchy) confuses the importer's
+# redirection logic; instead of trying to work-around that, tell user to upgrade or downgrade their setuptools.
+if is_module_satisfies("setuptools == 60.7.0"):
+    raise SystemExit(
+        "ERROR: Setuptools 60.7.0 is incompatible with PyInstaller. "
+        "Downgrade to an earlier version or upgrade to a later version."
+    )
+# In setuptools 60.7.1, the "Lorem Ipsum.txt" data file was dropped from the vendored jaraco.text package, so we can
+# accommodate it with couple of hidden imports.
+elif is_module_satisfies("setuptools >= 60.7.1"):
+    hiddenimports += [
+        'pkg_resources._vendor.jaraco.functools',
+        'pkg_resources._vendor.jaraco.context',
+        'pkg_resources._vendor.jaraco.text',
+    ]


Test patch: