1 import pyximport
; pyximport
.install(reload_support
=True)
7 tempdir
= os
.path
.join(tempfile
.gettempdir(), "pyrex_temp")
8 if os
.path
.exists(tempdir
):
9 remove_tempdir(tempdir
)
14 def remove_tempdir(tempdir
):
15 shutil
.rmtree(tempdir
, 0, on_remove_file_error
)
17 def on_remove_file_error(func
, path
, excinfo
):
18 print "Sorry! Could not remove a temp file:", path
19 print "Extra information."
21 print "You may want to delete this yourself when you get a chance."
24 pyximport
._test
_files
= []
25 tempdir
= make_tempdir()
26 sys
.path
.append(tempdir
)
27 filename
= os
.path
.join(tempdir
, "dummy.pyx")
28 open(filename
, "w").write("print 'Hello world from the Pyrex install hook'")
32 depend_filename
= os
.path
.join(tempdir
, "dummy.pyxdep")
33 depend_file
= open(depend_filename
, "w")
34 depend_file
.write("*.txt\nfoo.bar")
37 build_filename
= os
.path
.join(tempdir
, "dummy.pyxbld")
38 build_file
= open(build_filename
, "w")
40 from distutils.extension import Extension
41 def make_ext(name, filename):
42 return Extension(name=name, sources=[filename])
46 open(os
.path
.join(tempdir
, "foo.bar"), "w").write(" ")
47 open(os
.path
.join(tempdir
, "1.txt"), "w").write(" ")
48 open(os
.path
.join(tempdir
, "abc.txt"), "w").write(" ")
50 assert len(pyximport
._test
_files
)==1, pyximport
._test
_files
53 time
.sleep(1) # sleep a second to get safer mtimes
54 open(os
.path
.join(tempdir
, "abc.txt"), "w").write(" ")
55 print "Here goes the reolad"
57 assert len(pyximport
._test
_files
) == 1, pyximport
._test
_files
60 assert len(pyximport
._test
_files
) ==0, pyximport
._test
_files
61 remove_tempdir(tempdir
)
63 if __name__
=="__main__":