
    /~h                        d Z ddlmZ ddlZddlZddlZddlZddlm	Z	 ddl
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    V/var/www/peopleoo.sandbox-dev.co.uk/venv/lib/python3.12/site-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*   5   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?   D   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                8   t        | j                         |      }|r|st        d      |d}nt        j                  |j
                        }t               }d}	|D ]  }
|
| j                         k(  r:| j                  j                  d      r| j                  j                  d|
       Q	 t        j                  j                  |
      }t        |
d      5 }t!        j"                  d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{| j                  j                  d      r| j                  j                  d|
       t5        |
        |r|	st        d      yy# t        $ r |
}Y pw xY w# 1 sw Y   xY w# t.        $ rB}| j0                  r| j1                  t3        |             |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 combineNFdataiozSkipping combining ourself: rbsha3_256)usedforsecurityzCombining data file )debug)map_pathTz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   	functoolscachemapsetdata_filename_debugshouldwriter   r   relpath
ValueErroropenhashlibnewr$   readdigestaddr   r   _warnstrr
   )r   aliasesr8   strictkeepmessager;   rF   file_hashescombined_anyr   rel_file_namefobjr)   shacombine_this_onedelete_this_onenew_dataexcs                      r   combine_parallel_datarh   c   sj   F ((:(:(<jI&.//??7;;/%KL 2""$$ {{!!(+!!$@"FG	GGOOA.M !T] 	6d[[UCFMM$))+&--/C"+5		6 #({{!!(+!!$8">?OOC C'= Hx8#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/AI<'I/H>=H>I		J8JJ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:rG   z linez [])r   rM   printr   r   existsrV   r#   r!   r   keysr   r   r(   )r    r   summary	filenamesnfilesr   lineplugins           r   debug_data_filert      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    rZ   r)   r	   rw   Noner   )r7   rZ   r8   Iterable[str] | Nonerw   z	list[str])NNFFN)r   r   r[   zPathAliases | Noner8   ry   r\   rv   r]   rv   r^   zCallable[[str], None] | Nonerw   rx   )r    rZ   rw   rx   )r   r   r    rZ   rw   z	list[int])__doc__
__future__r   rI   r2   rT   os.pathr   typingr   collections.abcr   coverage.exceptionsr   r   coverage.filesr   coverage.miscr	   r
   r   r   coverage.sqldatar   r!   r*   r?   rh   rt   r'   r   r   r   <module>r      s    #      $ > & D D )0.$B #''+,0e2
e2e2 %e2 	e2
 e2 *e2 
e2P,r   