Patchwork [5,of,7,v2] mercurial: check mercurial/modulepolicy for modulepolicy

login
register
mail settings
Submitter timeless@mozdev.org
Date Jan. 12, 2016, 5:23 a.m.
Message ID <21b17c69ea254cceefc4.1452576187@waste.org>
Download mbox | patch
Permalink /patch/12675/
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 1452574998 0
#      Tue Jan 12 05:03:18 2016 +0000
# Node ID 21b17c69ea254cceefc474baabedd5a777278c8c
# Parent  cffb330960bad95524d0d170fdc7aea009e5b01d
mercurial: check mercurial/modulepolicy for modulepolicy

On local pure systems, setup doesn't rewrite mercurial/__init__.py,
because the file is managed by Mercurial...

In order to let such systems work, we allow for a file:
mercurial/modulepolicy to determine the policy.

A later patch will have setup.py write to this file.
Gregory Szorc - Jan. 12, 2016, 11:58 p.m.
On Mon, Jan 11, 2016 at 9:23 PM, timeless <timeless@mozdev.org> wrote:

> # HG changeset patch
> # User timeless <timeless@mozdev.org>
> # Date 1452574998 0
> #      Tue Jan 12 05:03:18 2016 +0000
> # Node ID 21b17c69ea254cceefc474baabedd5a777278c8c
> # Parent  cffb330960bad95524d0d170fdc7aea009e5b01d
> mercurial: check mercurial/modulepolicy for modulepolicy
>
> On local pure systems, setup doesn't rewrite mercurial/__init__.py,
> because the file is managed by Mercurial...
>
> In order to let such systems work, we allow for a file:
> mercurial/modulepolicy to determine the policy.
>
> A later patch will have setup.py write to this file.
>
> diff --git a/mercurial/__init__.py b/mercurial/__init__.py
> --- a/mercurial/__init__.py
> +++ b/mercurial/__init__.py
> @@ -23,7 +23,15 @@
>
>  # By default, require the C extensions for performance reasons.
>  if modulepolicy == '@' 'MODULELOADPOLICY' '@':
> -    modulepolicy = 'c'
> +    try:
> +        policyfile = os.path.join(os.path.dirname(__file__),
> 'modulepolicy')
> +        fp = open(policyfile, 'rb')
> +        r = fp.read()
> +        fp.close()
>

This should be:

  with open(policyfile, 'rb') as fh:
      r = fp.read()


> +        if r:
> +            modulepolicy = r.split("\n")[0]
> +    except IOError:
> +        modulepolicy = 'c'
>
>  # PyPy doesn't load C extensions.
>  #
> _______________________________________________
> Mercurial-devel mailing list
> Mercurial-devel@selenic.com
> https://selenic.com/mailman/listinfo/mercurial-devel
>
Yuya Nishihara - Jan. 15, 2016, 1:08 p.m.
On Mon, 11 Jan 2016 23:23:07 -0600, timeless wrote:
> # HG changeset patch
> # User timeless <timeless@mozdev.org>
> # Date 1452574998 0
> #      Tue Jan 12 05:03:18 2016 +0000
> # Node ID 21b17c69ea254cceefc474baabedd5a777278c8c
> # Parent  cffb330960bad95524d0d170fdc7aea009e5b01d
> mercurial: check mercurial/modulepolicy for modulepolicy
> 
> On local pure systems, setup doesn't rewrite mercurial/__init__.py,
> because the file is managed by Mercurial...
> 
> In order to let such systems work, we allow for a file:
> mercurial/modulepolicy to determine the policy.
> 
> A later patch will have setup.py write to this file.
> 
> diff --git a/mercurial/__init__.py b/mercurial/__init__.py
> --- a/mercurial/__init__.py
> +++ b/mercurial/__init__.py
> @@ -23,7 +23,15 @@
>  
>  # By default, require the C extensions for performance reasons.
>  if modulepolicy == '@' 'MODULELOADPOLICY' '@':
> -    modulepolicy = 'c'
> +    try:
> +        policyfile = os.path.join(os.path.dirname(__file__), 'modulepolicy')
> +        fp = open(policyfile, 'rb')
> +        r = fp.read()
> +        fp.close()
> +        if r:
> +            modulepolicy = r.split("\n")[0]
> +    except IOError:
> +        modulepolicy = 'c'

Instead of adding two separate modulepolicy initialization schemes, can't it
be like __version__.py?

 1. setup.py generates mercurial/__modulepolicy__.py
 2. __init__.py try loading __modulepolicy__ and falls back to default

Patch

diff --git a/mercurial/__init__.py b/mercurial/__init__.py
--- a/mercurial/__init__.py
+++ b/mercurial/__init__.py
@@ -23,7 +23,15 @@ 
 
 # By default, require the C extensions for performance reasons.
 if modulepolicy == '@' 'MODULELOADPOLICY' '@':
-    modulepolicy = 'c'
+    try:
+        policyfile = os.path.join(os.path.dirname(__file__), 'modulepolicy')
+        fp = open(policyfile, 'rb')
+        r = fp.read()
+        fp.close()
+        if r:
+            modulepolicy = r.split("\n")[0]
+    except IOError:
+        modulepolicy = 'c'
 
 # PyPy doesn't load C extensions.
 #