comparison setup.py @ 431:77c0e9a53795

Use cythonize in setup.py, also compile .py files, and entirely remove pyximport support.
author Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
date Fri, 30 Aug 2013 14:01:09 +0200
parents d8630c086926
children d56536ef28e8
comparison
equal deleted inserted replaced
430:c9433188ffdb 431:77c0e9a53795
1 # -*- encoding: utf-8 -*- 1 # -*- encoding: utf-8 -*-
2 2
3 import os, sys 3 import os
4 import sys
4 from distutils.core import setup 5 from distutils.core import setup
5 from distutils.extension import Extension 6 from distutils.extension import Extension
6 from distutils.command.build_scripts import build_scripts
7 from distutils.dep_util import newer
8 from distutils import log
9 from subprocess import check_output 7 from subprocess import check_output
10 8
11 # Cython is needed 9 # Cython is needed
12 try: 10 try:
13 from Cython.Distutils import build_ext 11 from Cython.Build import cythonize
14 except ImportError: 12 except ImportError:
15 print('You don’t seem to have Cython installed. Please get a ' 13 print('You don’t seem to have Cython installed. Please get a '
16 'copy from www.cython.org and install it') 14 'copy from www.cython.org and install it')
17 sys.exit(1) 15 sys.exit(1)
18 16
23 packages = [] 21 packages = []
24 extension_names = [] 22 extension_names = []
25 extensions = [] 23 extensions = []
26 24
27 25
28
29 # The installed script shouldn't call pyximport, strip references to it
30 class BuildScripts(build_scripts):
31 def copy_scripts(self):
32 self.mkpath('scripts')
33 for script in (os.path.basename(script) for script in self.scripts):
34 outfile = os.path.join('scripts', script)
35 if not self.force and not newer(script, outfile):
36 log.debug("not copying %s (up-to-date)", script)
37 elif not self.dry_run:
38 with open(script, 'r') as file, open(outfile, 'w') as out:
39 for line in file:
40 if not 'pyximport' in line:
41 out.write(line)
42
43 build_scripts.copy_scripts(self)
44
45
46
47 for directory, _, files in os.walk('pytouhou'): 26 for directory, _, files in os.walk('pytouhou'):
48 package = directory.replace(os.path.sep, '.') 27 package = directory.replace(os.path.sep, '.')
49 packages.append(package) 28 packages.append(package)
50 for filename in files: 29 for filename in files:
51 if filename.endswith('.pyx'): 30 if filename.endswith('.pyx') or filename.endswith('.py') and not filename == '__init__.py':
52 extension_name = '%s.%s' % (package, os.path.splitext(filename)[0]) 31 extension_name = '%s.%s' % (package, os.path.splitext(filename)[0])
53 extension_names.append(extension_name) 32 extension_names.append(extension_name)
54 if extension_name == 'pytouhou.lib.sdl': 33 if extension_name == 'pytouhou.lib.sdl':
55 compile_args = check_output([COMMAND, '--cflags'] + LIBRARIES).split() 34 compile_args = check_output([COMMAND, '--cflags'] + LIBRARIES).split()
56 link_args = check_output([COMMAND, '--libs'] + LIBRARIES).split() 35 link_args = check_output([COMMAND, '--libs'] + LIBRARIES).split()
64 [os.path.join(directory, filename)], 43 [os.path.join(directory, filename)],
65 extra_compile_args=compile_args, 44 extra_compile_args=compile_args,
66 extra_link_args=link_args)) 45 extra_link_args=link_args))
67 46
68 47
69
70 # TODO: find a less-intrusive, cleaner way to do this... 48 # TODO: find a less-intrusive, cleaner way to do this...
71 try: 49 try:
72 from cx_Freeze import setup, Executable 50 from cx_Freeze import setup, Executable
73 except ImportError: 51 except ImportError:
74 extra = {} 52 extra = {}
75 else: 53 else:
76 extra = { 54 extra = {'options': {'build_exe': {'includes': extension_names}},
77 'options': {'build_exe': {'includes': extension_names}}, 55 'executables': [Executable(script='eosd', base='Win32GUI')]}
78 'executables': [Executable(script='scripts/eosd', base='Win32GUI')]
79 }
80
81 56
82 57
83 setup(name='PyTouhou', 58 setup(name='PyTouhou',
84 version="0.1", 59 version='0.1',
85 author='Thibaut Girka', 60 author='Thibaut Girka',
86 author_email='thib@sitedethib.com', 61 author_email='thib@sitedethib.com',
87 url='http://hg.sitedethib.com/touhou/', 62 url='http://pytouhou.linkmauve.fr/',
88 license='GPLv3', 63 license='GPLv3',
89 packages=packages, 64 packages=packages,
90 ext_modules=extensions, 65 ext_modules=cythonize(extensions, nthreads=4,
91 scripts=['scripts/eosd', 'scripts/anmviewer'], 66 compiler_directives={'infer_types': True,
92 cmdclass={'build_ext': build_ext, 67 'infer_types.verbose': True}),
93 'build_scripts': BuildScripts}, 68 scripts=['eosd', 'anmviewer'],
94 **extra 69 **extra)
95 )
96