@@ -438,7 +438,7 @@ def resolve_glob(toctrees, index_file):
438438 f_ .update (docs )
439439
440440
441- def prepare_doc (doc , repos_dir , doc_dir ):
441+ def prepare_doc (doc , repos_dir , doc_dir , drop_ext ):
442442 if path .isdir (doc_dir ):
443443 pr .run (f"rm -r { doc_dir } " )
444444 mkdir (doc_dir )
@@ -488,18 +488,23 @@ def prepare_doc(doc, repos_dir, doc_dir):
488488 spec .loader .exec_module (__c )
489489 if hasattr (__c , 'extensions' ):
490490 for ext in __c .extensions :
491+ ext_miss = False
491492 if ext in exclude_extensions :
492493 __c .extensions .remove (ext )
493494 continue
494495 try :
495496 if hasattr (__c , 'sys' ):
496497 if not finder .find_spec (ext , __c .sys .path ):
497- missing_ext . append (( path_ , ext ))
498+ ext_miss = True
498499 else :
499500 if not importlib .util .find_spec (ext ):
500- missing_ext . append (( path_ , ext ))
501+ ext_miss = True
501502 except ModuleNotFoundError :
503+ ext_miss = True
504+ if ext_miss :
502505 missing_ext .append ((path_ , ext ))
506+ if drop_ext :
507+ __c .extensions .remove (ext )
503508
504509 doc ['extensions' ].update (__c .extensions )
505510 doc ['extensions' ].add ('sphinx.ext.intersphinx' )
@@ -631,7 +636,11 @@ def is_orphan_or_explicit_entry(d):
631636 ext = defaultdict (list )
632637 [ext [r ].append (ext_ ) for r , ext_ in missing_ext ]
633638 click .echo (f"Some inferred extensions are not installed: { dict (ext )} " )
634- sys .exit (1 )
639+ if not drop_ext :
640+ click .echo (f"If they are not necessary, use --drop-missing-extensions to remove them." )
641+ sys .exit (1 )
642+ else :
643+ click .echo (f"And will not be added to the configuration file." )
635644
636645 # Copy over custom pages
637646 for c in doc ['custom' ]:
@@ -1025,7 +1034,14 @@ def organize_include(doc):
10251034 default = False ,
10261035 help = "Clone repositories with SSH instead of HTTPS."
10271036)
1028- def custom_doc (directory , extra , no_parallel_ , open_ , builder , ssh ):
1037+ @click .option (
1038+ '--drop-missing-extensions' ,
1039+ 'drop_ext' ,
1040+ is_flag = True ,
1041+ default = False ,
1042+ help = "Drop extensions not installed, useful when the pages don't use them anyway."
1043+ )
1044+ def custom_doc (directory , extra , no_parallel_ , open_ , builder , ssh , drop_ext ):
10291045 """
10301046 Creates an aggregated documentation out the repos
10311047 in the doc.yaml file.
@@ -1126,7 +1142,7 @@ def custom_doc(directory, extra, no_parallel_, open_, builder, ssh):
11261142
11271143 # Messing with WeasyPrint?
11281144 # Comment the four lines below to skip Sphinx generation
1129- prepare_doc (doc , directory , doc_dir )
1145+ prepare_doc (doc , directory , doc_dir , drop_ext )
11301146 parse_warnings (doc_dir )
11311147 parse_status (doc_dir )
11321148 patch_doc (doc , directory , doc_dir , doc_patch_dir , git_lfs , sphinx_builder )
0 commit comments