Patchwork [7,of,7,v2] setup: write mercurial/modulepolicy for pure installs

login
register
mail settings
Submitter timeless@mozdev.org
Date Jan. 12, 2016, 5:23 a.m.
Message ID <17a8577c785046591d30.1452576189@waste.org>
Download mbox | patch
Permalink /patch/12677/
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 1452574025 0
#      Tue Jan 12 04:47:05 2016 +0000
# Node ID 17a8577c785046591d30f0b70ef6aff154c96720
# Parent  dc89d0d3d9c1a422e0c2e2550d554357c54d7a2a
setup: write mercurial/modulepolicy for pure installs


This file tells the Mercurial loader to use Python libraries,
which is what the user wanted when they ran setup --pure.

Patch

diff --git a/setup.py b/setup.py
--- a/setup.py
+++ b/setup.py
@@ -353,15 +353,22 @@ 
     def copy_file(self, *args, **kwargs):
         src, dst = args[0:2]
         copied = False
+        inplace = False
         if './' + src != dst:
             dst, copied = build_py.copy_file(self, *args, **kwargs)
+        else:
+            inplace = True
 
         if dst.endswith('mercurial/__init__.py'):
             if self.distribution.pure:
                 modulepolicy = 'py'
             else:
                 modulepolicy = 'c'
-            if copied:
+            if inplace:
+                policy = os.path.join(os.path.dirname(dst), 'modulepolicy')
+                with open(policy, 'wb') as fh:
+                    fh.write(modulepolicy)
+            elif copied:
                 content = open(dst, 'rb').read()
                 content = content.replace(b'@MODULELOADPOLICY@',
                                           modulepolicy.encode(libdir_escape))