Merge branch 'santagada-fix-xon.sh-python'

This commit is contained in:
Anthony Scopatz 2016-07-31 17:07:49 -04:00
commit 74f6fbbd49
2 changed files with 42 additions and 3 deletions

13
news/fix-xonsh-python.rst Normal file
View file

@ -0,0 +1,13 @@
**Added:** None
**Changed:**
* xon.sh uses the interpreter used to install instead of the default python3.
**Deprecated:** None
**Removed:** None
**Fixed:** None
**Security:** None

View file

@ -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,31 @@ 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):
"""Change default python3 to the concrete python binary used to install/develop inside xon.sh script"""
def run(self):
super().run()
if not self.dry_run:
for file in self.get_outputs():
if file.endswith('xon.sh'):
# this is the value distutils use on its shebang translation
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 +251,12 @@ if HAVE_SETUPTOOLS:
if dirty:
restore_version()
def install_script(self, dist, script_name, script_text, dev_path=None):
if script_name == 'xon.sh':
# change default python3 to the concrete python binary used to install/develop inside xon.sh script
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."""