@@ -610,6 +610,7 @@ def copy_notebooks(
610610 path_docs_ipynb : str = "notebooks" ,
611611 path_docs_images : str = "_static/images" ,
612612 patterns : Sequence [str ] = ("." , "**" ),
613+ ignore : Optional [Sequence [str ]] = None ,
613614 ) -> None :
614615 """Copy all notebooks from a folder to doc folder.
615616
@@ -619,40 +620,61 @@ def copy_notebooks(
619620 path_docs_ipynb: destination path to the notebooks' location relative to ``docs_root``
620621 path_docs_images: destination path to the images' location relative to ``docs_root``
621622 patterns: patterns to use when glob-ing notebooks
623+ ignore: ignore some specific notebooks even when the given string is in path
622624 """
623- ls_ipynb = []
624- for sub in patterns :
625- ls_ipynb += glob .glob (os .path .join (path_root , DIR_NOTEBOOKS , sub , "*.ipynb" ))
626-
625+ all_ipynb = []
626+ for pattern in patterns :
627+ all_ipynb += glob .glob (os .path .join (path_root , DIR_NOTEBOOKS , pattern , "*.ipynb" ))
627628 os .makedirs (os .path .join (docs_root , path_docs_ipynb ), exist_ok = True )
628- ipynb_content = []
629- for path_ipynb in tqdm .tqdm (ls_ipynb ):
630- ipynb = path_ipynb .split (os .path .sep )
631- sub_ipynb = os .path .sep .join (ipynb [ipynb .index (DIR_NOTEBOOKS ) + 1 :])
632- new_ipynb = os .path .join (docs_root , path_docs_ipynb , sub_ipynb )
633- os .makedirs (os .path .dirname (new_ipynb ), exist_ok = True )
629+ if ignore and not isinstance (ignore , (list , set , tuple )):
630+ ignore = [ignore ]
631+ elif not ignore :
632+ ignore = []
634633
635- path_meta = path_ipynb .replace (".ipynb" , ".yaml" )
636- path_thumb = AssistantCLI ._resolve_path_thumb (path_ipynb , path_meta )
634+ ipynb_content = []
635+ for path_ipynb in tqdm .tqdm (all_ipynb ):
636+ if any (skip in path_ipynb for skip in ignore ):
637+ print (f"ignore/skip copy: { path_ipynb } " )
638+ continue
639+ path_ipynb_in_dir = AssistantCLI ._copy_notebook (
640+ path_ipynb ,
641+ path_root = path_root ,
642+ docs_root = docs_root ,
643+ path_docs_ipynb = path_docs_ipynb ,
644+ path_docs_images = path_docs_images ,
645+ )
646+ ipynb_content .append (os .path .join (path_docs_ipynb , path_ipynb_in_dir ))
637647
638- if path_thumb is not None :
639- new_thumb = os .path .join (docs_root , path_docs_images , path_thumb )
640- old_path_thumb = os .path .join (path_root , DIR_NOTEBOOKS , path_thumb )
641- os .makedirs (os .path .dirname (new_thumb ), exist_ok = True )
642- copyfile (old_path_thumb , new_thumb )
643- path_thumb = os .path .join (path_docs_images , path_thumb )
648+ @staticmethod
649+ def _copy_notebook (
650+ path_ipynb : str , path_root : str , docs_root : str , path_docs_ipynb : str , path_docs_images : str
651+ ) -> str :
652+ """Copy particular notebook."""
653+ ipynb = path_ipynb .split (os .path .sep )
654+ path_ipynb_in_dir = os .path .sep .join (ipynb [ipynb .index (DIR_NOTEBOOKS ) + 1 :])
655+ new_ipynb = os .path .join (docs_root , path_docs_ipynb , path_ipynb_in_dir )
656+ os .makedirs (os .path .dirname (new_ipynb ), exist_ok = True )
657+
658+ path_meta = path_ipynb .replace (".ipynb" , ".yaml" )
659+ path_thumb = AssistantCLI ._resolve_path_thumb (path_ipynb , path_meta )
644660
645- print (f"{ path_ipynb } -> { new_ipynb } " )
661+ if path_thumb is not None :
662+ new_thumb = os .path .join (docs_root , path_docs_images , path_thumb )
663+ old_path_thumb = os .path .join (path_root , DIR_NOTEBOOKS , path_thumb )
664+ os .makedirs (os .path .dirname (new_thumb ), exist_ok = True )
665+ copyfile (old_path_thumb , new_thumb )
666+ path_thumb = os .path .join (path_docs_images , path_thumb )
646667
647- with open (path_ipynb ) as f :
648- ipynb = json .load (f )
668+ print (f"{ path_ipynb } -> { new_ipynb } " )
649669
650- ipynb ["cells" ].append (AssistantCLI ._get_card_item_cell (path_ipynb , path_meta , path_thumb ))
670+ with open (path_ipynb ) as fopen :
671+ ipynb = json .load (fopen )
651672
652- with open (new_ipynb , "w" ) as f :
653- json .dump (ipynb , f )
673+ ipynb ["cells" ].append (AssistantCLI ._get_card_item_cell (path_ipynb , path_meta , path_thumb ))
654674
655- ipynb_content .append (os .path .join ("notebooks" , sub_ipynb ))
675+ with open (new_ipynb , "w" ) as fopen :
676+ json .dump (ipynb , fopen , indent = 4 )
677+ return path_ipynb_in_dir
656678
657679 @staticmethod
658680 def update_env_details (folder : str , base_path : str = DIR_NOTEBOOKS ) -> str :
0 commit comments