diff --git a/omv/common/inout.py b/omv/common/inout.py index e20353f..715eab2 100644 --- a/omv/common/inout.py +++ b/omv/common/inout.py @@ -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] " @@ -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 @@ -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]) @@ -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: diff --git a/omv/engines/getjnml.py b/omv/engines/getjnml.py index e4b5697..21583c3 100644 --- a/omv/engines/getjnml.py +++ b/omv/engines/getjnml.py @@ -8,6 +8,7 @@ def install_jnml(version): + """Install JNeuroML from GitHub tar.""" if not version: version = "v0.14.0" diff --git a/omv/engines/jneuroml.py b/omv/engines/jneuroml.py index f5158c5..5f4883e 100644 --- a/omv/engines/jneuroml.py +++ b/omv/engines/jneuroml.py @@ -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} @@ -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 @@ -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() @@ -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) diff --git a/omv/omv_util.py b/omv/omv_util.py index 12ed3cd..8faefca 100644 --- a/omv/omv_util.py +++ b/omv/omv_util.py @@ -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