Skip to content

Feat: provide jnml command that will use the bundled jar #450

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

Open
wants to merge 7 commits into
base: development
Choose a base branch
from
Open
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
11 changes: 7 additions & 4 deletions pyneuroml/runners.py
Original file line number Diff line number Diff line change
Expand Up @@ -705,6 +705,7 @@ def run_jneuroml(
report_jnml_output: bool = True,
exit_on_fail: bool = False,
return_string: bool = False,
output_prefix: str = " jNeuroML >> ",
) -> typing.Union[typing.Tuple[bool, str], bool]:
"""Run jnml with provided arguments.

Expand All @@ -726,6 +727,8 @@ def run_jneuroml(
:type exit_on_fail: bool
:param return_string: toggle whether the output string should be returned
:type return_string: bool
:param output_prefix: string to prefix the returned jNeuroML output with
:type output_prefix: str

:returns: either a bool, or a Tuple (bool, str) depending on the value of
return_string: True of jnml ran successfully, False if not; along with the
Expand Down Expand Up @@ -756,7 +759,7 @@ def run_jneuroml(
try:
command = f'java -Xmx{max_memory} {pre_jar} -jar "{jar_path}" {pre_args} {target_file} {post_args}'
retcode, output = execute_command_in_dir(
command, exec_in_dir, verbose=verbose, prefix=" jNeuroML >> "
command, exec_in_dir, verbose=verbose, prefix=output_prefix
)

if retcode != 0:
Expand Down Expand Up @@ -919,7 +922,7 @@ def execute_command_in_dir_with_realtime_output(
raise e

if not p.returncode == 0:
logger.critical(
logger.error(
"*** Problem running command (return code: %s): [%s]"
% (p.returncode, command)
)
Expand Down Expand Up @@ -990,14 +993,14 @@ def execute_command_in_dir(
return return_string.decode("utf-8")

except subprocess.CalledProcessError as e:
logger.critical("*** Problem running last command: %s" % e)
logger.error("*** 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)
logger.error("*** Unknown problem running command: %s" % e)
return (-1, str(e))


Expand Down
48 changes: 48 additions & 0 deletions pyneuroml/utils/jnmlwrapper.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
#!/usr/bin/env python3
"""
Simple wrapper around jNeuroML to allow users to use jnml using the version
bundled in PyNeuroML

File: pyneuroml/utils/jnmlwrapper.py

Copyright 2025 NeuroML contributors
Author: Ankur Sinha <sanjay DOT ankur AT gmail DOT com>
"""

import logging
import os
import sys

from ..runners import run_jneuroml


def __jnmlwrapper():
"""Wrapper around jNeuroML jar shipped with PyNeuroML.

The following environment variables can be set:

- JNML_MAX_MEMORY_LOCAL: set the maximum memory available to the Java
Virtual Machine (default: 400M)

"""
max_memory = os.getenv("JNML_MAX_MEMORY_LOCAL", "400M")
logging.getLogger("pyneuroml.runners").setLevel(logging.CRITICAL)

retstat, output = run_jneuroml(
pre_args=" ".join(sys.argv[1:]),
target_file="",
post_args="",
max_memory=max_memory,
report_jnml_output=False,
output_prefix="",
return_string=True,
exit_on_fail=False,
)

# if command ran successfully, print the output
# if it didn't, `run_jneuroml` will throw a critical error
if retstat is True:
print(output)
sys.exit(0)
else:
sys.exit(1)
1 change: 1 addition & 0 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ console_scripts =
pynml-sonata = neuromllite.SonataReader:main
pynml-xpp = pyneuroml.xppaut:main
pynml-swc2nml = pyneuroml.swc.ExportNML:main
jnml = pyneuroml.utils.jnmlwrapper:__jnmlwrapper

[options.package_data]
* =
Expand Down
2 changes: 1 addition & 1 deletion test-ghactions.sh
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ echo "## Testing all CLI tools"
full_path=$(command -v pynml)
bin_location=$(dirname $full_path)

for f in ${bin_location}/pynml*
for f in ${bin_location}/pynml* ${bin_location}/jnml
do
current_exec=$(basename $f)
echo "-> Testing $current_exec runs"
Expand Down
Loading