Patchwork D7418: procutil: teach resourcereader() to handle exe relative resources

login
register
mail settings
Submitter phabricator
Date Nov. 15, 2019, 3:58 a.m.
Message ID <differential-rev-PHID-DREV-mvdxvziolsoz6e5rennu-req@mercurial-scm.org>
Download mbox | patch
Permalink /patch/43254/
State New
Headers show

Comments

phabricator - Nov. 15, 2019, 3:58 a.m.
indygreg created this revision.
Herald added a subscriber: mercurial-devel.
Herald added a reviewer: hg-reviewers.

REVISION SUMMARY
  Mercurial distributions like those produced with py2exe store
  their data/resource files relative to the executable. For
  example, in our Windows distributions, help files are in
  the help/ directory relative to hg.exe.
  
  In a future world where we are using the ResourceReader API
  for accessing package resources, we need a way to provide
  a ResourceReader for these pieces of data without breaking
  these Mercurial distributions.
  
  This commit introduces logic into resourcereader() which will
  return a filesystem-based ResourceReader if resources are
  relative to the executable and we are requesting resources for
  the "mercurial" package.
  
  Ideally we wouldn't need to do this and would instead change
  packaging. However, various downstream consumers may be sensitive
  to changes in the on-disk layout of Mercurial installs. I'm
  unwilling to cross this bridge at this time. I think it is more
  important to get things working with the ResourceReader API first.
  Then we can tackle better resource packaging/installation.
  
  It is also likely that we'll need more logic to handle additional
  packages/resources. For example, help resources are always in a
  help/ directory and map cleanly, but templates resources are in a
  Templates/ directory and there are case-sensitivity concerns.
  Our initial target for using the resource reading API is help.
  So we can defer on additional complexity.

REPOSITORY
  rHG Mercurial

BRANCH
  default

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

AFFECTED FILES
  mercurial/utils/procutil.py

CHANGE DETAILS




To: indygreg, #hg-reviewers
Cc: mercurial-devel
phabricator - Nov. 15, 2019, 4:02 a.m.
indygreg added a comment.
indygreg planned changes to this revision.


  The commit message on this one is probably a bit out of date, since packaging has changed some since I initially authored this commit.

REPOSITORY
  rHG Mercurial

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

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

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

Patch

diff --git a/mercurial/utils/procutil.py b/mercurial/utils/procutil.py
--- a/mercurial/utils/procutil.py
+++ b/mercurial/utils/procutil.py
@@ -642,6 +642,14 @@ 
     # Raising TypeError here is a little weird. But it is what the standard
     # library does.
     package = pycompat.sysstr(package)
+
+    # Executable relative resources are distributed next to the executable
+    # in special locations, not as proper package resources. We need to handle
+    # them specially.
+    if package == r'mercurial' and executablerelativeresources():
+        p = os.path.dirname(sys.executable)
+        return filesystemresourcereader(pycompat.fsencode(p))
+
     module = importlib.import_module(package)
 
     spec = getattr(module, '__spec__', None)