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

login
register
mail settings
Submitter phabricator
Date Feb. 1, 2020, 4:02 a.m.
Message ID <differential-rev-PHID-DREV-df2ji4iyd3jgyd7uadh2-req@mercurial-scm.org>
Download mbox | patch
Permalink /patch/44854/
State Superseded
Headers show

Comments

phabricator - Feb. 1, 2020, 4:02 a.m.
mharbison72 created this revision.
Herald added a subscriber: mercurial-devel.
Herald added a reviewer: hg-reviewers.

REVISION SUMMARY
  After 9e367157a990 <https://phab.mercurial-scm.org/rHG9e367157a99098dc8fdfff83a5b3d5446e5b656f>, config files for py2exe were expected to be in
  C:\Program Files\Mercurial\mercurial\defaultrc because of the implied resource
  structure of 'mercurial.defaultrc.*.rc', relative to the executable.
  Accomodating this would require changes to the WIX and Inno scripts (and perhaps
  the script that generates the WIX script), as well as 3rd party bundlers like
  TortoiseHg.  But these files aren't read as resources anyway- they fall back to
  the filesystem APIs.  (If we really wanted to carry on the charade, the
  installer would have to also sprinkle various empty __init__.py files around.)
  
  Instead, this simply prunes the 'mercurial.' portion of the resource name when
  run with py2exe.  (PyOxidizer uses the resources API, not the filesystem
  fallback, so it is unaffected.)  Since this hack only affects the py2 Windows
  installers and is less risky, I think it's reasonable.  We haven't needed to
  load any 3rd party resource up to this point, and would have to make packaging
  changes anyway to handle that.

REPOSITORY
  rHG Mercurial

BRANCH
  stable

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

AFFECTED FILES
  mercurial/utils/resourceutil.py

CHANGE DETAILS




To: mharbison72, #hg-reviewers
Cc: mercurial-devel
phabricator - Feb. 1, 2020, 4:06 a.m.
mharbison72 added a comment.


  This is meant for stable.  We will also need D8052 <https://phab.mercurial-scm.org/D8052> before tagging the release.  I'm going to see if I can fix the version field in the the Inno installer, but that's not critical like this.

REPOSITORY
  rHG Mercurial

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

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

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