Patchwork [2,of,7,v2] hghave: check the mercurial.modulepolicy for pure

login
register
mail settings
Submitter timeless@mozdev.org
Date Jan. 12, 2016, 5:23 a.m.
Message ID <a55eb78c1f0697d658ba.1452576184@waste.org>
Download mbox | patch
Permalink /patch/12672/
State Changes Requested
Headers show

Comments

timeless@mozdev.org - Jan. 12, 2016, 5:23 a.m.
# HG changeset patch
# User timeless <timeless@mozdev.org>
# Date 1452574111 0
#      Tue Jan 12 04:48:31 2016 +0000
# Node ID a55eb78c1f0697d658ba78f67641746a4bf119e5
# Parent  39122c2442cd445172d7f07adb3f8186f9ddc0f1
hghave: check the mercurial.modulepolicy for pure

This is the most "correct" way to find out if we are running pure,
but I am not sure about paths/loading the mercurial module in hghave...
Yuya Nishihara - Jan. 15, 2016, 12:39 p.m.
On Mon, 11 Jan 2016 23:23:04 -0600, timeless wrote:
> # HG changeset patch
> # User timeless <timeless@mozdev.org>
> # Date 1452574111 0
> #      Tue Jan 12 04:48:31 2016 +0000
> # Node ID a55eb78c1f0697d658ba78f67641746a4bf119e5
> # Parent  39122c2442cd445172d7f07adb3f8186f9ddc0f1
> hghave: check the mercurial.modulepolicy for pure
> 
> This is the most "correct" way to find out if we are running pure,
> but I am not sure about paths/loading the mercurial module in hghave...
> 
> diff --git a/tests/hghave.py b/tests/hghave.py
> --- a/tests/hghave.py
> +++ b/tests/hghave.py
> @@ -460,6 +460,14 @@
>  
>  @check("pure", "running with pure Python code")
>  def has_pure():
> +    try:
> +        parent = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
> +        sys.path.insert(0, parent)
> +        import mercurial
> +        if mercurial.modulepolicy == 'py':
> +            return True
> +    finally:
> +        del sys.path[0]

Perhaps we can expose the module policy by "hg debuginstall" or something.
I think that is one good reason we've introduced the custom importer.
timeless - Jan. 15, 2016, 6:02 p.m.
Yuya Nishihara wrote:

> Perhaps we can expose the module policy by "hg debuginstall" or something.
> I think that is one good reason we've introduced the custom importer.

+1

Patch

diff --git a/tests/hghave.py b/tests/hghave.py
--- a/tests/hghave.py
+++ b/tests/hghave.py
@@ -460,6 +460,14 @@ 
 
 @check("pure", "running with pure Python code")
 def has_pure():
+    try:
+        parent = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
+        sys.path.insert(0, parent)
+        import mercurial
+        if mercurial.modulepolicy == 'py':
+            return True
+    finally:
+        del sys.path[0]
     return any([
         os.environ.get("HGMODULEPOLICY") == "py",
         os.environ.get("HGTEST_RUN_TESTS_PURE") == "--pure",