From 4081185185a24440d84998ecaf8eaabd8de354b4 Mon Sep 17 00:00:00 2001 From: "Ankur Sinha (Ankur Sinha Gmail)" Date: Sat, 20 Jun 2020 20:10:56 +0100 Subject: [PATCH 1/4] Whitespace fixes --- getNeuroML.py | 53 ++++++++++++++++++++++----------------------------- 1 file changed, 23 insertions(+), 30 deletions(-) diff --git a/getNeuroML.py b/getNeuroML.py index d55ba1a..de331c7 100644 --- a/getNeuroML.py +++ b/getNeuroML.py @@ -5,6 +5,7 @@ import os.path as op import subprocess + def main(): """Main""" mode = "update" @@ -50,9 +51,7 @@ def main(): # Which repos use a development branch? dev_branch_repos = neuroml2_spec_repo + neuroml_repos + jlems_repo - - all_repos = lems_repos + neuroml_repos - + all_repos = lems_repos + neuroml_repos # Set the preferred method for cloning from GitHub github_pref = "HTTP" @@ -69,22 +68,21 @@ def main(): local_dir = ".." + os.sep + repo.split("/")[1] if mode is "clean": - print("------ Cleaning: %s -------"%repo) + print("------ Cleaning: %s -------" % repo) if repo in java_repos: command = "mvn clean" print("It's a Java repository, so cleaning using Maven...") info = execute_command_in_dir(command, local_dir) if mode is "update": - - print("------ Updating: %s -------" %repo) + print("------ Updating: %s -------" % repo) runMvnInstall = False if not op.isdir(local_dir): command = "git clone %s%s" % (pre_gh[github_pref], repo) - print ("Creating a new directory: %s by cloning from GitHub" % \ - (local_dir)) + print("Creating a new directory: %s by cloning from GitHub" % + (local_dir)) execute_command_in_dir(command, "..") runMvnInstall = True @@ -92,7 +90,7 @@ def main(): if switch_to_branch: if (repo in dev_branch_repos): command = "git checkout %s" % (switch_to_branch) - print ("Switching to branch: %s" % (switch_to_branch)) + print("Switching to branch: %s" % (switch_to_branch)) exit_on_fail = switch_to_branch is not "experimental" execute_command_in_dir(command, local_dir, exit_on_fail) runMvnInstall = True @@ -112,36 +110,31 @@ def main(): print("It's a Java repository, so installing using Maven...") info = execute_command_in_dir(command, local_dir) - #The code below needs a non trivial rewrite due to python3 differences. - - # + # The code below needs a non trivial rewrite due to python3 differences. if str("BUILD SUCCESS") in str(info): - print("Successful installation using : %s!" %command) + print("Successful installation using : %s!" % command) else: - print("Problem installing using : %s!" %command) + print("Problem installing using : %s!" % command) print(info) exit(1) if mode is "update": print("All repositories successfully updated & Java modules built!") - print("You should be able to run some examples straight " \ - "away using jnml: ") + print("You should be able to run some examples straight away using jnml: ") if os.name is not 'nt': - print(" ./jnml "\ - "-validate ../NeuroML2/examples/NML2_FullNeuroML.nml") - print(" ./jnml " \ - "../NeuroML2/LEMSexamples/LEMS_NML2_Ex2_Izh.xml") + print(" ./jnml " + + "-validate ../NeuroML2/examples/NML2_FullNeuroML.nml") + print(" ./jnml " + + "../NeuroML2/LEMSexamples/LEMS_NML2_Ex2_Izh.xml") else: - print(" jnml -validate " \ - "..\\NeuroML2\\examples\\NML2_FullNeuroML.nml") - print(" jnml " \ - "..\\NeuroML2\\LEMSexamples\\LEMS_NML2_Ex2_Izh.xml") + print(" jnml -validate " + + "..\\NeuroML2\\examples\\NML2_FullNeuroML.nml") + print(" jnml " + + "..\\NeuroML2\\LEMSexamples\\LEMS_NML2_Ex2_Izh.xml") if mode is "clean": print("All repositories successfully cleaned!") - - def execute_command_in_dir(command, directory, exit_on_fail=True): """Execute a command in specific working directory""" if os.name == 'nt': @@ -152,10 +145,10 @@ def execute_command_in_dir(command, directory, exit_on_fail=True): p = subprocess.Popen(command, cwd=directory, shell=True, stdout=subprocess.PIPE) return_str = p.communicate() - if p.returncode != 0: - print("Error: %s" % p.returncode) + if p.returncode != 0: + print("Error: %s" % p.returncode) print(return_str[0]) - if exit_on_fail: + if exit_on_fail: exit(p.returncode) if (sys.version_info > (3, 0)): return return_str[0].decode("utf-8") @@ -167,7 +160,7 @@ def help_info(): print("\nUsage:\n\n python getNeuroML.py\n " \ "Pull (or clone) the latest version of all NeuroML 2 repos & " \ "compile/install with Maven if applicable\n\n" \ - " python getNeuroML.py clean\n " + " python getNeuroML.py clean\n " "Run 'mvn clean' on all Java repos\n\n" \ " python getNeuroML.py master\n " \ "Switch all repos to master branch\n\n" \ From d1346e4f3cc694cee97d0727a81a707546276784 Mon Sep 17 00:00:00 2001 From: "Ankur Sinha (Ankur Sinha Gmail)" Date: Sat, 20 Jun 2020 20:12:29 +0100 Subject: [PATCH 2/4] Use equality operators for comparison instead of 'is/is not' --- getNeuroML.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/getNeuroML.py b/getNeuroML.py index de331c7..bdb0a01 100644 --- a/getNeuroML.py +++ b/getNeuroML.py @@ -67,14 +67,14 @@ def main(): local_dir = ".." + os.sep + repo.split("/")[1] - if mode is "clean": + if mode == "clean": print("------ Cleaning: %s -------" % repo) if repo in java_repos: command = "mvn clean" print("It's a Java repository, so cleaning using Maven...") info = execute_command_in_dir(command, local_dir) - if mode is "update": + if mode == "update": print("------ Updating: %s -------" % repo) runMvnInstall = False @@ -91,7 +91,7 @@ def main(): if (repo in dev_branch_repos): command = "git checkout %s" % (switch_to_branch) print("Switching to branch: %s" % (switch_to_branch)) - exit_on_fail = switch_to_branch is not "experimental" + exit_on_fail = switch_to_branch != "experimental" execute_command_in_dir(command, local_dir, exit_on_fail) runMvnInstall = True @@ -118,10 +118,10 @@ def main(): print(info) exit(1) - if mode is "update": + if mode == "update": print("All repositories successfully updated & Java modules built!") print("You should be able to run some examples straight away using jnml: ") - if os.name is not 'nt': + if os.name != 'nt': print(" ./jnml " + "-validate ../NeuroML2/examples/NML2_FullNeuroML.nml") print(" ./jnml " + @@ -131,7 +131,7 @@ def main(): "..\\NeuroML2\\examples\\NML2_FullNeuroML.nml") print(" jnml " + "..\\NeuroML2\\LEMSexamples\\LEMS_NML2_Ex2_Izh.xml") - if mode is "clean": + if mode == "clean": print("All repositories successfully cleaned!") From bab1932a491844963e5294fbd4962548aefbba21 Mon Sep 17 00:00:00 2001 From: "Ankur Sinha (Ankur Sinha Gmail)" Date: Sat, 20 Jun 2020 20:21:33 +0100 Subject: [PATCH 3/4] Improve help text --- getNeuroML.py | 30 +++++++++++++++++++++--------- 1 file changed, 21 insertions(+), 9 deletions(-) diff --git a/getNeuroML.py b/getNeuroML.py index bdb0a01..e5db192 100644 --- a/getNeuroML.py +++ b/getNeuroML.py @@ -4,6 +4,7 @@ import sys import os.path as op import subprocess +from textwrap import dedent def main(): @@ -157,15 +158,26 @@ def execute_command_in_dir(command, directory, exit_on_fail=True): def help_info(): - print("\nUsage:\n\n python getNeuroML.py\n " \ - "Pull (or clone) the latest version of all NeuroML 2 repos & " \ - "compile/install with Maven if applicable\n\n" \ - " python getNeuroML.py clean\n " - "Run 'mvn clean' on all Java repos\n\n" \ - " python getNeuroML.py master\n " \ - "Switch all repos to master branch\n\n" \ - " python getNeuroML.py development\n " \ - "Switch relevant repos to development branch\n\n") + usage = ( + """\ + Usage: python getNeuroML.py [OPTION] + Script to install NeuroML libraries. + Note: requires internet connectivity. + + python getNeuroML.py + Pull (or clone) the latest version of all NeuroML 2 repos & + compile/install with Maven if applicable + + python getNeuroML.py clean + Run 'mvn clean' on all Java repos + + python getNeuroML.py master + Switch all repos to master branch + + python getNeuroML.py development + Switch relevant repos to development branch + """) + print(dedent(usage)) if __name__ == "__main__": From 70961607faaca7e2d47a56f670a6ba9643db0185 Mon Sep 17 00:00:00 2001 From: "Ankur Sinha (Ankur Sinha Gmail)" Date: Sat, 20 Jun 2020 20:24:03 +0100 Subject: [PATCH 4/4] Fix whitespace warnings --- getNeuroML.py | 43 ++++++++++++++++++++++++------------------- 1 file changed, 24 insertions(+), 19 deletions(-) diff --git a/getNeuroML.py b/getNeuroML.py index e5db192..bcadd73 100644 --- a/getNeuroML.py +++ b/getNeuroML.py @@ -106,12 +106,14 @@ def main(): or not op.isdir(local_dir + os.sep + "target") \ or ("jNeuroML" in repo) - if (repo in java_repos or repo in neuroml2_spec_repo) and runMvnInstall: + if (repo in java_repos or repo in neuroml2_spec_repo) \ + and runMvnInstall: command = "mvn install" print("It's a Java repository, so installing using Maven...") info = execute_command_in_dir(command, local_dir) - # The code below needs a non trivial rewrite due to python3 differences. + # The code below needs a non trivial rewrite due to python3 + # differences. if str("BUILD SUCCESS") in str(info): print("Successful installation using : %s!" % command) else: @@ -121,7 +123,7 @@ def main(): if mode == "update": print("All repositories successfully updated & Java modules built!") - print("You should be able to run some examples straight away using jnml: ") + print("You should be able to run examples straight away using jnml: ") if os.name != 'nt': print(" ./jnml " + "-validate ../NeuroML2/examples/NML2_FullNeuroML.nml") @@ -141,9 +143,11 @@ def execute_command_in_dir(command, directory, exit_on_fail=True): if os.name == 'nt': directory = os.path.normpath(directory) - print(">>> Executing: (%s) in dir: %s (%s)" % (command, directory, os.path.abspath(directory))) + print(">>> Executing: (%s) in dir: %s (%s)" % + (command, directory, os.path.abspath(directory))) - p = subprocess.Popen(command, cwd=directory, shell=True, stdout=subprocess.PIPE) + p = subprocess.Popen(command, cwd=directory, shell=True, + stdout=subprocess.PIPE) return_str = p.communicate() if p.returncode != 0: @@ -159,24 +163,25 @@ def execute_command_in_dir(command, directory, exit_on_fail=True): def help_info(): usage = ( - """\ - Usage: python getNeuroML.py [OPTION] - Script to install NeuroML libraries. - Note: requires internet connectivity. + """\ + Usage: python getNeuroML.py [OPTION] + Script to install NeuroML libraries. + Note: requires internet connectivity. - python getNeuroML.py - Pull (or clone) the latest version of all NeuroML 2 repos & - compile/install with Maven if applicable + python getNeuroML.py + Pull (or clone) the latest version of all NeuroML 2 repos & + compile/install with Maven if applicable - python getNeuroML.py clean - Run 'mvn clean' on all Java repos + python getNeuroML.py clean + Run 'mvn clean' on all Java repos - python getNeuroML.py master - Switch all repos to master branch + python getNeuroML.py master + Switch all repos to master branch - python getNeuroML.py development - Switch relevant repos to development branch - """) + python getNeuroML.py development + Switch relevant repos to development branch + """ + ) print(dedent(usage))