Patchwork D7376: help: create packages for the help text

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

Comments

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

REVISION SUMMARY
  These files need to be loaded as resources with PyOxidizer, instead of using
  filesystem representations.  AFAICT, the resource loading mechanisms only work
  for the named package given to it, and can't reach into a subdirectory.
  
  While here, the `help` directory is renamed to `helptext`.  Without this, trying
  to load external help text crashed in mercurial/help.py when importing `.i18n`,
  saying there's no `mercurial.help.i18n` module.

REPOSITORY
  rHG Mercurial

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

AFFECTED FILES
  mercurial/help.py
  mercurial/help/bundlespec.txt
  mercurial/help/color.txt
  mercurial/help/common.txt
  mercurial/help/config.txt
  mercurial/help/dates.txt
  mercurial/help/deprecated.txt
  mercurial/help/diffs.txt
  mercurial/help/environment.txt
  mercurial/help/extensions.txt
  mercurial/help/filesets.txt
  mercurial/help/flags.txt
  mercurial/help/glossary.txt
  mercurial/help/hg-ssh.8.txt
  mercurial/help/hg.1.txt
  mercurial/help/hgignore.5.txt
  mercurial/help/hgignore.txt
  mercurial/help/hgrc.5.txt
  mercurial/help/hgweb.txt
  mercurial/help/internals/bundle2.txt
  mercurial/help/internals/bundles.txt
  mercurial/help/internals/cbor.txt
  mercurial/help/internals/censor.txt
  mercurial/help/internals/changegroups.txt
  mercurial/help/internals/config.txt
  mercurial/help/internals/extensions.txt
  mercurial/help/internals/linelog.txt
  mercurial/help/internals/mergestate.txt
  mercurial/help/internals/requirements.txt
  mercurial/help/internals/revlogs.txt
  mercurial/help/internals/wireprotocol.txt
  mercurial/help/internals/wireprotocolrpc.txt
  mercurial/help/internals/wireprotocolv2.txt
  mercurial/help/merge-tools.txt
  mercurial/help/pager.txt
  mercurial/help/patterns.txt
  mercurial/help/phases.txt
  mercurial/help/revisions.txt
  mercurial/help/scripting.txt
  mercurial/help/subrepos.txt
  mercurial/help/templates.txt
  mercurial/help/urls.txt
  mercurial/helptext/__init__.py
  mercurial/helptext/bundlespec.txt
  mercurial/helptext/color.txt
  mercurial/helptext/common.txt
  mercurial/helptext/config.txt
  mercurial/helptext/dates.txt
  mercurial/helptext/deprecated.txt
  mercurial/helptext/diffs.txt
  mercurial/helptext/environment.txt
  mercurial/helptext/extensions.txt
  mercurial/helptext/filesets.txt
  mercurial/helptext/flags.txt
  mercurial/helptext/glossary.txt
  mercurial/helptext/hg-ssh.8.txt
  mercurial/helptext/hg.1.txt
  mercurial/helptext/hgignore.5.txt
  mercurial/helptext/hgignore.txt
  mercurial/helptext/hgrc.5.txt
  mercurial/helptext/hgweb.txt
  mercurial/helptext/internals/__init__.py
  mercurial/helptext/internals/bundle2.txt
  mercurial/helptext/internals/bundles.txt
  mercurial/helptext/internals/cbor.txt
  mercurial/helptext/internals/censor.txt
  mercurial/helptext/internals/changegroups.txt
  mercurial/helptext/internals/config.txt
  mercurial/helptext/internals/extensions.txt
  mercurial/helptext/internals/linelog.txt
  mercurial/helptext/internals/mergestate.txt
  mercurial/helptext/internals/requirements.txt
  mercurial/helptext/internals/revlogs.txt
  mercurial/helptext/internals/wireprotocol.txt
  mercurial/helptext/internals/wireprotocolrpc.txt
  mercurial/helptext/internals/wireprotocolv2.txt
  mercurial/helptext/merge-tools.txt
  mercurial/helptext/pager.txt
  mercurial/helptext/patterns.txt
  mercurial/helptext/phases.txt
  mercurial/helptext/revisions.txt
  mercurial/helptext/scripting.txt
  mercurial/helptext/subrepos.txt
  mercurial/helptext/templates.txt
  mercurial/helptext/urls.txt
  setup.py

CHANGE DETAILS




To: mharbison72, #hg-reviewers
Cc: mercurial-devel
phabricator - Nov. 14, 2019, 6:04 a.m.
martinvonz added a comment.


  Looks good to me, but I don't know Python well enough to say if `mercurial.help` and `mercurial.help.internal` should be "namespace packages" (which I think is what you're doing with the `pkgutil.extend_path()` stuff). I'd appreciate it if someone who knows Python better can comment.

