1616 arch = "x64"
1717
1818class CythonBuildExt (build_ext ):
19- """ Updated version of cython build_ext command to move
20- the generated API headers to include/pysfml directory
19+ """ Updated version of cython build_ext command to deal with the
20+ generated API headers. C/C++ header files are all moved to the
21+ temporary build directory before being properly installed on
22+ the system.
2123 """
2224
2325 def cython_sources (self , sources , extension ):
26+
27+ # cythonize .pxd source files
2428 ret = build_ext .cython_sources (self , sources , extension )
2529
2630 # should result the module name; e.g, graphics[.pyx]
2731 module = os .path .basename (sources [0 ])[:- 4 ]
2832
29- # move its headers (foo.h and foo_api.h) to include/pysfml
30- destination = os .path .join ('include' , 'pysfml' )
31-
32- filename = module + '.h'
33- source = os .path .join ('src' , 'sfml' , module , filename )
34- if os .path .isfile (source ):
35- try :
36- shutil .move (source , destination )
37- except shutil .Error :
38- pass
39-
40- filename = module + '_api.h'
41- source = os .path .join ('src' , 'sfml' , module , filename )
42- if os .path .isfile (source ):
43- try :
44- shutil .move (source , destination )
45- except shutil .Error :
46- pass
33+ # prepare a list with all header files related to the module (*.hpp, *_api.h, *.h)
34+ header_files = glob (os .path .join ('src' , 'sfml' , module , '*.hpp' ))
4735
48- return ret
36+ header_files .append (os .path .join ('src' , 'sfml' , module , module + '.h' ))
37+ header_files .append (os .path .join ('src' , 'sfml' , module , module + '_api.h' ))
38+
39+ # deal with exceptions
40+ if module == "network" :
41+ header_files .remove (os .path .join ('src' , 'sfml' , module , module + '.h' ))
42+ header_files .remove (os .path .join ('src' , 'sfml' , module , module + '_api.h' ))
43+
44+ # create the temporary destination in the build directory
45+ destination = os .path .join (self .build_temp , 'include' , 'pysfml' , module )
46+
47+ if not os .path .exists (destination ):
48+ os .makedirs (destination )
49+
50+ # move all header files to the build directory
51+ for header_file in header_files :
52+ if os .path .isfile (header_file ):
53+ try :
54+ shutil .copy (header_file , destination )
55+ except shutil .Error :
56+ pass
57+
58+ # add the temporary header directory to compilation options
59+ self .compiler .include_dirs .append (os .path .join (self .build_temp , 'include' ))
60+
61+ # update data_files to install the files on the system
4962
63+ # On Windows: C:\Python27\include\pysfml\*_api.h
64+ # On Unix: /usr/local/include/pysfml/*_api.h
65+ install_directory = os .path .join (sys .exec_prefix , 'include' , 'pysfml' , module )
66+ files_to_install = [os .path .join (self .build_temp , 'include' , 'pysfml' , module , os .path .basename (header_file )) for header_file in header_files ]
67+ data_files .append ((install_directory , files_to_install ))
68+
69+ return ret
5070
5171modules = ['system' , 'window' , 'graphics' , 'audio' , 'network' ]
5272
@@ -57,7 +77,6 @@ def cython_sources(self, sources, extension):
5777include_path = os .path .join ('include' , 'pysfml' )
5878source_path = os .path .join ('src' , 'sfml' )
5979
60-
6180# clean the directory (remove generated C++ files by Cython)
6281def remove_if_exist (filename ):
6382 if os .path .isfile (filename ):
@@ -86,7 +105,7 @@ def remove_if_exist(filename):
86105 extension = lambda name , files , libs : Extension (
87106 name = 'sfml.' + name ,
88107 sources = [os .path .join ('src' , 'sfml' , name , filename ) for filename in files ],
89- include_dirs = ['include' , 'include /Includes' ],
108+ include_dirs = ['include/Includes' ],
90109 language = 'c++' ,
91110 libraries = libs ,
92111 extra_compile_args = ['-fpermissive' ]
@@ -119,29 +138,10 @@ def remove_if_exist(filename):
119138
120139major , minor , _ , _ , _ = sys .version_info
121140
122- files = []
123-
124- # Install C headers
125- c_api_headers = []
126- c_api_headers .append (os .path .join (include_path , 'system.h' ))
127- c_api_headers .append (os .path .join (include_path , 'system_api.h' ))
128- c_api_headers .append (os .path .join (include_path , 'NumericObject.hpp' ))
129- c_api_headers .append (os .path .join (include_path , 'window.h' ))
130- c_api_headers .append (os .path .join (include_path , 'window_api.h' ))
131- c_api_headers .append (os .path .join (include_path , 'graphics.h' ))
132- c_api_headers .append (os .path .join (include_path , 'graphics_api.h' ))
133- c_api_headers .append (os .path .join (include_path , 'audio_api.h' ))
134-
135- if platform .system () == 'Windows' :
136- # On Windows: C:\Python27\include\pysfml\*_api.h
137- files = [(sys .exec_prefix + '\\ include\\ pysfml' , c_api_headers )]
138- else :
139- # On Unix: /usr/local/include/pysfml/*_api.h
140- files = [(sys .exec_prefix + '/include/pysfml' , c_api_headers )]
141-
141+ data_files = []
142142if platform .system () == 'Windows' :
143143 dlls = [("Lib\\ site-packages\\ sfml" , glob ('extlibs/sfml/bin/' + arch + '/*.dll' ))]
144- files += dlls
144+ data_files += dlls
145145
146146with open ('README.rst' , 'r' ) as f :
147147 long_description = f .read ()
@@ -153,7 +153,7 @@ def remove_if_exist(filename):
153153 ext_modules = ext_modules ,
154154 package_dir = {'' : 'src' },
155155 packages = ['sfml' ],
156- data_files = files ,
156+ data_files = data_files ,
157157 version = '2.2.0' ,
158158 description = 'Python bindings for SFML' ,
159159 long_description = long_description ,
0 commit comments