@@ -171,7 +171,7 @@ def html(module_name, docfilter=None, reload=False, skip_errors=False, **kwargs)
171171 that takes a single argument (a documentation object) and returns
172172 `True` or `False`. If `False`, that object will not be documented.
173173 """
174- mod = Module (import_module (module_name , reload = reload ),
174+ mod = Module (import_module (module_name , reload = reload , skip_errors = False ),
175175 docfilter = docfilter , skip_errors = skip_errors )
176176 link_inheritance ()
177177 return mod .html (** kwargs )
@@ -188,14 +188,18 @@ def text(module_name, docfilter=None, reload=False, skip_errors=False, **kwargs)
188188 that takes a single argument (a documentation object) and returns
189189 `True` or `False`. If `False`, that object will not be documented.
190190 """
191- mod = Module (import_module (module_name , reload = reload ),
191+ mod = Module (import_module (module_name , reload = reload , skip_errors = False ),
192192 docfilter = docfilter , skip_errors = skip_errors )
193193 link_inheritance ()
194194 return mod .text (** kwargs )
195195
196196
197- def import_module (module : Union [str , ModuleType ],
198- * , reload : bool = False ) -> ModuleType :
197+ def import_module (
198+ module : Union [str , ModuleType ],
199+ * ,
200+ reload : bool = False ,
201+ skip_errors : bool = False ,
202+ ) -> ModuleType :
199203 """
200204 Return module object matching `module` specification (either a python
201205 module path or a filesystem path to file/directory).
@@ -222,7 +226,11 @@ def _module_path(module):
222226 try :
223227 module = importlib .import_module (module_path )
224228 except Exception as e :
225- raise ImportError (f'Error importing { module !r} : { e .__class__ .__name__ } : { e } ' )
229+ msg = f'Error importing { module !r} : { e .__class__ .__name__ } : { e } '
230+ if not skip_errors :
231+ raise ImportError (msg )
232+ warn (msg , category = Module .ImportWarning , stacklevel = 2 )
233+ module = ModuleType (module_path )
226234
227235 assert inspect .ismodule (module )
228236 # If this is pdoc itself, return without reloading. Otherwise later
@@ -656,7 +664,7 @@ def __init__(self, module: Union[ModuleType, str], *,
656664 of raising an exception.
657665 """
658666 if isinstance (module , str ):
659- module = import_module (module )
667+ module = import_module (module , skip_errors = skip_errors )
660668
661669 super ().__init__ (module .__name__ , self , module )
662670 if self .name .endswith ('.__init__' ) and not self .is_package :
@@ -765,15 +773,9 @@ def iter_modules(paths):
765773
766774 assert self .refname == self .name
767775 fullname = f"{ self .name } .{ root } "
768- try :
769- m = Module (import_module (fullname ),
770- docfilter = docfilter , supermodule = self ,
771- context = self ._context , skip_errors = skip_errors )
772- except Exception as ex :
773- if skip_errors :
774- warn (str (ex ), Module .ImportWarning )
775- continue
776- raise
776+ m = Module (import_module (fullname , skip_errors = skip_errors ),
777+ docfilter = docfilter , supermodule = self ,
778+ context = self ._context , skip_errors = skip_errors )
777779
778780 self .doc [root ] = m
779781 # Skip empty namespace packages because they may
0 commit comments