D7418: procutil: teach resourcereader() to handle exe relative resources
indygreg (Gregory Szorc)
phabricator at mercurial-scm.org
Fri Nov 15 03:58:58 UTC 2019
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
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)
To: indygreg, #hg-reviewers
Cc: mercurial-devel
More information about the Mercurial-devel
mailing list