changeset 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 c9433188ffdb
children d4874ebaa06e
files anmviewer eosd pytouhou/lib/opengl.pyxbld pytouhou/lib/sdl.pyxbld pytouhou/ui/anmrenderer.pyxbld pytouhou/ui/background.pyxbld pytouhou/ui/gamerenderer.pyxbld pytouhou/ui/gamerunner.pyxbld pytouhou/ui/renderer.pyxbld pytouhou/ui/shader.pyxbld pytouhou/ui/texture.pyxbld pytouhou/ui/window.pyxbld setup.py
diffstat 13 files changed, 13 insertions(+), 114 deletions(-) [+]
line wrap: on
line diff
--- a/anmviewer	Sat Aug 03 15:49:04 2013 +0200
+++ b/anmviewer	Fri Aug 30 14:01:09 2013 +0200
@@ -16,9 +16,6 @@
 import argparse
 import os
 
-import pyximport
-pyximport.install()
-
 from pytouhou.ui.window import Window
 from pytouhou.resource.loader import Loader
 from pytouhou.ui.anmrenderer import ANMRenderer
--- a/eosd	Sat Aug 03 15:49:04 2013 +0200
+++ b/eosd	Fri Aug 30 14:01:09 2013 +0200
@@ -52,9 +52,6 @@
 import sys
 import logging
 
-import pyximport
-pyximport.install()
-
 from pytouhou.ui.window import Window
 from pytouhou.resource.loader import Loader
 from pytouhou.ui.gamerunner import GameRunner
--- a/pytouhou/lib/opengl.pyxbld	Sat Aug 03 15:49:04 2013 +0200
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,30 +0,0 @@
-# -*- encoding: utf-8 -*-
-##
-## Copyright (C) 2013 Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
-##
-## This program is free software; you can redistribute it and/or modify
-## it under the terms of the GNU General Public License as published
-## by the Free Software Foundation; version 3 only.
-##
-## This program is distributed in the hope that it will be useful,
-## but WITHOUT ANY WARRANTY; without even the implied warranty of
-## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-## GNU General Public License for more details.
-##
-
-""" Build instructions for the OpenGL module. """
-
-from distutils.extension import Extension
-from subprocess import check_output
-
-COMMAND = 'pkg-config'
-LIBRARIES = ['gl']
-
-def make_ext(modname, pyxfilename):
-    """ Compile and link with the corrects options. """
-    compile_args = check_output([COMMAND, '--cflags'] + LIBRARIES).split()
-    link_args = check_output([COMMAND, '--libs'] + LIBRARIES).split()
-    return Extension(name=modname,
-                     sources=[pyxfilename],
-                     extra_compile_args=compile_args,
-                     extra_link_args=link_args)
--- a/pytouhou/lib/sdl.pyxbld	Sat Aug 03 15:49:04 2013 +0200
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,30 +0,0 @@
-# -*- encoding: utf-8 -*-
-##
-## Copyright (C) 2013 Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
-##
-## This program is free software; you can redistribute it and/or modify
-## it under the terms of the GNU General Public License as published
-## by the Free Software Foundation; version 3 only.
-##
-## This program is distributed in the hope that it will be useful,
-## but WITHOUT ANY WARRANTY; without even the implied warranty of
-## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-## GNU General Public License for more details.
-##
-
-""" Build instructions for the SDL module. """
-
-from distutils.extension import Extension
-from subprocess import check_output
-
-COMMAND = 'pkg-config'
-LIBRARIES = ['sdl2', 'SDL2_image', 'SDL2_mixer']
-
-def make_ext(modname, pyxfilename):
-    """ Compile and link with the corrects options. """
-    compile_args = check_output([COMMAND, '--cflags'] + LIBRARIES).split()
-    link_args = check_output([COMMAND, '--libs'] + LIBRARIES).split()
-    return Extension(name=modname,
-                     sources=[pyxfilename],
-                     extra_compile_args=compile_args,
-                     extra_link_args=link_args)
--- a/pytouhou/ui/anmrenderer.pyxbld	Sat Aug 03 15:49:04 2013 +0200
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,1 +0,0 @@
-../lib/opengl.pyxbld
\ No newline at end of file
--- a/pytouhou/ui/background.pyxbld	Sat Aug 03 15:49:04 2013 +0200
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,1 +0,0 @@
-../lib/opengl.pyxbld
\ No newline at end of file
--- a/pytouhou/ui/gamerenderer.pyxbld	Sat Aug 03 15:49:04 2013 +0200
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,1 +0,0 @@
-../lib/opengl.pyxbld
\ No newline at end of file
--- a/pytouhou/ui/gamerunner.pyxbld	Sat Aug 03 15:49:04 2013 +0200
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,1 +0,0 @@
-../lib/opengl.pyxbld
\ No newline at end of file
--- a/pytouhou/ui/renderer.pyxbld	Sat Aug 03 15:49:04 2013 +0200
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,1 +0,0 @@
-../lib/opengl.pyxbld
\ No newline at end of file
--- a/pytouhou/ui/shader.pyxbld	Sat Aug 03 15:49:04 2013 +0200
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,1 +0,0 @@
-../lib/opengl.pyxbld
\ No newline at end of file
--- a/pytouhou/ui/texture.pyxbld	Sat Aug 03 15:49:04 2013 +0200
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,1 +0,0 @@
-../lib/opengl.pyxbld
\ No newline at end of file
--- a/pytouhou/ui/window.pyxbld	Sat Aug 03 15:49:04 2013 +0200
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,1 +0,0 @@
-../lib/opengl.pyxbld
\ No newline at end of file
--- a/setup.py	Sat Aug 03 15:49:04 2013 +0200
+++ b/setup.py	Fri Aug 30 14:01:09 2013 +0200
@@ -1,16 +1,14 @@
 # -*- encoding: utf-8 -*-
 
