Parse import path. Determine if the path is native or starts with known prefix.

		:param importpath:	import path to parse
		:type  importpath:	str
		:return: bool
961045
def parse(self, importpath):
		
		# reset default values
		self.native = False
		self._prefix = ""
		self._package = ""

		url = re.sub(r'http://', '', importpath)
		url = re.sub(r'https://', '', url)

		# is import path native package?
		if url.split('/')[0] in self.native_packages["packages"]:
			self.native = True
			return self

		for regex in self.known_ipprefixes:
			match = re.search(regex, url)
			if match:
				self._prefix = match.group(1)
				if match.group(3):
					self._package = match.group(3)
				return self

		raise ValueError("Import path prefix for '%s' not recognized" % importpath)
1325406
def tryImportClass(self):
        
        logger.info("Importing: {}".format(self.fullClassName))
        self._triedImport = True
        self._exception = None
        self._cls = None
        try:
            for pyPath in self.pythonPath.split(':'):
                if pyPath and pyPath not in sys.path:
                    logger.debug("Appending {!r} to the PythonPath.".format(pyPath))
                    sys.path.append(pyPath)
            self._cls = import_symbol(self.fullClassName) # TODO: check class?
        except Exception as ex:
            self._exception = ex
            logger.warn("Unable to import {!r}: {}".format(self.fullClassName, ex))
            if DEBUGGING:
                raise
1060115
function isReachViolation(importPath) {
      const steps = normalizeSep(importPath)
        .split('/')
        .reduce((acc, step) => {
          if (!step || step === '.') {
            return acc
          } else if (step === '..') {
            return acc.slice(0, -1)
          } else {
            return acc.concat(step)
          }
        }, [])

      const nonScopeSteps = steps.filter(step => step.indexOf('@') !== 0)
      if (nonScopeSteps.length <= 1) return false

      // before trying to resolve, see if the raw import (with relative
      // segments resolved) matches an allowed pattern
      const justSteps = steps.join('/')
      if (reachingAllowed(justSteps) || reachingAllowed(`/${justSteps}`)) return false

      // if the import statement doesn't match directly, try to match the
      // resolved path if the import is resolvable
      const resolved = resolve(importPath, context)
      if (!resolved || reachingAllowed(normalizeSep(resolved))) return false

      // this import was not allowed by the allowed paths, and reaches
      // so it is a violation
      return true
    }
403177
def from_path(cls, path, origin=MISSING, **kwargs):
        
        origin, relpath = cls._key_from_path(path, origin)

        # Open in binary mode so we can reliably detect the encoding
        with path.open('rb') as f:
            return cls.from_file(f, origin, relpath, **kwargs)
327079
def file_containing_import(import_path, import_root):
    '''
    '''
    if not _import_paths:
        load_stdlib()

    if os.path.isfile(import_root):
        import_root = os.path.dirname(import_root)

    search_paths = [import_root] + _import_paths
    module_parts = import_path.split('.')
    for i in range(len(module_parts), 0, -1):
        module_path = os.path.join(*module_parts[:i])
        for sp in search_paths:
            p = os.path.join(sp, module_path)
            if os.path.isdir(p):
                return os.path.join(p, '__init__.py')
            elif os.path.isfile(p + '.py'):
                return p + '.py'
    return None
359294
function resolveImportPaths(filePath, importPaths){
  var dir = path.dirname(filePath);
  return importPaths.map(function(relativePath){
    if(!path.extname(relativePath)){
      relativePath += '.less';
    }
    return path.resolve(dir, relativePath);
  });
}
205714
def _parse_from_import_source(self):
        
        assert self.current.value == 'from', self.current.value
        self.stream.move()
        is_future_import = self.current.value == '__future__'
        self.stream.move()
        while (self.current is not None and
               self.current.kind in (tk.DOT, tk.NAME, tk.OP) and
               self.current.value != 'import'):
            self.stream.move()
        if self.current is None or self.current.value != 'import':
            return False
        self.check_current(value='import')
        assert self.current.value == 'import', self.current.value
        self.stream.move()
        return is_future_import
