parameters: (orig_path, package_name, module)
docstring: Rebuild module.__path__ ensuring that all entries are ordered
      corresponding to their sys.path order
docstring_summary: Rebuild module.__path__ ensuring that all entries are ordered
      corresponding to their sys.path order
docstring_tokens: Rebuild module . __path__ ensuring that all entries are ordered corresponding to their sys . path order
function: def _rebuild_mod_path(orig_path, package_name, module):
      """
      Rebuild module.__path__ ensuring that all entries are ordered
      corresponding to their sys.path order
      """
      sys_path = [_normalize_cached(p) for p in sys.path]
  
      def safe_sys_path_index(entry):
          """
          Workaround for #520 and #513.
          """
          try:
              return sys_path.index(entry)
          except ValueError:
              return float('inf')
  
      def position_in_sys_path(path):
          """
          Return the ordinal of the path based on its position in sys.path
          """
          path_parts = path.split(os.sep)
          module_parts = package_name.count('.') + 1
          parts = path_parts[:-module_parts]
          return safe_sys_path_index(_normalize_cached(os.sep.join(parts)))
  
      if not isinstance(orig_path, list):
          # Is this behavior useful when module.__path__ is not a list?
          return
  
      orig_path.sort(key=position_in_sys_path)
      module.__path__[:] = [_normalize_cached(p) for p in orig_path]
function_tokens: def _rebuild_mod_path ( orig_path , package_name , module ) : sys_path = [ _normalize_cached ( p ) for p in sys . path ] def safe_sys_path_index ( entry ) : """
          Workaround for #520 and #513.
          """ try : return sys_path . index ( entry ) except ValueError : return float ( 'inf' ) def position_in_sys_path ( path ) : """
          Return the ordinal of the path based on its position in sys.path
          """ path_parts = path . split ( os . sep ) module_parts = package_name . count ( '.' ) + 1 parts = path_parts [ : - module_parts ] return safe_sys_path_index ( _normalize_cached ( os . sep . join ( parts ) ) ) if not isinstance ( orig_path , list ) : # Is this behavior useful when module.__path__ is not a list? return orig_path . sort ( key = position_in_sys_path ) module . __path__ [ : ] = [ _normalize_cached ( p ) for p in orig_path ]