Patchwork D8058: resourceutil: account for the non-resource-like file hierarchy under py2exe

login
register
mail settings
Submitter phabricator
Date Feb. 2, 2020, midnight
Message ID <54a737e8e2df3d9d3efc2157f8553d0e@localhost.localdomain>
Download mbox | patch
Permalink /patch/44867/
State Not Applicable
Headers show

Comments

phabricator - Feb. 2, 2020, midnight
Closed by commit rHGaab70b540d3d: resourceutil: account for the non-resource-like file hierarchy under py2exe (authored by mharbison72).
This revision was automatically updated to reflect the committed changes.

REPOSITORY
  rHG Mercurial

CHANGES SINCE LAST UPDATE
  https://phab.mercurial-scm.org/D8058?vs=19805&id=19818

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

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

AFFECTED FILES
  mercurial/utils/resourceutil.py

CHANGE DETAILS




To: mharbison72, #hg-reviewers, indygreg
Cc: 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
@@ -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')