From 1d71395f6b1681431e2aa2d57ec5d1ae38e4a58a Mon Sep 17 00:00:00 2001 From: Leonardo Santagada Date: Fri, 29 Jul 2016 17:49:06 +0200 Subject: [PATCH] fix xon.sh to make it take the current python and not a generic python3 --- setup.py | 30 +++++++++++++++++++++++++++--- 1 file changed, 27 insertions(+), 3 deletions(-) diff --git a/setup.py b/setup.py index 85122384f..e515ecae4 100755 --- a/setup.py +++ b/setup.py @@ -181,7 +181,7 @@ class xinstall(install): import traceback traceback.print_exc() print('Installing Jupyter hook failed.') - install.run(self) + super().run() if dirty: restore_version() @@ -193,7 +193,7 @@ class xsdist(sdist): build_tables() amalgamate_source() dirty = dirty_version() - sdist.make_release_tree(self, basedir, files) + super().make_release_tree(basedir, files) if dirty: restore_version() @@ -213,11 +213,30 @@ class install_scripts_quoted_shebang(install_scripts): contents = contents.replace(shebang, quoted_shebang) super().write_script(script_name, contents, mode, *ignored) + +class install_scripts_rewrite(install_scripts): + """Rewrite python3 to the current python executable""" + def run(self): + super().run() + if os.name == 'posix' and not self.dry_run: + for file in self.get_outputs(): + if file.endswith('xon.sh'): + bs_cmd = self.get_finalized_command('build_scripts') + exec_param = getattr(bs_cmd, 'executable', None) + + with open(file, 'r') as f: + content = f.read() + + processed = content.replace(' python3 ', ' {} '.format(exec_param)) + + with open(file, 'w') as f: + f.write(processed) + # The custom install needs to be used on Windows machines if os.name == 'nt': cmdclass = {'install': xinstall, 'sdist': xsdist, 'install_scripts': install_scripts_quoted_shebang} else: - cmdclass = {'install': xinstall, 'sdist': xsdist} + cmdclass = {'install': xinstall, 'sdist': xsdist, 'install_scripts': install_scripts_rewrite} if HAVE_SETUPTOOLS: @@ -231,6 +250,11 @@ if HAVE_SETUPTOOLS: if dirty: restore_version() + def install_script(self, dist, script_name, script_text, dev_path=None): + if script_name == 'xon.sh': + script_text = script_text.replace(' python3 ', ' {} '.format(sys.executable)) + super().install_script(dist, script_name, script_text, dev_path) + def main(): """The main entry point."""