230202
def load_path_with_default(self, path, default_constructor):
        '''
        
        '''
        try:
            imported_obj = self.load_path(path)
        except (ImportError, ConfigurationError):
            imported_obj = default_constructor(path)
        else:
            # Ugly but seemingly expedient way to check a module was an
            # namespace type module
            if (isinstance(imported_obj, ModuleType) and
                    imported_obj.__spec__.origin == 'namespace'):
                imported_obj = default_constructor(path)
        return imported_obj
530004
function isImported(source, classifiedName, importPath) {
    const allNodes = getSourceNodes(source);
    const matchingNodes = allNodes
        .filter(node => node.kind === ts.SyntaxKind.ImportDeclaration)
        .filter((imp) => imp.moduleSpecifier.kind === ts.SyntaxKind.StringLiteral)
        .filter((imp) => {
        return imp.moduleSpecifier.text === importPath;
    })
        .filter((imp) => {
        if (!imp.importClause) {
            return false;
        }
        const nodes = findNodes(imp.importClause, ts.SyntaxKind.ImportSpecifier).filter(n => n.getText() === classifiedName);
        return nodes.length > 0;
    });
    return matchingNodes.length > 0;
}
1220975
def get_imported_repo(self, import_path):
    
    try:
      session = requests.session()
      # TODO: Support https with (optional) fallback to http, as Go does.
      # See https://github.com/pantsbuild/pants/issues/3503.
      session.mount("http://",
                    requests.adapters.HTTPAdapter(max_retries=self.get_options().retries))
      page_data = session.get('http://{import_path}?go-get=1'.format(import_path=import_path))
    except requests.ConnectionError:
      return None

    if not page_data:
      return None

    # Return the first match, rather than doing some kind of longest prefix search.
    # Hopefully no one returns multiple valid go-import meta tags.
    for (root, vcs, url) in self.find_meta_tags(page_data.text):
      if root and vcs and url:
        # Check to make sure returned root is an exact match to the provided import path. If it is
        # not then run a recursive check on the returned and return the values provided by that call.
        if root == import_path:
          return ImportedRepo(root, vcs, url)
        elif import_path.startswith(root):
          return self.get_imported_repo(root)

    return None
1251741
def check_path(path):
    
    if path is None or path == b'' or path.startswith(b'/'):
        raise ValueError("illegal path '%s'" % path)

    if (
        (sys.version_info[0] >= 3 and not isinstance(path, bytes)) and
        (sys.version_info[0] == 2 and not isinstance(path, str))
    ):
        raise TypeError("illegale type for path '%r'" % path)

    return path
1339217
def find_module(self, fullname, path=None):
        
        # path points to the top-level package path if any
        # and we can only import sub-modules/-packages
        if path is None:
            return
        if fullname.startswith(self.module_prefix):
            return self
        else:
            return None
212441
def find_path_package(thepath):
    
    pname = find_path_package_name(thepath)
    if not pname:
        return None
    fromlist = b'' if six.PY2 else ''
    return __import__(pname, globals(), locals(), [fromlist])
226108
def set_root_path(self, root_path=None, settings_module=None):
        
        if root_path:
            self.root_path = root_path
            return

        if settings_module:
            self.root_path = os.path.dirname(os.path.abspath(settings_module.__file__))
            return

        # try to guess which module import app.py
        import inspect

        caller = inspect.stack()[1]
        caller_module = inspect.getmodule(caller[0])
        assert hasattr(caller_module, '__file__'), 'Caller module %s should have __file__ attr' % caller_module
        self.root_path = os.path.dirname(os.path.abspath(caller_module.__file__))
727910
def is_local(path):
    # type: (str) -> bool
    
    if not running_under_virtualenv():
        return True
    return normalize_path(path).startswith(normalize_path(sys.prefix))
87870
def import_(path):
    
    exists(path)
    log(_("importing {}...").format(path))
    name = Path(path).stem
    try:
        return internal.import_file(name, path)
    except Exception as e:
        raise Failure(str(e))
183540
def _import_module(self, module_path):
        
        LOGGER.debug('Importing %s', module_path)
        try:
            return __import__(module_path)
        except ImportError as error:
            LOGGER.critical('Could not import %s: %s', module_path, error)
            return None