From: W. Trevor King Date: Wed, 20 Mar 2013 22:58:18 +0000 (-0400) Subject: swc-windows-installer.py: Use `with` to write script wrappers X-Git-Tag: v0.1~36 X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=dca9218f3886899f8fc7a011497b87271852649d;p=swc-setup-windows-installer.git swc-windows-installer.py: Use `with` to write script wrappers From PEP 343. This gives you automatic file descriptor (file handles on Windows?) cleanup on errors. Also use os.path.join() to build the paths. [1]: http://www.python.org/dev/peps/pep-0343/ --- diff --git a/setup/swc-windows-installer.py b/setup/swc-windows-installer.py index 3ce1fbf..42914ab 100755 --- a/setup/swc-windows-installer.py +++ b/setup/swc-windows-installer.py @@ -42,25 +42,25 @@ def install_nano(install_directory): def create_ipython_entry_point(python_scripts_directory): """Creates a terminal-based IPython entry point for msysgit""" - output_file = open(python_scripts_directory + 'ipython', 'w') - file_contents = """#!/usr/bin/env python + contents = """#!/usr/bin/env python from IPython.frontend.terminal.ipapp import launch_new_instance launch_new_instance() """ - - output_file.write(file_contents) + with open(os.path.join(python_scripts_directory, 'ipython'), 'w') as f: + f.write(contents) def create_nosetests_entry_point(python_scripts_directory): """Creates a terminal-based nosetests entry point for msysgit""" - output_file = open(python_scripts_directory + 'nosetests', 'w') - file_contents = """#!/usr/bin/env/ python + contents = """#!/usr/bin/env/ python import sys import nose if __name__ == '__main__': sys.exit(nose.core.main()) """ - output_file.write(file_contents) + with open(os.path.join(python_scripts_directory, 'nosetests'), 'w') as f: + f.write(contents) + def main(): python_scripts_directory = "C:\\Anaconda\\Scripts\\"