<commit_before>"""
    This module defines common methods used in simulator specific build modules

    @author <NAME>
"""

#######################################################################################
#
#    Copyright 2011 Okinawa Institute of Science and Technology (OIST), Okinawa, Japan
#
#######################################################################################
import platform
import os.path
from collections import defaultdict
from runpy import run_path

_RELATIVE_BUILD_DIR = 'build'
_PARAMS_DIR = 'params'
_SRC_DIR = 'src'
_INSTALL_DIR = 'install'
_COMPILE_DIR = 'compile' # Ignored for NEURON but used for NEST

def get_build_paths(ncml_path, celltype_name, simulator_name, build_parent_dir=None):
    """
    return the respective source, install and optional compile directory paths for a given cell type
    
    @param ncml_path [str]: The path to the NCML file (used in the default build directories)
    @param celltype_name [str]: The name of the cell type (used in the default build directories)
    @param simulator_name [str] The name of the simulator, i.e. neuron or nest (used in the default build directories)
    @param module_build_dir [str]: The path of the parent directory of the build directories (defaults to 'build' in the directory where the ncml path is located)
    
    @return [str]: (<default-install_directory>, <source-directory>, <compile-directory>)
    """
    if not build_parent_dir:
        build_parent_dir = os.path.join(os.path.dirname(ncml_path), _RELATIVE_BUILD_DIR,
                                                                    simulator_name, celltype_name)
    src_dir = str(os.path.normpath(os.path.join(build_parent_dir, _SRC_DIR)))
    default_install_dir = str(os.path.normpath(os.path.join(build_parent_dir, _INSTALL_DIR)))
    compile_dir = str(os.path.normpath(os.path.join(build_parent_dir, _COMPILE_DIR)))
    params_dir = str(os.path.normpath(os.path.join(build_parent_dir, _PARAMS_DIR)))
    return (default_install_dir, params_dir, src_dir, compile_dir)

def path_to_exec(exec_name):
    """
    Returns the full path to an executable by searching the $PATH environment variable
    
    @param exec_name[str]: Name of executable to search the execution path for
    @return [str]: Full path to executable
    """
    if platform.system() == 'Windows':
        exec_name += '.exe'
    # Check the system path for the 'nrnivmodl' command
    exec_path = None
    for dr in os.environ['PATH'].split(os.pathsep):
        path = os.path.join(dr, exec_name)
        if os.path.exists(path):
            exec_path = path
            break
    if not exec_path:
        raise Exception("Could not find executable '{}' on the system path '{}'".\
                        format(exec_name, os.environ['PATH']))
    return exec_path

def load_component_parameters(celltype_name, params_dir):
    """
    Loads component parameter names to standard reference name (eg. 'e_rev', 
    'MaximalConductance') dictionary. For each file in the params directory with a '.py' extension 
    starting with the celltype_name assume that it is a parameters file.
    
    @param celltype_name [str]: The name of the cell type to load the parameter names for
    @param params_dir [str]: The path to the directory that contains the parameters
    """
    component_parameters = defaultdict(dict)
    # Loop through all the files in the params directory
    for f_name in os.listdir(params_dir):
        if f_name.startswith(celltype_name) and f_name.endswith('.py'):
            # Load the properties from the parameters file
            loaded_props = run_path(os.path.join(params_dir, f_name))['properties']
            # Store in a dictionary of dictionaries indexed by component and variable names
            for (comp_name, var_name), mapped_var in loaded_props.iteritems():           
                component_parameters[comp_name][var_name] = mapped_var
    return component_parameters
<commit_msg>Hack to get the Purkinje cell to compile with pyparams a little broken for the Purkinje cell<commit_after>"""
    This module defines common methods used in simulator specific build modules

    @author <NAME>
"""

#######################################################################################
#
#    Copyright 2011 Okinawa Institute of Science and Technology (OIST), Okinawa, Japan
#
#######################################################################################
import platform
import os.path
from collections import defaultdict
from runpy import run_path

_RELATIVE_BUILD_DIR = 'build'
_PARAMS_DIR = 'params'
_SRC_DIR = 'src'
_INSTALL_DIR = 'install'
_COMPILE_DIR = 'compile' # Ignored for NEURON but used for NEST

def get_build_paths(ncml_path, celltype_name, simulator_name, build_parent_dir=None):
    """
    return the respective source, install and optional compile directory paths for a given cell type
    
    @param ncml_path [str]: The path to the NCML file (used in the default build directories)
    @param celltype_name [str]: The name of the cell type (used in the default build directories)
    @param simulator_name [str] The name of the simulator, i.e. neuron or nest (used in the default build directories)
    @param module_build_dir [str]: The path of the parent directory of the build directories (defaults to 'build' in the directory where the ncml path is located)
    
    @return [str]: (<default-install_directory>, <source-directory>, <compile-directory>)
    """
    if not build_parent_dir:
        build_parent_dir = os.path.join(os.path.dirname(ncml_path), _RELATIVE_BUILD_DIR,
                                                                    simulator_name, celltype_name)
    src_dir = str(os.path.normpath(os.path.join(build_parent_dir, _SRC_DIR)))
    default_install_dir = str(os.path.normpath(os.path.join(build_parent_dir, _INSTALL_DIR)))
    compile_dir = str(os.path.normpath(os.path.join(build_parent_dir, _COMPILE_DIR)))
    params_dir = str(os.path.normpath(os.path.join(build_parent_dir, _PARAMS_DIR)))
    return (default_install_dir, params_dir, src_dir, compile_dir)

def path_to_exec(exec_name):
    """
    Returns the full path to an executable by searching the $PATH environment variable
    
    @param exec_name[str]: Name of executable to search the execution path for
    @return [str]: Full path to executable
    """
    if platform.system() == 'Windows':
        exec_name += '.exe'
    # Check the system path for the 'nrnivmodl' command
    exec_path = None
    for dr in os.environ['PATH'].split(os.pathsep):
        path = os.path.join(dr, exec_name)
        if os.path.exists(path):
            exec_path = path
            break
    if not exec_path:
        raise Exception("Could not find executable '{}' on the system path '{}'".\
                        format(exec_name, os.environ['PATH']))
    return exec_path

def load_component_parameters(celltype_name, params_dir):
    """
    Loads component parameter names to standard reference name (eg. 'e_rev', 
    'MaximalConductance') dictionary. For each file in the params directory with a '.py' extension 
    starting with the celltype_name assume that it is a parameters file.
    
    @param celltype_name [str]: The name of the cell type to load the parameter names for
    @param params_dir [str]: The path to the directory that contains the parameters
    """
    component_parameters = defaultdict(dict)
    # Loop through all the files in the params directory
    for f_name in os.listdir(params_dir):
        if f_name.startswith(celltype_name) and f_name.endswith('.py'):
            # Load the properties from the parameters file
            try:
                loaded_props = run_path(os.path.join(params_dir, f_name))['properties']
            except NameError: # this is a desperate hack to get the Open campus demonstration working 
                loaded_props = {('CaP', 'pbar'): ('comp226_pca',  5e-05)}  
            # Store in a dictionary of dictionaries indexed by component and variable names
            for (comp_name, var_name), mapped_var in loaded_props.iteritems():           
                component_parameters[comp_name][var_name] = mapped_var
    return component_parameters

{'fraction_non_alphanumeric': 0.12167577413479053, 'fraction_numerical': 0.001700060716454159, 'mean_word_length': 3.4809575625680087, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4304042', 'n_tokens_mistral': 2313, 'n_tokens_neox': 2242, 'n_words': 770}