Issue 17002: html.entities ImportError in distutils2/pypi/simple.py on Python2.7 (original) (raw)
I guess it should be wrapped in a try, except:
try: from html.entities import name2codepoint except ImportError: from htmlentitydefs import name2codepoint
This works locally
Here's a sample traceback:
Traceback (most recent call last): File "python2nix.py", line 119, in egg_release = pypi.get_release(egg['name'] + '==' + version) File "/nix/var/nix/profiles/plone/lib/python2.7/site-packages/Distutils2-1.0a4-py2.7.egg/distutils2/pypi/simple.py", line 201, in get_release releases = self.get_releases(predicate, prefer_final) File "/nix/var/nix/profiles/plone/lib/python2.7/site-packages/Distutils2-1.0a4-py2.7.egg/distutils2/pypi/simple.py", line 189, in get_releases self._process_index_page(predicate.name) File "/nix/var/nix/profiles/plone/lib/python2.7/site-packages/Distutils2-1.0a4-py2.7.egg/distutils2/pypi/simple.py", line 75, in wrapped return func(self, *args, **kwargs) File "/nix/var/nix/profiles/plone/lib/python2.7/site-packages/Distutils2-1.0a4-py2.7.egg/distutils2/pypi/simple.py", line 397, in _process_index_page self._process_url(url, name) File "/nix/var/nix/profiles/plone/lib/python2.7/site-packages/Distutils2-1.0a4-py2.7.egg/distutils2/pypi/simple.py", line 320, in _process_url for link, is_download in link_matcher(f.read().decode(), base_url): File "/nix/var/nix/profiles/plone/lib/python2.7/site-packages/Distutils2-1.0a4-py2.7.egg/distutils2/pypi/simple.py", line 362, in _simple_link_matcher url = self._get_full_url(match.group(1), base_url) File "/nix/var/nix/profiles/plone/lib/python2.7/site-packages/Distutils2-1.0a4-py2.7.egg/distutils2/pypi/simple.py", line 349, in _get_full_url return urlparse.urljoin(base_url, self._htmldecode(url)) File "/nix/var/nix/profiles/plone/lib/python2.7/site-packages/Distutils2-1.0a4-py2.7.egg/distutils2/pypi/simple.py", line 469, in _htmldecode return ENTITY_SUB(self._decode_entity, text) File "/nix/var/nix/profiles/plone/lib/python2.7/site-packages/Distutils2-1.0a4-py2.7.egg/distutils2/pypi/simple.py", line 463, in _decode_entity from html.entities import name2codepoint ImportError: No module named html.entities
Good call. All function-level imports are avoided in d2 unless absolutely necessary, and this one slipped through the cracks. distutils2 went from Python 2 to 3 to 2 and 3 again, so these things happen (and it’s one of the reasons why I’ve always insisted on trying to keep as much history as possible in one repo).
Will fix, as even though d2 will not continue to live as one monolithic project, the pypi submodule will certainly be extracted in a smaller lib reusable by other tools.