"""Build and import a minimal C extension, testpyd.pyd, using distutils.
Raise ValueError if testpyd.pyd depends on VC.CRT in WinSxS.
For Windows systems only. Requires modify permissions in current directory.
"""
import os
import re
from distutils.core import setup, Extension
# cleanup files from previous run
try:
os.remove('testpyd.pyd')
except WindowsError:
pass
# create a minimal C extension
open("testpyd.c", 'w').write("""
#include "Python.h"
PyMethodDef methods[] = {{NULL, NULL},};
void inittestpyd() {
(void)Py_InitModule("testpyd", methods);
}
""")
setup(name='testpyd', script_args=['build_ext', '--inplace'],
ext_modules=[Extension('testpyd', ['testpyd.c'],)],)
# cleanup intermediate files
try:
os.remove('testpyd.c')
except WindowsError:
pass
try:
os.system("rd.exe /Q /S build")
except:
pass
# import the generated extension
import testpyd
# search for VC.CRT assemblyIdentity in testpyd.pyd
fd = open('testpyd.pyd', 'rb')
string = fd.read()
fd.close()
pattern = r"""