code: def _search_path(path):
      mapping = dict()
  
      for file in os.listdir(path):
          # Install from PYPI.
  
          # broken pip packages might start with '~' - ignore it
          if str(file).startswith("~"):
              continue
  
          if fnmatch.fnmatch(file, "*-info"):
              pkg_name, version = file.split("-")[:2]
              if version.endswith("dist"):
                  version = version.rsplit(".", 1)[0]
              # Issue for ubuntu: sudo pip install xxx
              elif version.endswith("egg"):
                  version = version.rsplit(".", 1)[0]
  
              mapping_pkg_name = pkg_name
              # pep610 support. add support for new pip>=20.1 git reference feature
              git_direct_json = os.path.join(
                  path, file, "direct_url.json"
              )
              if os.path.isfile(git_direct_json):
                  # noinspection PyBroadException
                  try:
                      with open(git_direct_json, "r") as f:
                          direct_json = json.load(f)
  
                      if "vcs_info" in direct_json:
                          vcs_info = direct_json["vcs_info"]
                          git_url = "{vcs}+{url}@{commit}#egg={package}".format(
                              vcs=vcs_info["vcs"],
                              url=direct_json["url"],
                              commit=vcs_info["commit_id"],
                              package=pkg_name,
                          )
                          # If subdirectory is present, append this to the git_url
                          if "subdirectory" in direct_json:
                              git_url = "{git_url}&subdirectory={subdirectory}".format(
                                  git_url=git_url,
                                  subdirectory=direct_json[
                                      "subdirectory"
                                  ],
                              )
                          # Bugfix: package name should be the URL link, because we need it unique
                          # mapping[pkg_name] = ('-e', git_url)
                          pkg_name, version = (
                              "-e {}".format(git_url),
                              "",
                          )
                      elif "url" in direct_json:
                          url_link = (
                              direct_json.get("url", "").strip().lower()
                          )
                          if url_link and not url_link.startswith(
                              "file://"
                          ):
                              git_url = direct_json["url"]
                              # If subdirectory is present, append this to the git_url
                              if "subdirectory" in direct_json:
                                  git_url = "{git_url}#subdirectory={subdirectory}".format(
                                      git_url=direct_json["url"],
                                      subdirectory=direct_json[
                                          "subdirectory"
                                      ],
                                  )
  
                              pkg_name, version = git_url, ""
  
                  except Exception:
                      pass
  
              # default
              mapping[mapping_pkg_name] = (pkg_name, version)
  
              # analyze 'top_level.txt' if it exists
              top_level = os.path.join(path, file, "top_level.txt")
              if not os.path.isfile(top_level):
                  continue
              with open(top_level, "r") as f:
                  for line in f:
                      top_package = line.strip()
                      # NOTICE: this is a namespace package
                      if top_package and mapping_pkg_name.startswith(
                          "{}_".format(top_package)
                      ):
                          top = mapping.get(top_package, dict())
                          if not isinstance(top, dict):
                              top = {top_package: top}
                          top[mapping_pkg_name] = (pkg_name, version)
                          mapping[top_package] = top
                      else:
                          mapping[top_package] = (pkg_name, version)
  
          # Install from local and available in GitHub.
          elif fnmatch.fnmatch(file, "*-link"):
              link = os.path.join(path, file)
              if not os.path.isfile(link):
                  continue
              # Link path.
              with open(link, "r") as f:
                  for line in f:
                      line = line.strip()
                      if line != ".":
                          dev_dir = line
              if not dev_dir:
                  continue
              if not os.path.exists(dev_dir):
                  continue
              # Egg info path.
              info_dir = [
                  _file
                  for _file in os.listdir(dev_dir)
                  if _file.endswith("egg-info")
              ]
              if not info_dir:
                  continue
              info_dir = info_dir[0]
              top_level = os.path.join(
                  dev_dir, info_dir, "top_level.txt"
              )
              # Check whether it can be imported.
              if not os.path.isfile(top_level):
                  continue
  
              # Check .git dir.
              git_path = os.path.join(dev_dir, ".git")
              if os.path.isdir(git_path):
                  config = parse_git_config(git_path)
                  url = config.get('remote "origin"', {}).get("url")
                  if not url:
                      continue
                  branch = 'branch "master"'
                  if branch not in config:
                      for section in config:
                          if "branch" in section:
                              branch = section
                              break
                  if not branch:
                      continue
                  branch = branch.split()[1][1:-1]
  
                  pkg_name = info_dir.split(".egg")[0]
                  git_url = "git+{0}@{1}#egg={2}".format(
                      url, branch, pkg_name
                  )
                  with open(top_level, "r") as f:
                      for line in f:
                          # Bugfix: package name should be the URL link, because we need it unique
                          # mapping[line.strip()] = ('-e', git_url)
                          mapping[line.strip()] = (
                              "-e {}".format(git_url),
                              "",
                          )
  
      return mapping
  
imports: from __future__ import print_function, division, absolute_import
  import json
  import os
  import sys
  import six
  import fnmatch
  import importlib
  import ast
  import doctest
  import collections
  import functools
  from pathlib2 import Path
  from .utils import parse_git_config
  from .modules import ImportedModules
label_desc: Use image node_id 7 for calling a global function with example usage: _search_path(path) and returns: mapping