33import sys
44import os
55from os .path import abspath , join , dirname
6+ from subprocess import list2cmdline
67from distutils .core import setup
78from distutils .command .install_scripts import install_scripts
89
5556 for pattern in ('*.html' , '*.css' , '*.js' )]
5657WINDOWS = os .sep == '\\ '
5758if sys .platform .startswith ('java' ):
58- SCRIPTS = ['jybot' , 'jyrebot' , 'robot' , 'rebot' ]
59- INTERPRETER = 'jython'
59+ SCRIPTS = ['jybot' , 'jyrebot' ]
6060elif sys .platform == 'cli' :
61- SCRIPTS = ['ipybot' , 'ipyrebot' , 'robot' , 'rebot' ]
62- INTERPRETER = 'ipy'
61+ SCRIPTS = ['ipybot' , 'ipyrebot' ]
6362else :
64- SCRIPTS = ['pybot' , 'rebot' , 'robot' ]
65- INTERPRETER = 'python'
66- SCRIPTS = [join ('src' , 'bin' , s ) for s in SCRIPTS ]
63+ SCRIPTS = ['pybot' ]
64+ SCRIPTS = [join ('src' , 'bin' , s ) for s in SCRIPTS + ['robot' , 'rebot' ]]
6765if WINDOWS :
6866 SCRIPTS = [s + '.bat' for s in SCRIPTS ]
6967if 'bdist_wininst' in sys .argv :
7068 SCRIPTS .append ('robot_postinstall.py' )
7169 LONG_DESCRIPTION = WINDOWS_DESCRIPTION
7270
7371
74- def replace_interpreter (filepath ):
75- with open (filepath , 'r' ) as input :
76- replaced = input .read ().replace ('python' , INTERPRETER )
77- with open (filepath , 'w' ) as output :
78- output .write (replaced )
72+ class custom_install_scripts (install_scripts ):
7973
80-
81- class install_scripts_and_replace_bat_interpreter (install_scripts ):
8274 def run (self ):
8375 install_scripts .run (self )
84- if not WINDOWS or INTERPRETER == 'python' :
85- return
76+ if WINDOWS :
77+ self ._replace_interpreter_in_bat_files ()
78+
79+ def _replace_interpreter_in_bat_files (self ):
8680 print ("replacing interpreter in robot.bat and rebot.bat." )
87- for filepath in self .get_outputs ():
88- if filepath .endswith ('robot.bat' ):
89- replace_interpreter (filepath )
90- if filepath .endswith ('rebot.bat' ):
91- replace_interpreter (filepath )
81+ interpreter = list2cmdline ([sys .executable ])
82+ for path in self .get_outputs ():
83+ if path .endswith (('robot.bat' , 'rebot.bat' )):
84+ with open (path , 'r' ) as input :
85+ replaced = input .read ().replace ('python' , interpreter )
86+ with open (path , 'w' ) as output :
87+ output .write (replaced )
9288
9389
9490setup (
@@ -104,9 +100,9 @@ def run(self):
104100 keywords = KEYWORDS ,
105101 platforms = 'any' ,
106102 classifiers = CLASSIFIERS ,
107- cmdclass = {'install_scripts' : install_scripts_and_replace_bat_interpreter },
108103 package_dir = {'' : 'src' },
109104 package_data = {'robot' : PACKAGE_DATA },
110105 packages = PACKAGES ,
111106 scripts = SCRIPTS ,
107+ cmdclass = {'install_scripts' : custom_install_scripts }
112108)
0 commit comments