Commits

Jakub Wilk committed f2cab03

setup: don't spawn sed; use pure-Python code to edit *.c files.

Comments (0)

Files changed (1)

 
 import glob
 import os
+import re
 import sys
 import subprocess as ipc
 
                 distutils.spawn.spawn(['cython', source])
                 # XXX This is needed to work around <http://bugs.debian.org/607112>.
                 # Fortunately, python-djvulibre doesn't really need __Pyx_GetVtable().
-                distutils.spawn.spawn(['sed', '-i~', '-e',
-                    r's/\(static int __Pyx_GetVtable(PyObject [*]dict, void [*]vtabptr) {\)/\1 return 0;/',
-                    target
-                ])
+                file = open(target, 'r+')
+                try:
+                    contents = file.read()
+                    contents = re.compile(
+                        r'(?<=^static int __Pyx_GetVtable\(PyObject [*]dict, void [*]vtabptr\) {)$',
+                        re.MULTILINE
+                    ).sub(' return 0;', contents)
+                    file.seek(0)
+                    file.truncate()
+                    file.write(contents)
+                finally:
+                    file.close()
             self.make_file(depends, target, build_c, [source, target])
 
 class clean(distutils.command.clean.clean):
 
     def run(self):
         if self.all:
-            for wildcard in 'djvu/*.c', 'djvu/*.c~', 'djvu/config.pxi':
+            for wildcard in 'djvu/*.c', 'djvu/config.pxi':
                 filenames = glob.glob(wildcard)
                 if filenames:
                     distutils.log.info('removing %r', wildcard)