def load_mechanisms(path, warn_if_already_loaded=True): """ load_mechanisms(path) Search for and load NMODL mechanisms from the path given. This function will not load a mechanism path twice. The path should specify the directory in which nrnivmodl or mknrndll was run, and in which the directory 'i686' (or 'x86_64' or 'powerpc' depending on your platform) was created""" import platform global nrn_dll_loaded if path in nrn_dll_loaded: if warn_if_already_loaded: print("Mechanisms already loaded from path: %s. Aborting." % path) return True # in case NEURON is assuming a different architecture to Python, # we try multiple possibilities libname = 'libnrnmech.so' libsubdir = '.libs' arch_list = [platform.machine(), 'i686', 'x86_64', 'powerpc', 'umac'] # windows loads nrnmech.dll if h.unix_mac_pc() == 3: libname = 'nrnmech.dll' libsubdir = '' arch_list = [''] for arch in arch_list: lib_path = os.path.join(path, arch, libsubdir, libname) if os.path.exists(lib_path): h.nrn_load_dll(lib_path) nrn_dll_loaded.append(path) return True print("NEURON mechanisms not found in %s." % path) return False
""" Module to help with mocking/bypassing RaspberryPi specific code to enable for debugging on a Mac or Windows host. """ from sys import platform, version_info from sys import platform as os_platform import platform REQUIRED_PYTHON_VERSION = 3.5 IS_LINUX = 'linux' in os_platform DETECTED_CPU = platform.machine() IS_PI = "arm" in DETECTED_CPU def validate_python_version(): """ Checks to make sure that the correct version of Python is being used. Raises: Exception -- If the version of Python is not new enough. """ python_version = float('{}.{}'.format( version_info.major, version_info.minor)) error_text = 'Requires Python {}'.format(REQUIRED_PYTHON_VERSION) if python_version < REQUIRED_PYTHON_VERSION: print(error_text) raise Exception(error_text)
# next try is to derive from nrnversion(6) (only works for autotools build) import platform import os p = h.nrnversion(6) if "--prefix=" in p: p = p[p.find('--prefix=') + 9:] p = p[:p.find("'")] else: p = "/usr/local/nrn" if sys.version_info >= (3, 0): import sysconfig hoc_path = p + "/lib/python/neuron/hoc%s" % sysconfig.get_config_var('SO') else: hoc_path = p + "/lib/python/neuron/hoc.so" if not os.path.isfile(hoc_path): hoc_path = p + "/%s/lib/libnrnpython%d.so" % (platform.machine(), sys.version_info[0]) if not os.path.isfile(hoc_path): hoc_path = p + "/%s/lib/libnrnpython.so" % platform.machine() setattr(hoc, "__file__", hoc_path) else: _original_hoc_file = hoc.__file__ # As a workaround to importing doc at neuron import time # (which leads to chicken and egg issues on some platforms) # define a dummy help function which imports doc, # calls the real help function, and reassigns neuron.help to doc.help # (thus replacing the dummy) def help(request=None): global help from neuron import doc doc.help(request) help = doc.help
print( """Python version: %s dist: %s linux_distribution: %s system: %s machine: %s platform: %s uname: %s version: %s mac_ver: %s """ % ( sys.version.split('\n'), str(platform.dist()), linux_distribution(), platform.system(), platform.machine(), platform.platform(), platform.uname(), platform.version(), platform.mac_ver(), )) def call_shell(): session = subprocess.Popen(['syspack.sh'], stdout=PIPE, stderr=PIPE) stdout, stderr = session.communicate() if stderr: raise Exception("Error " + str(stderr))