Skip to content

Add example testing execute_command_in_dir etc. #442

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Feb 12, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 = p.gleeson@gmail.com
url = https://github.com/NeuroML/pyNeuroML
Expand Down
Loading