Patchwork D7415: procutil: move datapath logic to procutil()

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

Comments

phabricator - Nov. 15, 2019, 3:59 a.m.
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




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


  This is an old series I had authored a few months back as part of preliminary PyOxidizer porting. It demonstrates an alternate approach to loading files with the resources API. Essentially, I was trying to abstract the resources API so that in the future once we are Python 3.7+ native we could use `importlib.resources` directly and perform all resources I/O using a resources abstraction.
  
  This series is in desperate need of a rebase.
  
  Please take a look @mharbison72 and consider taking ownership of these patches under your own name.

REPOSITORY
  rHG Mercurial

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

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

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


  Also see D7433 <https://phab.mercurial-scm.org/D7433>-D7436, which move this code to a new module so the `i18n` module can depend on this code.

REPOSITORY
  rHG Mercurial

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

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

To: indygreg, #hg-reviewers
Cc: martinvonz, mharbison72, mercurial-devel
phabricator - Nov. 16, 2019, 7:20 p.m.
indygreg added a comment.
indygreg abandoned this revision.


  This patch is now irrelevant due to D7434 <https://phab.mercurial-scm.org/D7434>.

REPOSITORY
  rHG Mercurial

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

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

To: indygreg, #hg-reviewers
Cc: martinvonz, mharbison72, 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
@@ -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):