
    He                        d Z ddlmZ ddlZddlZddlZddlmZm	Z	 ddl
mZmZ ddlmZ ddlmZmZmZmZ ddlmZ ddd	Zdd
ZdddZ	 	 	 	 	 d	 	 	 	 	 	 	 	 	 	 	 	 	 ddZddZddZy)a  Coverage data for coverage.py.

This file had the 4.x JSON data support, which is now gone.  This file still
has storage-agnostic helpers, and is kept to avoid changing too many imports.
CoverageData is now defined in sqldata.py, and imported here to keep the
imports working.

    )annotationsN)CallableIterable)CoverageExceptionNoDataError)PathAliases)Hasherfile_be_gonehuman_sortedplural)CoverageDatac                    i }|rd }nt         j                  j                  }| j                         D ]+  }| j	                  |      }|J t        |      | ||      <   - |S )aH  Return a dict summarizing the line coverage data.

    Keys are based on the file names, and values are the number of executed
    lines.  If `fullpath` is true, then the keys are the full pathnames of
    the files, otherwise they are the basenames of the files.

    Returns a dict mapping file names to counts of lines.

    c                    | S N )fs    //usr/lib/python3/dist-packages/coverage/data.py<lambda>zline_counts.<locals>.<lambda>)   s         )ospathbasenamemeasured_fileslineslen)datafullpathsummfilename_fnfilenamer   s         r   line_countsr!      sl     D!gg&&'') 1

8$   &)%j["#1 Kr   c                    | j                         r.|j                  t        | j                  |      xs g              n|j                  t	        | |             |j                  | j                  |             y)zContribute `filename`'s data to the `hasher`.

    `hasher` is a `coverage.misc.Hasher` instance to be updated with
    the file's data.  It should only get the results data, not the run
    data.

    N)has_arcsupdatesortedarcssorted_linesfile_tracer)r   r    hashers      r   add_data_to_hashr*   3   sV     }}fTYYx06B78l423
MM$""8,-r   c                   t         j                  j                  t         j                  j                  |             \  }}|xs |g}g }|D ]  }t         j                  j	                  |      r/|j                  t         j                  j                  |             Qt         j                  j                  |      rxt        j                  t         j                  j                  t         j                  j                  |      |            dz   }|j                  t        j                  |             t        d| d       |D cg c]  }|j                  d      r| }}t        |      S c c}w )zMake a list of data files to be combined.

    `data_file` is a path to a data file.  `data_paths` is a list of files or
    directories of files.

    Returns a list of absolute file paths.
    z.*z)Couldn't combine from non-existent path ''z-journal)r   r   splitabspathisfileappendisdirglobescapejoinextendr   endswithr%   )	data_file
data_pathsdata_dirlocalfiles_to_combineppatternfnms           r   combinable_filesr?   B   s    ggmmBGGOOI$>?OHe)zJ P77>>!##BGGOOA$67WW]]1kk"'',,rwwq/A5"IJDPG##DIIg$67 I!ANOOP (8Xs||J?WXX
 "## Ys   E/E/c                   t        | j                         |      }|r|st        d      t               }d}|D ]  }	|	| j	                         k(  r:| j
                  j                  d      r| j
                  j                  d|	       Q	 t        j                  j                  |	      }
t        |	d      5 }t        j                  d      }|j                  |j!                                |j#                         }||v}ddd       | }r| j
                  j                  d      r| j
                  j                  d|	       |j%                         	 t'        |	| j
                  	      }|j!                          | j                  ||
       d}|r |d|
        n|r |d|
        |sy| j
                  j                  d      r| j
                  j                  d|	       t/        |	        |r|st        d      yy# t        $ r |	}
Y nw xY w# 1 sw Y   xY w# t(        $ rB}| j*                  r| j+                  t-        |             |r |d|
 d|        d}Y d}~d}~ww xY w)a  Combine a number of data files together.

    `data` is a CoverageData.

    Treat `data.filename` as a file prefix, and combine the data from all
    of the data files starting with that prefix plus a dot.

    If `aliases` is provided, it's a `PathAliases` object that is used to
    re-map paths to match the local machine's.

    If `data_paths` is provided, it is a list of directories or files to
    combine.  Directories are searched for files that start with
    `data.filename` plus dot as a prefix, and those files are combined.

    If `data_paths` is not provided, then the directory portion of
    `data.filename` is used as the directory to search for data files.

    Unless `keep` is True every data file found and combined is then deleted
    from disk. If a file cannot be read, a warning will be issued, and the
    file will not be deleted.

    If `strict` is true, and no files are found to combine, an error is
    raised.

    `message` is a function to use for printing messages to the user.

    zNo data to combineFdataiozSkipping combining ourself: rbsha3_256NzCombining data file )debug)aliasesTzCombined data file zCouldn't combine data file : zSkipping duplicate data zDeleting data file zNo usable data files)r?   base_filenamer   setdata_filename_debugshouldwriter   r   relpath
ValueErroropenhashlibnewr$   readdigestaddr   r   _warnstrr
   )r   rE   r8   strictkeepmessager;   file_hashescombined_anyr   rel_file_namefobjr)   shacombine_this_onedelete_this_onenew_dataexcs                     r   combine_parallel_datarc   a   sL   F ((:(:(<jI&.//%KL 2""$$ {{!!(+!!$@"FG	GGOOA.M !T] 	6d[[,FMM$))+&--/C"+5		6 #({{!!(+!!$8">?OOC C'= Hg6#1-AB2=/BC{{!!(+!!$7u"=>Oe2h l011 #vU  	 M			6 	6 % (:: JJs3x(9-3%PQ"'(s7   
H	5A	H'H(	HHH%	(	I318I..I3c           	     (   t        |       }|j                         } t        d|         t        j                  j                  |       st        d       y|j                          t        d|j                                t        |d      }t        |j                               }t        |      }t        | dt        |       d       |D ]B  }| d	||    d
t        ||          }|j                  |      }|r	|d| dz  }t        |       D y)z(Implementation of 'coverage debug data'.zpath: z%No data collected: file doesn't existNz
has_arcs: T)r   z file:rF   z linez [])r   rI   printr   r   existsrR   r#   r!   r   keysr   r   r(   )r    r   summary	filenamesnfilesr   lineplugins           r   debug_data_filero      s   !D!!#H	F8*
77>>(#56IIK	Jt}})
*+$.GW\\^,I^F	VHE&.)
+, Bwqzl%wqz(:';<!!!$bN"Ddr   c                B    | j                  |      }t        |xs g       S )z+Get the sorted lines for a file, for tests.)r   r%   )r   r    r   s      r   r'   r'      s    JJx E%+2r   )F)r   r   r   boolreturnzdict[str, int])r   r   r    rV   r)   r	   rr   Noner   )r7   rV   r8   Iterable[str] | Nonerr   z	list[str])NNFFN)r   r   rE   zPathAliases | Noner8   rt   rW   rq   rX   rq   rY   zCallable[[str], None] | Nonerr   rs   )r    rV   rr   rs   )r   r   r    rV   rr   z	list[int])__doc__
__future__r   r2   rP   os.pathr   typingr   r   coverage.exceptionsr   r   coverage.filesr   coverage.miscr	   r
   r   r   coverage.sqldatar   r!   r*   r?   rc   ro   r'   r   r   r   <module>r}      s    #    % > & D D )0.$B #''+,0`2
`2`2 %`2 	`2
 `2 *`2 
`2F,r   