def _deep_split(filenames, size_per_shard, parsed_formats):
 roots = []
 inputs = []
 size_left = size_per_shard
 for filename in filenames:
  index = 0
  with files.open(filename) as f:
   cache_for_split = {}
   while True:
    if (size_left <= 0):
     roots.append(FileFormatRoot(copy.deepcopy(parsed_formats), inputs))
     size_left = size_per_shard
     inputs = []
    start_index = index
    (size_left, index) = parsed_formats[0].split(size_left, start_index, f, cache_for_split)
    if (start_index == index):
     break
    inputs.append(_FileRange(filename, (start_index, index)))
 if inputs:
  roots.append(FileFormatRoot(copy.deepcopy(parsed_formats), inputs))
 return roots

def _deep_split ( filenames , size_per_shard , parsed_formats ) : roots = [ ] inputs = [ ] size_left = size_per_shard for filename in filenames : index = 0 with files . open ( filename ) as f : cache_for_split = { } while True : if ( size_left <= 0 ) : roots . append ( FileFormatRoot ( copy . deepcopy ( parsed_formats ) , inputs ) ) size_left = size_per_shard inputs = [ ] start_index = index ( size_left , index ) = parsed_formats [ 0 ] . split ( size_left , start_index , f , cache_for_split ) if ( start_index == index ) : break inputs . append ( _FileRange ( filename , ( start_index , index ) ) ) if inputs : roots . append ( FileFormatRoot ( copy . deepcopy ( parsed_formats ) , inputs ) ) return roots
split files into roots using the first fileformat .