On 3/28/23 23:11, John Snow wrote:
+ # venv class is cute and toggles this off before post_setup,
+ # but we need it to decide if we want to generate shims or not.
Ha, yeah that's a bug in the venv package. post_setup() can already run
with system_site_packages reverted to True.
+ for entry_point in entry_points:
+ # Python 3.8 doesn't have 'module' or 'attr' attributes
+ if not (hasattr(entry_point, 'module') and
+ hasattr(entry_point, 'attr')):
+ match = pattern.match(entry_point.value)
+ assert match is not None
+ module = match.group('module')
+ attr = match.group('attr')
+ else:
+ module = entry_point.module
+ attr = entry_point.attr
+ yield {
+ 'name': entry_point.name,
+ 'module': module,
+ 'import_name': attr,
+ 'func': attr,
What about using a dataclass or namedtuple instead of a dictionary?
+
+ try:
+ entry_points = _get_entry_points()
+ except ImportError as exc:
+ logger.debug("%s", str(exc))
+ raise Ouch(
+ "Neither importlib.metadata nor pkg_resources found, "
+ "can't generate console script shims.\n"
+ "Use Python 3.8+, or install importlib-metadata, or setuptools."
+ ) from exc
Why not put this extra try/except inside _get_entry_points()?
+
+ # Test for ensurepip:
+ try:
+ import ensurepip
Use find_spec()?
BTW, another way to repair Debian 10's pip is to create a symbolic link
to sys.base_prefix + '/share/python-wheels' in sys.prefix +
'/share/python-wheels'. Since this is much faster, perhaps it can be
done unconditionally and checkpip mode can go away together with
self._context?
Paolo