# Path: django_node/settings.py
# PATH_TO_NODE = setting_overrides.get(
#     'PATH_TO_NODE',
#     'node'
# )
# 
# PATH_TO_NPM = setting_overrides.get(
#     'PATH_TO_NPM',
#     'npm'
# )
# 
# NODE_VERSION_COMMAND = setting_overrides.get(
#     'NODE_VERSION_COMMAND',
#     '--version',
# )
# 
# NODE_VERSION_FILTER = setting_overrides.get(
#     'NODE_VERSION_FILTER',
#     lambda version: tuple(map(int, (version[1:] if version[0] == 'v' else version).split('.'))),
# )
# 
# NPM_VERSION_COMMAND = setting_overrides.get(
#     'NPM_VERSION_COMMAND',
#     '--version',
# )
# 
# NPM_VERSION_FILTER = setting_overrides.get(
#     'NPM_VERSION_FILTER',
#     lambda version: tuple(map(int, version.split('.'))),
# )
# 
# Path: django_node/exceptions.py
# class DynamicImportError(Exception):
#     pass
# 
# class ErrorInterrogatingEnvironment(Exception):
#     pass
# 
# class MalformedVersionInput(Exception):
#     pass
# 
# class MissingDependency(Exception):
#     pass
# 
# class OutdatedDependency(Exception):
#     pass
# 
# class ModuleDoesNotContainAnyServices(Exception):
#     pass


import sys
import subprocess
import tempfile
import importlib
import re
import inspect
from django.utils import six
from .settings import (
    PATH_TO_NODE, PATH_TO_NPM, NODE_VERSION_COMMAND, NODE_VERSION_FILTER, NPM_VERSION_COMMAND, NPM_VERSION_FILTER,
)
from .exceptions import (
    DynamicImportError, ErrorInterrogatingEnvironment, MalformedVersionInput, MissingDependency, OutdatedDependency,
    ModuleDoesNotContainAnyServices
)
    from . import node, npm  # Avoid a circular import
    from .base_service import BaseService  # Avoid a circular import
    version = None
    if version_raw:
        version = version_filter(version_raw)
    return installed, version, version_raw,

# Interrogate the system
node_installed, node_version, node_version_raw = _interrogate(
    (PATH_TO_NODE, NODE_VERSION_COMMAND,),
    NODE_VERSION_FILTER,
)
npm_installed, npm_version, npm_version_raw = _interrogate(
    (PATH_TO_NPM, NPM_VERSION_COMMAND,),
    NPM_VERSION_FILTER,
)

NPM_NAME = 'NPM'
NODE_NAME = 'Node.js'


def _validate_version_iterable(version):
    if not isinstance(version, tuple):
        raise MalformedVersionInput(
            'Versions must be tuples. Received {0}'.format(version)
        )
    if len(version) < 3:
        raise MalformedVersionInput(
            'Versions must have three numbers defined. Received {0}'.format(version)
        )
    for number in version:
        if not isinstance(number, six.integer_types):

# Path: django_node/settings.py
# PATH_TO_NODE = setting_overrides.get(
#     'PATH_TO_NODE',
#     'node'
# )
# 
# PATH_TO_NPM = setting_overrides.get(
#     'PATH_TO_NPM',
#     'npm'
# )
# 
# NODE_VERSION_COMMAND = setting_overrides.get(
#     'NODE_VERSION_COMMAND',
#     '--version',
# )
# 
# NODE_VERSION_FILTER = setting_overrides.get(
#     'NODE_VERSION_FILTER',
#     lambda version: tuple(map(int, (version[1:] if version[0] == 'v' else version).split('.'))),
# )
# 
# NPM_VERSION_COMMAND = setting_overrides.get(
#     'NPM_VERSION_COMMAND',
#     '--version',
# )
# 
# NPM_VERSION_FILTER = setting_overrides.get(
#     'NPM_VERSION_FILTER',
#     lambda version: tuple(map(int, version.split('.'))),
# )
# 
# Path: django_node/exceptions.py
# class DynamicImportError(Exception):
#     pass
# 
# class ErrorInterrogatingEnvironment(Exception):
#     pass
# 
# class MalformedVersionInput(Exception):
#     pass
# 
# class MissingDependency(Exception):
#     pass
# 
# class OutdatedDependency(Exception):
#     pass
# 
# class ModuleDoesNotContainAnyServices(Exception):
#     pass


# Path: django_node/utils.py
import sys
import subprocess
import tempfile
import importlib
import re
import inspect
from django.utils import six
from .settings import (
    PATH_TO_NODE, PATH_TO_NPM, NODE_VERSION_COMMAND, NODE_VERSION_FILTER, NPM_VERSION_COMMAND, NPM_VERSION_FILTER,
)
from .exceptions import (
    DynamicImportError, ErrorInterrogatingEnvironment, MalformedVersionInput, MissingDependency, OutdatedDependency,
    ModuleDoesNotContainAnyServices
)
    from . import node, npm  # Avoid a circular import
    from .base_service import BaseService  # Avoid a circular import

    version = None
    if version_raw:
        version = version_filter(version_raw)
    return installed, version, version_raw,

# Interrogate the system
node_installed, node_version, node_version_raw = _interrogate(
    (PATH_TO_NODE, NODE_VERSION_COMMAND,),
    NODE_VERSION_FILTER,
)
npm_installed, npm_version, npm_version_raw = _interrogate(
    (PATH_TO_NPM, NPM_VERSION_COMMAND,),
    NPM_VERSION_FILTER,
)

NPM_NAME = 'NPM'
NODE_NAME = 'Node.js'


def _validate_version_iterable(version):
    if not isinstance(version, tuple):
        raise MalformedVersionInput(
            'Versions must be tuples. Received {0}'.format(version)
        )
    if len(version) < 3:
        raise MalformedVersionInput(
            'Versions must have three numbers defined. Received {0}'.format(version)
        )
    for number in version:
        if not isinstance(number, six.integer_types):

            raise MalformedVersionInput(