REPOSITORY
  rHG Mercurial

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

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

To: mharbison72, #hg-reviewers
Cc: martinvonz, mercurial-devel
phabricator - Nov. 15, 2019, 1:15 a.m.
martinvonz added a comment.


  We could also consider removing the `internals/` subdirectory and replacing it by a `internals.` prefix to the filename. Just a thought; I don't care much.
  
  In D7376#108573 <https://phab.mercurial-scm.org/D7376#108573>, @martinvonz wrote:
  
  > Looks good to me, but I don't know Python well enough to say if `mercurial.help` and `mercurial.help.internal` should be "namespace packages" (which I think is what you're doing with the `pkgutil.extend_path()` stuff). I'd appreciate it if someone who knows Python better can comment.
  
  I'm not sure if it's better to make these namespaces or not, but I think it's better to start with regular packages. We can always upgrade them to namespace packages later.

REPOSITORY
  rHG Mercurial

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

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

To: mharbison72, #hg-reviewers, marmoute
Cc: martinvonz, mercurial-devel
phabricator - Nov. 15, 2019, 3:14 a.m.
indygreg added a comment.


  FWIW I have a series of patches somewhere that teach the help, templates, etc subsystems to use the `importlib.resources` API if available.
  
  I also have plans to enable PyOxidizer to package resources with more flexibility so we wouldn't necessarily have to rename a bunch of files and add `__init__.py` files to mark directories as packages so `importlib.resources` *just works*. I haven't gotten around to it yet. I figured if Mercurial has resources files like this, other projects would, so I would need to teach PyOxidizer to handle wonky layouts like this.
  
  But if we want to continue and support the `importlib.resources` API so things work with the current state of PyOxidizer, that's fine by me. It just isn't strictly required if there is resistance to mass renaming files and conforming to the wonky requirements imposed today.

REPOSITORY
  rHG Mercurial

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

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

To: mharbison72, #hg-reviewers, marmoute
Cc: indygreg, martinvonz, mercurial-devel
phabricator - Nov. 15, 2019, 4:02 a.m.
martinvonz added a comment.


  In D7376#108863 <https://phab.mercurial-scm.org/D7376#108863>, @indygreg wrote:
  
  > FWIW I have a series of patches somewhere that teach the help, templates, etc subsystems to use the `importlib.resources` API if available.
  
  I'd be happy to see those soon. I had just started working on that.
  
  > I also have plans to enable PyOxidizer to package resources with more flexibility so we wouldn't necessarily have to rename a bunch of files and add `__init__.py` files to mark directories as packages so `importlib.resources` *just works*. I haven't gotten around to it yet. I figured if Mercurial has resources files like this, other projects would, so I would need to teach PyOxidizer to handle wonky layouts like this.
  > But if we want to continue and support the `importlib.resources` API so things work with the current state of PyOxidizer, that's fine by me. It just isn't strictly required if there is resistance to mass renaming files and conforming to the wonky requirements imposed today.
  
  I'm fine with fixing it in mercurial. It seems like the right way of doing it anyway and it's not that much work.

REPOSITORY
  rHG Mercurial

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

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

To: mharbison72, #hg-reviewers, marmoute
Cc: indygreg, martinvonz, mercurial-devel
phabricator - Nov. 15, 2019, 4:08 a.m.
indygreg added a comment.


  See the series starting at D7415 <https://phab.mercurial-scm.org/D7415> for the patches I authored a while ago. Please take them over and push them over the finish line if you agree with the approach!

REPOSITORY
  rHG Mercurial

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

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

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

Patch

diff --git a/setup.py b/setup.py
--- a/setup.py
+++ b/setup.py
@@ -1191,6 +1191,8 @@ 
     'mercurial',
     'mercurial.cext',
     'mercurial.cffi',
+    'mercurial.helptext',
+    'mercurial.helptext.internals',
     'mercurial.hgweb',
     'mercurial.interfaces',
     'mercurial.pure',
@@ -1535,11 +1537,15 @@ 
 packagedata = {
     'mercurial': [
         'locale/*/LC_MESSAGES/hg.mo',
-        'help/*.txt',
-        'help/internals/*.txt',
         'default.d/*.rc',
         'dummycert.pem',
-    ]
+    ],
+    'mercurial.helptext': [
+        '*.txt',
+    ],
+    'mercurial.helptext.internals': [
+       '*.txt',
+    ],
 }
 
 
