Skip to content

Feat: use jnml from pyneuroml #138

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 7 commits into from
Jul 3, 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
19 changes: 6 additions & 13 deletions omv/common/inout.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import yaml
from collections import deque
import os
import sys

# import textwrap
import subprocess as sp
from collections import deque

import yaml

LINEWIDTH = 70
__PROMPT__ = "[omv] "
Expand All @@ -25,10 +25,7 @@ def omvify(x):


def check(b):
if sys.version_info >= (3, 0):
tick = "\u2714" if b else "\u2718"
else:
tick = "\u2714" if b else "\u2718"
tick = "\u2714" if b else "\u2718"
return tick


Expand Down Expand Up @@ -57,11 +54,7 @@ def inform(
else:
p = pars if pars else ""
# print("msg is %s"%msg.__class__)
msgstr = (
msg.encode("utf-8")
if sys.version_info[0] == 2 and isinstance(msg, unicode)
else str(msg)
)
msgstr = str(msg)
infostr = msgstr + str(p)
block = deque([infostr])

Expand Down Expand Up @@ -128,7 +121,7 @@ def check_output(cmds, cwd=".", shell=False, verbosity=0, env=None):


def pip_install(packages, version=None):
pip = "pip3" if sys.version_info.major == 3 else "pip"
pip = "pip"
cmds = [pip, "install"]
if isinstance(packages, str):
if version is None:
Expand Down
1 change: 1 addition & 0 deletions omv/engines/getjnml.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@


def install_jnml(version):
"""Install JNeuroML from GitHub tar."""
if not version:
version = "v0.14.0"

Expand Down
41 changes: 10 additions & 31 deletions omv/engines/jneuroml.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,41 +2,23 @@
import shutil
import subprocess as sp
from pathlib import Path
import platform

from omv.common.inout import inform, trim_path, is_verbose, check_output
from omv.engines.engine import OMVEngine, EngineExecutionError
from omv.common.inout import check_output, inform, is_verbose, trim_path
from omv.engines.engine import EngineExecutionError, OMVEngine


class JNeuroMLEngine(OMVEngine):
name = "jNeuroML"
e_name = "jnml"

@staticmethod
def get_environment():
if "JNML_HOME" in os.environ:
jnmlhome = os.environ["JNML_HOME"]
elif shutil.which("jnml") is not None:
jnmlhome = Path(shutil.which("jnml")).parent
elif shutil.which(JNeuroMLEngine.e_name) is not None:
jnmlhome = Path(shutil.which(JNeuroMLEngine.e_name)).parent
else:
osname = platform.system()
if osname == "Linux":
try:
jnmlhome = os.path.join(
os.environ["XDG_DATA_HOME"], "jnml/jNeuroMLJar"
)
except KeyError:
localsharepath = os.path.join(os.environ["HOME"], ".local/share")
if os.path.isdir(localsharepath):
jnmlhome = os.path.join(
os.environ["HOME"], ".local/share/jnml/jNeuroMLJar"
)
else:
jnmlhome = os.path.join(os.environ["HOME"], "jnml/jNeuroMLJar")

elif osname == "Darwin":
jnmlhome = os.path.join(os.environ["HOME"], "Library/jnml/jNeuroMLJar")
else:
jnmlhome = os.path.join(os.environ["HOME"], "jnml/jNeuroMLJar")
jnmlhome = ""

environment_vars = {"JNML_HOME": jnmlhome}

Expand All @@ -45,9 +27,7 @@ def get_environment():
@staticmethod
def get_executable():
environment_vars = JNeuroMLEngine.get_environment()
jnml = os.path.join(
environment_vars["JNML_HOME"], "jnml" if os.name != "nt" else "jnml.bat"
)
jnml = os.path.join(environment_vars["JNML_HOME"], JNeuroMLEngine.e_name)
return jnml

@staticmethod
Expand All @@ -59,7 +39,6 @@ def is_installed():
"Checking whether %s is installed..." % JNeuroMLEngine.name,
indent=1,
)
FNULL = open(os.devnull, "w")
jnml = JNeuroMLEngine.get_executable()
r = check_output(
[jnml, "-v"], verbosity=2, env=JNeuroMLEngine.get_environment()
Expand All @@ -76,10 +55,10 @@ def is_installed():

@staticmethod
def install(version):
from omv.engines.getjnml import install_jnml
from omv.engines.getpyneuroml import install_pynml

inform("Will fetch and install jNeuroML jar", indent=2)
install_jnml(version)
inform("Will install PyNeuroML for jnml", indent=2)
install_pynml(version)

if not JNeuroMLEngine.is_installed():
inform("Failure to install, exiting", indent=1)
Expand Down
4 changes: 1 addition & 3 deletions omv/omv_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -228,9 +228,7 @@ def _install_engine(eng):
if ee.is_installed():
already_installed = True
else:
from omv.engines.getjnml import install_jnml

install_jnml(engine_version)
ee.install(None)

elif eng.lower() == "neuroConstruct" or eng == "Py_neuroConstruct".lower():
from omv.engines.pyneuroconstruct import PyneuroConstructEngine as ee
Expand Down