changeset 219:091301805cce

Move “eclviewer.py” to “eosd” and get rid of run-time depency on Cython.
author Thibaut Girka <thib@sitedethib.com>
date Thu, 15 Dec 2011 19:24:11 +0100
parents 9634eefd2063
children 0595315d3880
files eclviewer.py eosd setup.py
diffstat 3 files changed, 97 insertions(+), 75 deletions(-) [+]
line wrap: on
line diff
--- a/eclviewer.py	Mon Dec 05 23:57:58 2011 +0100
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,74 +0,0 @@
-#!/usr/bin/env python
-# -*- encoding: utf-8 -*-
-##
-## Copyright (C) 2011 Thibaut Girka <thib@sitedethib.com>
-##
-## 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.
-##
-
-import argparse
-import os
-
-import pyximport
-pyximport.install()
-
-from pytouhou.resource.loader import Loader
-from pytouhou.game.background import Background
-from pytouhou.ui.gamerunner import GameRunner
-from pytouhou.games.eosd import EoSDGame
-from pytouhou.game.player import PlayerState
-from pytouhou.formats.t6rp import T6RP
-
-
-def main(path, stage_num, rank, character, replay, data):
-    if replay:
-        with open(replay, 'rb') as file:
-            replay = T6RP.read(file)
-        rank = replay.rank
-        character = replay.character
-        if not replay.levels[stage_num-1]:
-            raise Exception
-        from pytouhou.utils.random import Random
-        prng = Random(replay.levels[stage_num-1].random_seed)
-    else:
-        prng = None
-
-    resource_loader = Loader()
-    resource_loader.scan_archives(os.path.join(path, name)
-                                    for name in data)
-    game = EoSDGame(resource_loader, [PlayerState(character=character)], stage_num, rank, 16,
-                    prng=prng)
-
-    # Load stage data
-    stage = resource_loader.get_stage('stage%d.std' % stage_num)
-
-    background_anm_wrapper = resource_loader.get_anm_wrapper(('stg%dbg.anm' % stage_num,))
-    background = Background(stage, background_anm_wrapper)
-
-    # Let's go!
-    print(stage.name)
-
-    # Main loop
-    runner = GameRunner(resource_loader, game, background, replay=replay)
-    runner.start()
-
-
-parser = argparse.ArgumentParser(description='Libre reimplementation of the Touhou 6 engine.')
-
-parser.add_argument('data', metavar='DAT', default=('CM.DAT', 'ST.DAT'), nargs='*', help='Game’s .DAT data files')
-parser.add_argument('-p', '--path', metavar='DIRECTORY', default='.', help='Game directory path.')
-parser.add_argument('-s', '--stage', metavar='STAGE', type=int, required=True, help='Stage, 1 to 7 (Extra).')
-parser.add_argument('-r', '--rank', metavar='RANK', type=int, default=0, help='Rank, from 0 (Easy, default) to 3 (Lunatic).')
-parser.add_argument('-c', '--character', metavar='CHARACTER', type=int, default=0, help='Select the character to use, from 0 (ReimuA, default) to 3 (MarisaB).')
-parser.add_argument('--replay', metavar='REPLAY', help='Select a replay')
-
-args = parser.parse_args()
-
-main(args.path, args.stage, args.rank, args.character, args.replay, tuple(args.data))
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/eosd	Thu Dec 15 19:24:11 2011 +0100
@@ -0,0 +1,74 @@
+#!/usr/bin/env python
+# -*- encoding: utf-8 -*-
+##
+## Copyright (C) 2011 Thibaut Girka <thib@sitedethib.com>
+##
+## 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.
+##
+
+import argparse
+import os
+
+import pyximport
+pyximport.install()
+
+from pytouhou.resource.loader import Loader
+from pytouhou.game.background import Background
+from pytouhou.ui.gamerunner import GameRunner
+from pytouhou.games.eosd import EoSDGame
+from pytouhou.game.player import PlayerState
+from pytouhou.formats.t6rp import T6RP
+
+
+def main(path, stage_num, rank, character, replay, data):
+    if replay:
+        with open(replay, 'rb') as file:
+            replay = T6RP.read(file)
+        rank = replay.rank
+        character = replay.character
+        if not replay.levels[stage_num-1]:
+            raise Exception
+        from pytouhou.utils.random import Random
+        prng = Random(replay.levels[stage_num-1].random_seed)
+    else:
+        prng = None
+
+    resource_loader = Loader()
+    resource_loader.scan_archives(os.path.join(path, name)
+                                    for name in data)
+    game = EoSDGame(resource_loader, [PlayerState(character=character)], stage_num, rank, 16,
+                    prng=prng)
+
+    # Load stage data
+    stage = resource_loader.get_stage('stage%d.std' % stage_num)
+
+    background_anm_wrapper = resource_loader.get_anm_wrapper(('stg%dbg.anm' % stage_num,))
+    background = Background(stage, background_anm_wrapper)
+
+    # Let's go!
+    print(stage.name)
+
+    # Main loop
+    runner = GameRunner(resource_loader, game, background, replay=replay)
+    runner.start()
+
+
+parser = argparse.ArgumentParser(description='Libre reimplementation of the Touhou 6 engine.')
+
+parser.add_argument('data', metavar='DAT', default=('CM.DAT', 'ST.DAT'), nargs='*', help='Game’s .DAT data files')
+parser.add_argument('-p', '--path', metavar='DIRECTORY', default='.', help='Game directory path.')
+parser.add_argument('-s', '--stage', metavar='STAGE', type=int, required=True, help='Stage, 1 to 7 (Extra).')
+parser.add_argument('-r', '--rank', metavar='RANK', type=int, default=0, help='Rank, from 0 (Easy, default) to 3 (Lunatic).')
+parser.add_argument('-c', '--character', metavar='CHARACTER', type=int, default=0, help='Select the character to use, from 0 (ReimuA, default) to 3 (MarisaB).')
+parser.add_argument('--replay', metavar='REPLAY', help='Select a replay')
+
+args = parser.parse_args()
+
+main(args.path, args.stage, args.rank, args.character, args.replay, tuple(args.data))
--- a/setup.py	Mon Dec 05 23:57:58 2011 +0100
+++ b/setup.py	Thu Dec 15 19:24:11 2011 +0100
@@ -3,6 +3,9 @@
 import os, 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
 
 
 # Cython is needed
@@ -14,6 +17,22 @@
     sys.exit(1)
 
 
+# The installed script shouldn't call pyximport, strip references to it
+class BuildScripts(build_scripts):
+    def copy_scripts(self):
+        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)
+
+        orig_build_scripts.copy_scripts(self)
+
+
 packages = []
 extensions = []
 
@@ -27,6 +46,7 @@
                                         [os.path.join(directory, filename)]))
 
 
+
 setup(name='PyTouhou',
       author='Thibaut Girka',
       author_email='thib@sitedethib.com',
@@ -34,6 +54,8 @@
       license='GPLv3',
       packages=packages,
       ext_modules=extensions,
-      cmdclass = {'build_ext': build_ext}
+      scripts=['scripts/eosd'],
+      cmdclass={'build_ext': build_ext,
+                'build_scripts': BuildScripts}
      )