-import os, sys
+import os
+import sys
 from distutils.core import setup
 from distutils.extension import Extension
-from distutils.command.build_scripts import build_scripts
-from distutils.dep_util import newer
-from distutils import log
 from subprocess import check_output
 
 # Cython is needed
 try:
-    from Cython.Distutils import build_ext
+    from Cython.Build import cythonize
 except ImportError:
     print('You don’t seem to have Cython installed. Please get a '
           'copy from www.cython.org and install it')
@@ -25,30 +23,11 @@
 extensions = []
 
 
-
-# The installed script shouldn't call pyximport, strip references to it
-class BuildScripts(build_scripts):
-    def copy_scripts(self):
-        self.mkpath('scripts')
-        for script in (os.path.basename(script) for script in self.scripts):
-            outfile = os.path.join('scripts', script)
-            if not self.force and not newer(script, outfile):
-                log.debug("not copying %s (up-to-date)", script)
-            elif not self.dry_run:
-                with open(script, 'r') as file, open(outfile, 'w') as out:
-                    for line in file:
-                        if not 'pyximport' in line:
-                            out.write(line)
-
-        build_scripts.copy_scripts(self)
-
-
-
 for directory, _, files in os.walk('pytouhou'):
     package = directory.replace(os.path.sep, '.')
     packages.append(package)
     for filename in files:
-        if filename.endswith('.pyx'):
+        if filename.endswith('.pyx') or filename.endswith('.py') and not filename == '__init__.py':
             extension_name = '%s.%s' % (package, os.path.splitext(filename)[0])
             extension_names.append(extension_name)
             if extension_name == 'pytouhou.lib.sdl':
@@ -66,31 +45,25 @@
                                         extra_link_args=link_args))
 
 
-
 # TODO: find a less-intrusive, cleaner way to do this...
 try:
     from cx_Freeze import setup, Executable
 except ImportError:
     extra = {}
 else:
-    extra = {
-             'options': {'build_exe': {'includes': extension_names}},
-             'executables': [Executable(script='scripts/eosd', base='Win32GUI')]
-            }
-
+    extra = {'options': {'build_exe': {'includes': extension_names}},
+             'executables': [Executable(script='eosd', base='Win32GUI')]}
 
 
 setup(name='PyTouhou',
-      version="0.1",
+      version='0.1',
       author='Thibaut Girka',
       author_email='thib@sitedethib.com',
-      url='http://hg.sitedethib.com/touhou/',
+      url='http://pytouhou.linkmauve.fr/',
       license='GPLv3',
       packages=packages,
-      ext_modules=extensions,
-      scripts=['scripts/eosd', 'scripts/anmviewer'],
-      cmdclass={'build_ext': build_ext,
-                'build_scripts': BuildScripts},
-      **extra
-     )
-
+      ext_modules=cythonize(extensions, nthreads=4,
+                            compiler_directives={'infer_types': True,
+                                                 'infer_types.verbose': True}),
+      scripts=['eosd', 'anmviewer'],
+      **extra)