Patchwork D7386: help: access text files as resources under PyOxidizer

login
register
mail settings
Submitter phabricator
Date Nov. 14, 2019, 4:01 a.m.
Message ID <differential-rev-PHID-DREV-ivioowse6dyi6pjrsmq4-req@mercurial-scm.org>
Download mbox | patch
Permalink /patch/43183/
State Superseded
Headers show

Comments

phabricator - Nov. 14, 2019, 4:01 a.m.
mharbison72 created this revision.
Herald added a subscriber: mercurial-devel.
Herald added a reviewer: hg-reviewers.

REVISION SUMMARY
  This allows `hg help revsets` to run on an oxidized Mac executable.  I left the
  old path in place for py2 support, as well as the other packaging apps.
  
  On Windows, that same command simply prints:
  
    abort: Incorrect function
  
  ... and doesn't put out a stacktrace even with `--traceback`.

REPOSITORY
  rHG Mercurial

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

AFFECTED FILES
  mercurial/help.py

CHANGE DETAILS




To: mharbison72, #hg-reviewers
Cc: mercurial-devel
phabricator - Nov. 14, 2019, 4:09 a.m.
mharbison72 added a comment.
mharbison72 added a subscriber: indygreg.


  It looks like py2app puts it's name in `sys.frozen`[1], instead of just making it `True`/`False`.  Should PyOxidizer do the same @indygreg ?
  
  I don't have any idea why the error on Windows (I even disabled pager).  I know I had trouble with `hg.exe` until I started setting `Py_LegacyWindowsStdioFlag = 1`.
  
  [1] https://www.mercurial-scm.org/repo/hg/file/5.2/mercurial/util.py#l1829

REPOSITORY
  rHG Mercurial

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

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

To: mharbison72, #hg-reviewers
Cc: indygreg, mercurial-devel
phabricator - Dec. 28, 2019, 5:52 p.m.
mharbison72 added a comment.
mharbison72 abandoned this revision.


  Superseded by D7622 <https://phab.mercurial-scm.org/D7622>.

REPOSITORY
  rHG Mercurial

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

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

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

Patch

diff --git a/mercurial/help.py b/mercurial/help.py
--- a/mercurial/help.py
+++ b/mercurial/help.py
@@ -10,6 +10,7 @@ 
 import itertools
 import os
 import re
+import sys
 import textwrap
 
 from .i18n import (
@@ -310,12 +311,26 @@ 
 def loaddoc(topic, subdir=None):
     """Return a delayed loader for help/topic.txt."""
 
+    if getattr(sys, 'oxidized', None):
+        from importlib import resources
+
+        def _docdata():
+            docpkg = b'mercurial.helptext'
+            if subdir:
+                docpkg += b'.' + subdir
+            with resources.open_binary(pycompat.sysstr(docpkg),
+                                       pycompat.sysstr(topic + b".txt")) as dh:
+                return dh.read()
+    else:
+        def _docdata():
+            docdir = os.path.join(util.datapath, b'helptext')
+            if subdir:
+                docdir = os.path.join(docdir, subdir)
+            path = os.path.join(docdir, topic + b".txt")
+            return util.readfile(path)
+
     def loader(ui):
-        docdir = os.path.join(util.datapath, b'helptext')
-        if subdir:
-            docdir = os.path.join(docdir, subdir)
-        path = os.path.join(docdir, topic + b".txt")
-        doc = gettext(util.readfile(path))
+        doc = gettext(_docdata())
         for rewriter in helphooks.get(topic, []):
             doc = rewriter(ui, topic, doc)
         return doc