Skip to content

Commit 4643bcc

Browse files
committed
Set actual interpreter path to robot.bat and rebot.bat. robotframework#2216
1 parent 26b48c6 commit 4643bcc

File tree

1 file changed

+18
-22
lines changed

1 file changed

+18
-22
lines changed

setup.py

Lines changed: 18 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import sys
44
import os
55
from os.path import abspath, join, dirname
6+
from subprocess import list2cmdline
67
from distutils.core import setup
78
from distutils.command.install_scripts import install_scripts
89

@@ -55,40 +56,35 @@
5556
for pattern in ('*.html', '*.css', '*.js')]
5657
WINDOWS = os.sep == '\\'
5758
if sys.platform.startswith('java'):
58-
SCRIPTS = ['jybot', 'jyrebot', 'robot', 'rebot']
59-
INTERPRETER = 'jython'
59+
SCRIPTS = ['jybot', 'jyrebot']
6060
elif sys.platform == 'cli':
61-
SCRIPTS = ['ipybot', 'ipyrebot', 'robot', 'rebot']
62-
INTERPRETER = 'ipy'
61+
SCRIPTS = ['ipybot', 'ipyrebot']
6362
else:
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']]
6765
if WINDOWS:
6866
SCRIPTS = [s+'.bat' for s in SCRIPTS]
6967
if '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

9490
setup(
@@ -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

Comments
 (0)