Skip to content

Commit

Permalink
Merge pull request #442 from NeuroML/experimental
Browse files Browse the repository at this point in the history
Add example testing execute_command_in_dir etc.
  • Loading branch information
pgleeson authored Feb 12, 2025
2 parents 0f2793c + 3c10a56 commit fe715e4
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 6 deletions.
17 changes: 17 additions & 0 deletions examples/test_execute_command.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
from pyneuroml import pynml

run_dir = '.'

commands = ['pwd', 'ls -alt testss']

for command in commands:

print("\n====================\n")

returncode, output = pynml.execute_command_in_dir(command, run_dir, prefix="Output [%s] > "%command, verbose=True)

print(' ---- Return code from execute_command_in_dir: %s; output: \n%s\n--------------------------'%(returncode, output))

success = pynml.execute_command_in_dir_with_realtime_output(command, run_dir, prefix="Output [%s]: "%command, verbose=False)

print(' ---- Success of execute_command_in_dir_with_realtime_output: %s'%success)
2 changes: 1 addition & 1 deletion pyneuroml/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
__version__ = importlib_metadata.version("pyNeuroML")


JNEUROML_VERSION = "0.13.3"
JNEUROML_VERSION = "0.14.0"

logger = logging.getLogger(__name__)
logger.propagate = False
Expand Down
Binary file not shown.
11 changes: 7 additions & 4 deletions pyneuroml/runners.py
Original file line number Diff line number Diff line change
Expand Up @@ -902,7 +902,7 @@ def execute_command_in_dir_with_realtime_output(
)
with p.stdout:
for line in iter(p.stdout.readline, ""):
print("# %s" % line.strip())
print(" %s %s" % (prefix,line.strip()))
p.wait() # wait for the subprocess to exit

print("####################################################################")
Expand All @@ -920,7 +920,7 @@ def execute_command_in_dir_with_realtime_output(

if not p.returncode == 0:
logger.critical(
"*** Problem running command (return code: %s): \n %s"
"*** Problem running command (return code: %s): [%s]"
% (p.returncode, command)
)

Expand Down Expand Up @@ -990,10 +990,13 @@ def execute_command_in_dir(
return return_string.decode("utf-8")

except subprocess.CalledProcessError as e:
logger.critical("*** Problem running command: \n %s" % e)
logger.critical(
logger.critical("*** Problem running last command: %s" % e)

print("####################################################################")
print(
"%s%s" % (prefix, e.output.decode().replace("\n", "\n" + prefix))
)
print("####################################################################")
return (e.returncode, e.output.decode())
except Exception as e:
logger.critical("*** Unknown problem running command: %s" % e)
Expand Down
2 changes: 1 addition & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[metadata]
name = pyNeuroML
version = 1.3.14
version = 1.3.15
author = Padraig Gleeson
author_email = [email protected]
url = https://github.com/NeuroML/pyNeuroML
Expand Down

0 comments on commit fe715e4

Please sign in to comment.