From e93aafb40d0c958e43bd4db4ddae1453f7cf8965 Mon Sep 17 00:00:00 2001 From: Ethan White Date: Sun, 20 Oct 2013 22:01:59 -0700 Subject: [PATCH] swc-windows-installer.py: Bring in Ethan's make_bash_profile and make_posix_path This integerates some of Ethan's nano-installer changes. In the pull request, Ethan elaborates on the .bash_profile choice [1]: In response to comments on the Tutors list the installer now uses .bash_profile instead of .bashrc and appends the lines rather than overwriting the file. I have also added comments that indicate where the new lines in .bash_profile come from. Once the Python version is in I'll move on to getting this compiled into a .exe file, which should be more familiar to our students and won't run into issues with Canopy installs opening the file in Canopy rather than executing it. The referenced tutors@ discussion is in the messages leading up to [2], where Ethan top-quotes a discussion with R. David Murray about the relative merits of .bash_profile and .bashrc. The imporant point David made was that .bash_profile is only executed once at login, while .bashrc is executed for each new shell. Putting PATH appends in .bash_profile means that you don't end up adding duplicate entries to the PATH as you spawn subshells. For example: ${ORIGINAL_PATH}:${NANO_PATH}:${NANO_PATH}:... [1]: https://github.com/swcarpentry/bc/pull/35 [2]: http://lists.software-carpentry.org/pipermail/tutors_lists.software-carpentry.org/2013-September/000969.html --- setup/swc-windows-installer.py | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/setup/swc-windows-installer.py b/setup/swc-windows-installer.py index c0bde19..c4c7f41 100755 --- a/setup/swc-windows-installer.py +++ b/setup/swc-windows-installer.py @@ -67,6 +67,28 @@ def create_nosetests_entry_point(python_scripts_directory): f.write(contents) +def make_bash_profile(home_dir, nano_dir): + """Creates a .bash_profile file for nano setup + + Adds nano to the path and sets the default editor to nano + + """ + + nano_path = make_posix_path(nano_dir) + contents = '\n'.join(['', + '# Add nano to path and set as default editor', + '# Added by the Software Carpentry nano installer', + 'export PATH=$PATH:%s' % nano_path, + 'export EDITOR=nano', + '']) + with open(os.path.join(home_dir, '.bash_profile'), 'a') as f: + f.write(contents) + +def make_posix_path(windows_path): + """Convert a Windows path to a posix path""" + return windows_path.replace('\\', '/').replace('C:', '/c') + + def main(): python_scripts_directory = "C:\\Anaconda\\Scripts\\" #python_scripts_directory = "./scripts/" -- 2.26.2