mercurial/utils/resourceutil.py
branchstable
changeset 44219 aab70b540d3d
parent 44208 9e367157a990
child 44241 aea79f41ee55
--- a/mercurial/utils/resourceutil.py	Thu Jan 30 19:37:06 2020 -0500
+++ b/mercurial/utils/resourceutil.py	Fri Jan 31 22:20:39 2020 -0500
@@ -34,10 +34,24 @@
     # executable version (py2exe) doesn't support __file__
     datapath = os.path.dirname(pycompat.sysexecutable)
     _rootpath = datapath
+
+    # The installers store the files outside of library.zip, like
+    # C:\Program Files\Mercurial\defaultrc\*.rc.  This strips the
+    # leading "mercurial." off of the package name, so that these
+    # pseudo resources are found in their directory next to the
+    # executable.
+    def _package_path(package):
+        dirs = package.split(b'.')
+        assert dirs[0] == b'mercurial'
+        return os.path.join(_rootpath, *dirs[1:])
+
 else:
     datapath = os.path.dirname(os.path.dirname(pycompat.fsencode(__file__)))
     _rootpath = os.path.dirname(datapath)
 
+    def _package_path(package):
+        return os.path.join(_rootpath, *package.split(b'.'))
+
 try:
     from importlib import resources
 
@@ -63,9 +77,6 @@
 
 except (ImportError, AttributeError):
 
-    def _package_path(package):
-        return os.path.join(_rootpath, *package.split(b'.'))
-
     def open_resource(package, name):
         path = os.path.join(_package_path(package), name)
         return open(path, 'rb')