
    ^ht                     V    S r SSKrSSKrSSKrSSKrSSKrSSKrS rS rS r	S r
S rg)z3Set of common tools to aid bundler implementations.    Nc                 n    [        X5      n[        [        R                  R	                  U 5      U5      nU$ )a  Gets a list of files referenced either in Markdown fenced code blocks
or in HTML comments from the nbclassic. Expands patterns expressed in
gitignore syntax (https://git-scm.com/docs/gitignore). Returns the
fully expanded list of filenames relative to the notebook dirname.

Parameters
----------
abs_nb_path: str
    Absolute path of the notebook on disk
version: int
    Version of the notebook document format to use

Returns
-------
list
    Filename strings relative to the notebook path
)get_reference_patternsexpand_referencesospathdirname)abs_nb_pathversionref_patternsexpandeds       Q/home/james-whalen/.local/lib/python3.13/site-packages/nbclassic/bundler/tools.pyget_file_referencesr      s,    $ *+?L !=|LHO    c                     [         R                  " X5      n/ nUR                   H  n[        U5      nU(       d  M  X5-   nM     U$ )a>  Gets a list of reference patterns either in Markdown fenced code blocks
or in HTML comments from the nbclassic.

Parameters
----------
abs_nb_path: str
    Absolute path of the notebook on disk
version: int
    Version of the notebook document format to use

Returns
-------
list
    Pattern strings from the notebook
)nbformatreadcellsget_cell_reference_patterns)r	   r
   notebookreferenced_listcell
referencess         r   r   r   "   sD      }}[2HO06
:-:O  r   c                    / nU R                  S5      R                  S5      (       a  U R                  S5      R                  S5      (       a  U R                  S5      [        S5      S R                  5       nU H\  nUR                  S5      (       a    GO/UR	                  S5      S:  d  M3  UR                  S	5      (       a  MK  UR                  U5        M^     OU R                  S5      R                  S5      (       a  U R                  S5      R	                  S
5      S:  a  U R                  S5      nUR	                  S
5      nXE[        S
5      -   S R                  5       nU H[  nUR                  S
5      (       a    ODUR	                  S5      S:  d  M2  UR                  S	5      (       a  MJ  UR                  U5        M]     U Vs/ s H  ofR                  5       (       d  M  UPM     sn$ s  snf )aO  
Retrieves the list of references from a single notebook cell. Looks for
fenced code blocks or HTML comments in Markdown cells, e.g.,

```
some.csv
foo/
!foo/bar
```

or

<!--associate:
some.csv
foo/
!foo/bar
-->

Parameters
----------
cell: dict
    Notebook cell object

Returns
-------
list
    Reference patterns found in the cell
	cell_typemarkdownsourcez<!--associate:Nz-->z../r   #z```)get
startswithlen
splitlinesfindappendstrip)r   
referencedlinesliner   offsetrefs          r   r   r   :   s   : Jxx''
338J8U8UVf8g8g"3'7#8#9:EEGDu%% yy!#DOOC,@,@!!$'  
+		)	)*	5	5$((8:L:Q:QRW:X\]:](#U#E
*+,779Du%% yy!#DOOC,@,@!!$'  &5:CC:555s   	G.%G.c           	         / nU H\  n[         R                  R                  U5      nUR                  S5      (       a  U[         R                  -  nUR                  U5        M^     Un/ n/ n/ nU H  nU(       a  UR                  [         R                  5      S:  a  [         R                  " 5       n	[         R                  " U 5        UR                  S5      (       a  U[        R                  " USS 5      -   nOU[        R                  " U5      -   n[         R                  " U	5        M  U(       d  M  UR                  U5        M     U GH  nUR                  S5      n
U
(       a  USS nOUn[         R                  " U 5       GH  u  pnU GH  n[         R                  R                  U[        U 5      S-   S U5      nUR                  [         R                  5      (       aE  UR                  U5      (       a-  U
(       a  UR                  U5        M  UR                  U5        M  M  UR                  S5      S:  a  UR                  S5      n[        U5      S:X  ag  UR                  US   5      (       aK  UR                  US   5      (       a/  U
(       a  UR                  U5        GM  UR                  U5        GM2  GM5  GM8  GM;  [        R                  " UU5      (       d  GMZ  U
(       a  UR                  U5        GMu  UR                  U5        GM     GM     GM     U H  n UR!                  U5        M     [%        U5      $ ! ["         a  n SnAM4  SnAff = f)a-  Expands a set of reference patterns by evaluating them against the
given root directory. Expansions are performed against patterns
expressed in the same manner as in gitignore
(https://git-scm.com/docs/gitignore).

NOTE: Temporarily changes the current working directory when called.

Parameters
----------
root_path: str
    Assumed root directory for the patterns
references: list
    Reference patterns from get_reference_patterns expressed with
    forward-slash directory separators

Returns
-------
list
    Filename strings relative to the root path
/r   !   Nz**   )r   r   normpathendswithsepr#   r"   getcwdchdirr   globwalkjoinr    splitfnmatchremove
ValueErrorset)	root_pathr   normalized_referencesr)   normalized_refglobbed	negations	must_walkpatterncwdpattern_is_negationtestpatternroot_	filenamesfilenamejoinedendsnegatederrs                       r   r   r   r   s   . ))#.<<bff$N$$^4  'JGIIw||BFF+a/))+CHHY!!#&&%		'!"+(>>	!DIIg$66HHSMWW%  %005!!"+K!K"$'')"4DY%d3y>A+=+>&?J''//((55.%,,V4#NN62	 6
 !%%d+q0&,,T2D4yA~!,,T!W55&//$q':R:R2 ) 0 0 8 'v 6	 ;S5 & v{;;.%,,V4#NN62/ & #5 @ 	NN7# 
 w<  		s   )M		
MMc                 d   U H  n[         R                  R                  [         R                  R                  X5      5      (       d  MF  [         R                  R	                  U5      nU(       a6  [         R                  R                  X5      n [         R
                  " U5        [        R                  " [         R                  R                  X5      [         R                  R                  X5      5        M     g! [         a*  nUR                  [        R                  :X  a   SnANUeSnAff = f)a  Copies the given list of files, relative to src, into dst, creating
directories along the way as needed and ignore existence errors.
Skips any files that do not exist. Does not create empty directories
from src in dst.

Parameters
----------
src: str
    Root of the source directory
dst: str
    Root of the destination directory
src_relative_filenames: list
    Filenames relative to src
N)r   r   isfiler6   r   makedirsOSErrorerrnoEEXISTshutilcopy2)srcdstsrc_relative_filenamesrI   parent_relative
parent_dstexcs          r   copy_filelistr\      s     +77>>"'',,s566 ggooh7OWW\\#?
"KK
+ LLc4bggll36QR +  "yyELL0!		"s   C;;
D/D*(D**D/)__doc__r   rT   rR   r   r8   r4   r   r   r   r   r\    r   r   <module>r_      s9    9 
     ,066pUnSr   