D7415: procutil: move datapath logic to procutil()

indygreg (Gregory Szorc) phabricator at mercurial-scm.org
Fri Nov 15 03:59:12 UTC 2019


indygreg created this revision.
Herald added a subscriber: mercurial-devel.
Herald added a reviewer: hg-reviewers.

REVISION SUMMARY
  And refactor it as a function.
  
  procutil.py is the more appropriate location for this code, as
  procutil is responsible for managing aspects of the executable
  environment.
  
  The impetus for this change is introducing an abstraction for
  resource reading. I'd like that code to live in procutil.py
  so we don't make util.py any larger. The code requires datapath.
  And since util imports procutil, we need datapath in procutil
  to avoid a cycle.

REPOSITORY
  rHG Mercurial

BRANCH
  default

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

AFFECTED FILES
  mercurial/util.py
  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
@@ -535,3 +535,12 @@
             # mission accomplished, this child needs to exit and not
             # continue the hg process here.
             os._exit(returncode)
+
+def datapath():
+    """Return location of data/resource files that are part of the source."""
+    if mainfrozen() and getattr(sys, 'frozen', None) != 'macosx_app':
+        # executable version (py2exe) doesn't support __file__
+        return os.path.dirname(pycompat.sysexecutable)
+    else:
+        return os.path.dirname(
+            os.path.dirname(pycompat.fsencode(__file__)))
diff --git a/mercurial/util.py b/mercurial/util.py
--- a/mercurial/util.py
+++ b/mercurial/util.py
@@ -1660,13 +1660,7 @@
     b.reverse()
     return pycompat.ossep.join((['..'] * len(a)) + b) or '.'
 
-# the location of data files matching the source code
-if procutil.mainfrozen() and getattr(sys, 'frozen', None) != 'macosx_app':
-    # executable version (py2exe) doesn't support __file__
-    datapath = os.path.dirname(pycompat.sysexecutable)
-else:
-    datapath = os.path.dirname(pycompat.fsencode(__file__))
-
+datapath = procutil.datapath()
 i18n.setdatapath(datapath)
 
 def checksignature(func):



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


More information about the Mercurial-devel mailing list