fixed the skip_import_error option
This commit is contained in:
@@ -63,6 +63,7 @@ class GriffeLoader:
|
|||||||
self,
|
self,
|
||||||
module_paths: List[str],
|
module_paths: List[str],
|
||||||
project_name: Optional[str] = None,
|
project_name: Optional[str] = None,
|
||||||
|
skip_import_errors: bool = None,
|
||||||
) -> Project:
|
) -> Project:
|
||||||
if not module_paths:
|
if not module_paths:
|
||||||
raise ValueError("At least one module path must be provided")
|
raise ValueError("At least one module path must be provided")
|
||||||
@@ -73,7 +74,14 @@ class GriffeLoader:
|
|||||||
project = Project(name=project_name)
|
project = Project(name=project_name)
|
||||||
|
|
||||||
for module_path in module_paths:
|
for module_path in module_paths:
|
||||||
module = self.load_module(module_path)
|
try:
|
||||||
|
module = self.load_module(module_path)
|
||||||
|
except ImportError as import_error:
|
||||||
|
if skip_import_errors:
|
||||||
|
logger.debug("Could not load %s: %s", module_path, import_error)
|
||||||
|
continue
|
||||||
|
else:
|
||||||
|
raise import_error
|
||||||
project.add_module(module)
|
project.add_module(module)
|
||||||
|
|
||||||
return project
|
return project
|
||||||
|
|||||||
@@ -23,6 +23,7 @@ class GriffeLoader:
|
|||||||
self,
|
self,
|
||||||
module_paths: List[str],
|
module_paths: List[str],
|
||||||
project_name: Optional[str] = ...,
|
project_name: Optional[str] = ...,
|
||||||
|
skip_import_errors: bool = ...,
|
||||||
) -> Project:
|
) -> Project:
|
||||||
"""Load a documentation project from Python modules."""
|
"""Load a documentation project from Python modules."""
|
||||||
|
|
||||||
|
|||||||
@@ -1,12 +1,21 @@
|
|||||||
|
import pytest
|
||||||
from docforge import GriffeLoader
|
from docforge import GriffeLoader
|
||||||
|
|
||||||
|
|
||||||
def test_import_failure_does_not_crash():
|
def test_load_project_raises_on_missing_module_by_default():
|
||||||
|
loader = GriffeLoader()
|
||||||
|
|
||||||
|
with pytest.raises(ImportError):
|
||||||
|
loader.load_project(
|
||||||
|
["nonexistent.module", "sys"]
|
||||||
|
)
|
||||||
|
|
||||||
|
def test_load_project_skips_missing_modules_when_enabled():
|
||||||
loader = GriffeLoader()
|
loader = GriffeLoader()
|
||||||
|
|
||||||
project = loader.load_project(
|
project = loader.load_project(
|
||||||
["nonexistent.module", "sys"]
|
["nonexistent.module", "sys"],
|
||||||
|
skip_import_errors=True,
|
||||||
)
|
)
|
||||||
|
|
||||||
# sys should still load
|
assert "sys" in project.modules
|
||||||
assert "sys" in project.modules
|
|
||||||
Reference in New Issue
Block a user