diff --git a/mercurial/help/urls.txt b/mercurial/helptext/urls.txt
rename from mercurial/help/urls.txt
rename to mercurial/helptext/urls.txt
diff --git a/mercurial/help/templates.txt b/mercurial/helptext/templates.txt
rename from mercurial/help/templates.txt
rename to mercurial/helptext/templates.txt
diff --git a/mercurial/help/subrepos.txt b/mercurial/helptext/subrepos.txt
rename from mercurial/help/subrepos.txt
rename to mercurial/helptext/subrepos.txt
diff --git a/mercurial/help/scripting.txt b/mercurial/helptext/scripting.txt
rename from mercurial/help/scripting.txt
rename to mercurial/helptext/scripting.txt
diff --git a/mercurial/help/revisions.txt b/mercurial/helptext/revisions.txt
rename from mercurial/help/revisions.txt
rename to mercurial/helptext/revisions.txt
diff --git a/mercurial/help/phases.txt b/mercurial/helptext/phases.txt
rename from mercurial/help/phases.txt
rename to mercurial/helptext/phases.txt
diff --git a/mercurial/help/patterns.txt b/mercurial/helptext/patterns.txt
rename from mercurial/help/patterns.txt
rename to mercurial/helptext/patterns.txt
diff --git a/mercurial/help/pager.txt b/mercurial/helptext/pager.txt
rename from mercurial/help/pager.txt
rename to mercurial/helptext/pager.txt
diff --git a/mercurial/help/merge-tools.txt b/mercurial/helptext/merge-tools.txt
rename from mercurial/help/merge-tools.txt
rename to mercurial/helptext/merge-tools.txt
diff --git a/mercurial/help/internals/wireprotocolv2.txt b/mercurial/helptext/internals/wireprotocolv2.txt
rename from mercurial/help/internals/wireprotocolv2.txt
rename to mercurial/helptext/internals/wireprotocolv2.txt
diff --git a/mercurial/help/internals/wireprotocolrpc.txt b/mercurial/helptext/internals/wireprotocolrpc.txt
rename from mercurial/help/internals/wireprotocolrpc.txt
rename to mercurial/helptext/internals/wireprotocolrpc.txt
diff --git a/mercurial/help/internals/wireprotocol.txt b/mercurial/helptext/internals/wireprotocol.txt
rename from mercurial/help/internals/wireprotocol.txt
rename to mercurial/helptext/internals/wireprotocol.txt
diff --git a/mercurial/help/internals/revlogs.txt b/mercurial/helptext/internals/revlogs.txt
rename from mercurial/help/internals/revlogs.txt
rename to mercurial/helptext/internals/revlogs.txt
diff --git a/mercurial/help/internals/requirements.txt b/mercurial/helptext/internals/requirements.txt
rename from mercurial/help/internals/requirements.txt
rename to mercurial/helptext/internals/requirements.txt
diff --git a/mercurial/help/internals/mergestate.txt b/mercurial/helptext/internals/mergestate.txt
rename from mercurial/help/internals/mergestate.txt
rename to mercurial/helptext/internals/mergestate.txt
diff --git a/mercurial/help/internals/linelog.txt b/mercurial/helptext/internals/linelog.txt
rename from mercurial/help/internals/linelog.txt
rename to mercurial/helptext/internals/linelog.txt
diff --git a/mercurial/help/internals/extensions.txt b/mercurial/helptext/internals/extensions.txt
rename from mercurial/help/internals/extensions.txt
rename to mercurial/helptext/internals/extensions.txt
diff --git a/mercurial/help/internals/config.txt b/mercurial/helptext/internals/config.txt
rename from mercurial/help/internals/config.txt
rename to mercurial/helptext/internals/config.txt
diff --git a/mercurial/help/internals/changegroups.txt b/mercurial/helptext/internals/changegroups.txt
rename from mercurial/help/internals/changegroups.txt
rename to mercurial/helptext/internals/changegroups.txt
diff --git a/mercurial/help/internals/censor.txt b/mercurial/helptext/internals/censor.txt
rename from mercurial/help/internals/censor.txt
rename to mercurial/helptext/internals/censor.txt
diff --git a/mercurial/help/internals/cbor.txt b/mercurial/helptext/internals/cbor.txt
rename from mercurial/help/internals/cbor.txt
rename to mercurial/helptext/internals/cbor.txt
diff --git a/mercurial/help/internals/bundles.txt b/mercurial/helptext/internals/bundles.txt
rename from mercurial/help/internals/bundles.txt
rename to mercurial/helptext/internals/bundles.txt
diff --git a/mercurial/help/internals/bundle2.txt b/mercurial/helptext/internals/bundle2.txt
rename from mercurial/help/internals/bundle2.txt
rename to mercurial/helptext/internals/bundle2.txt
diff --git a/mercurial/helptext/internals/__init__.py b/mercurial/helptext/internals/__init__.py
new file mode 100644
--- /dev/null
+++ b/mercurial/helptext/internals/__init__.py
@@ -0,0 +1,4 @@ 
+from __future__ import absolute_import
+import pkgutil
+
+__path__ = pkgutil.extend_path(__path__, __name__)
diff --git a/mercurial/help/hgweb.txt b/mercurial/helptext/hgweb.txt
rename from mercurial/help/hgweb.txt
rename to mercurial/helptext/hgweb.txt
diff --git a/mercurial/help/hgrc.5.txt b/mercurial/helptext/hgrc.5.txt
rename from mercurial/help/hgrc.5.txt
rename to mercurial/helptext/hgrc.5.txt
diff --git a/mercurial/help/hgignore.txt b/mercurial/helptext/hgignore.txt
rename from mercurial/help/hgignore.txt
rename to mercurial/helptext/hgignore.txt
diff --git a/mercurial/help/hgignore.5.txt b/mercurial/helptext/hgignore.5.txt
rename from mercurial/help/hgignore.5.txt
rename to mercurial/helptext/hgignore.5.txt
diff --git a/mercurial/help/hg.1.txt b/mercurial/helptext/hg.1.txt
rename from mercurial/help/hg.1.txt
rename to mercurial/helptext/hg.1.txt
diff --git a/mercurial/help/hg-ssh.8.txt b/mercurial/helptext/hg-ssh.8.txt
rename from mercurial/help/hg-ssh.8.txt
rename to mercurial/helptext/hg-ssh.8.txt
diff --git a/mercurial/help/glossary.txt b/mercurial/helptext/glossary.txt
rename from mercurial/help/glossary.txt
rename to mercurial/helptext/glossary.txt
diff --git a/mercurial/help/flags.txt b/mercurial/helptext/flags.txt
rename from mercurial/help/flags.txt
rename to mercurial/helptext/flags.txt
diff --git a/mercurial/help/filesets.txt b/mercurial/helptext/filesets.txt
rename from mercurial/help/filesets.txt
rename to mercurial/helptext/filesets.txt
diff --git a/mercurial/help/extensions.txt b/mercurial/helptext/extensions.txt
rename from mercurial/help/extensions.txt
rename to mercurial/helptext/extensions.txt
diff --git a/mercurial/help/environment.txt b/mercurial/helptext/environment.txt
rename from mercurial/help/environment.txt
rename to mercurial/helptext/environment.txt
diff --git a/mercurial/help/diffs.txt b/mercurial/helptext/diffs.txt
rename from mercurial/help/diffs.txt
rename to mercurial/helptext/diffs.txt
diff --git a/mercurial/help/deprecated.txt b/mercurial/helptext/deprecated.txt
rename from mercurial/help/deprecated.txt
rename to mercurial/helptext/deprecated.txt
diff --git a/mercurial/help/dates.txt b/mercurial/helptext/dates.txt
rename from mercurial/help/dates.txt
rename to mercurial/helptext/dates.txt
diff --git a/mercurial/help/config.txt b/mercurial/helptext/config.txt
rename from mercurial/help/config.txt
rename to mercurial/helptext/config.txt
diff --git a/mercurial/help/common.txt b/mercurial/helptext/common.txt
rename from mercurial/help/common.txt
rename to mercurial/helptext/common.txt
diff --git a/mercurial/help/color.txt b/mercurial/helptext/color.txt
rename from mercurial/help/color.txt
rename to mercurial/helptext/color.txt
diff --git a/mercurial/help/bundlespec.txt b/mercurial/helptext/bundlespec.txt
rename from mercurial/help/bundlespec.txt
rename to mercurial/helptext/bundlespec.txt
diff --git a/mercurial/helptext/__init__.py b/mercurial/helptext/__init__.py
new file mode 100644
--- /dev/null
+++ b/mercurial/helptext/__init__.py
@@ -0,0 +1,4 @@ 
+from __future__ import absolute_import
+import pkgutil
+
+__path__ = pkgutil.extend_path(__path__, __name__)
diff --git a/mercurial/help.py b/mercurial/help.py
--- a/mercurial/help.py
+++ b/mercurial/help.py
@@ -311,7 +311,7 @@ 
     """Return a delayed loader for help/topic.txt."""
 
     def loader(ui):
-        docdir = os.path.join(util.datapath, b'help')
+        docdir = os.path.join(util.datapath, b'helptext')
         if subdir:
             docdir = os.path.join(docdir, subdir)
         path = os.path.join(docdir, topic + b".txt")