Patchwork D7701: resourceutil: use `from importlib import resources`

login
register
mail settings
Submitter phabricator
Date Dec. 23, 2019, 5:27 p.m.
Message ID <b2971fdbdee3b71e25bcd090e5443f6d@localhost.localdomain>
Download mbox | patch
Permalink /patch/44026/
State Not Applicable
Headers show

Comments

phabricator - Dec. 23, 2019, 5:27 p.m.
Closed by commit rHG75ec46c63657: resourceutil: use `from importlib import resources` (authored by martinvonz).
This revision was automatically updated to reflect the committed changes.

REPOSITORY
  rHG Mercurial

CHANGES SINCE LAST UPDATE
  https://phab.mercurial-scm.org/D7701?vs=18871&id=18914

CHANGES SINCE LAST ACTION
  https://phab.mercurial-scm.org/D7701/new/

REVISION DETAIL
  https://phab.mercurial-scm.org/D7701

AFFECTED FILES
  mercurial/utils/resourceutil.py

CHANGE DETAILS




To: martinvonz, #hg-reviewers, indygreg
Cc: indygreg, mercurial-devel

Patch

diff --git a/mercurial/utils/resourceutil.py b/mercurial/utils/resourceutil.py
--- a/mercurial/utils/resourceutil.py
+++ b/mercurial/utils/resourceutil.py
@@ -37,19 +37,19 @@ 
     datapath = os.path.dirname(os.path.dirname(pycompat.fsencode(__file__)))
 
 try:
-    import importlib
+    from importlib import resources
 
     # Force loading of the resources module
-    importlib.resources.open_binary  # pytype: disable=module-attr
+    resources.open_binary  # pytype: disable=module-attr
 
     def open_resource(package, name):
         package = b'mercurial.' + package
-        return importlib.resources.open_binary(  # pytype: disable=module-attr
+        return resources.open_binary(  # pytype: disable=module-attr
             pycompat.sysstr(package), pycompat.sysstr(name)
         )
 
 
-except AttributeError:
+except (ImportError, AttributeError):
 
     def _package_path(package):
         return os.path.join(datapath, *package.split(b'.'))