diff --git a/packages/markitdown/src/markitdown/_exceptions.py b/packages/markitdown/src/markitdown/_exceptions.py index cae5990..abfebc6 100644 --- a/packages/markitdown/src/markitdown/_exceptions.py +++ b/packages/markitdown/src/markitdown/_exceptions.py @@ -1,5 +1,12 @@ from typing import Optional, List, Any +MISSING_DEPENDENCY_MESSAGE = """{converter} recognized the input as a potential {extension} file, but the dependencies needed to read {extension} files have not been installed. To resolve this error, include the optional dependency [{feature}] or [all] when installing MarkItDown. For example: + +* pip install markitdown[{feature}] +* pip install markitdown[all] +* pip install markitdown[{feature}, ...] +* etc.""" + class MarkItDownException(Exception): """ diff --git a/packages/markitdown/src/markitdown/converters/_docx_converter.py b/packages/markitdown/src/markitdown/converters/_docx_converter.py index b68500f..de4bf0d 100644 --- a/packages/markitdown/src/markitdown/converters/_docx_converter.py +++ b/packages/markitdown/src/markitdown/converters/_docx_converter.py @@ -8,7 +8,7 @@ from ._base import ( from ._base import DocumentConverter from ._html_converter import HtmlConverter -from .._exceptions import MissingDependencyException +from .._exceptions import MissingDependencyException, MISSING_DEPENDENCY_MESSAGE # Try loading optional (but in this case, required) dependencies # Save reporting of any exceptions for later @@ -39,12 +39,11 @@ class DocxConverter(HtmlConverter): # Load the dependencies if _dependency_exc_info is not None: raise MissingDependencyException( - f"""{type(self).__name__} recognized the input as a potential .docx file, but the dependencies needed to read .docx files have not been installed. To resolve this error, include the optional dependency [docx] or [all] when installing MarkItDown. For example: - -* pip install markitdown[docx] -* pip install markitdown[all] -* pip install markitdown[pptx, docx, ...] -* etc.""" + MISSING_DEPENDENCY_MESSAGE.format( + converter=type(self).__name__, + extension=".docx", + feature="docx", + ) ) from _dependency_exc_info[1].with_traceback( _dependency_exc_info[2] ) # Restore the original traceback diff --git a/packages/markitdown/src/markitdown/converters/_pptx_converter.py b/packages/markitdown/src/markitdown/converters/_pptx_converter.py index 7d72c1b..e8cbf71 100644 --- a/packages/markitdown/src/markitdown/converters/_pptx_converter.py +++ b/packages/markitdown/src/markitdown/converters/_pptx_converter.py @@ -7,7 +7,7 @@ from typing import Union from ._base import DocumentConverterResult, DocumentConverter from ._html_converter import HtmlConverter -from .._exceptions import MissingDependencyException +from .._exceptions import MissingDependencyException, MISSING_DEPENDENCY_MESSAGE # Try loading optional (but in this case, required) dependencies # Save reporting of any exceptions for later @@ -67,12 +67,11 @@ class PptxConverter(HtmlConverter): # Load the dependencies if _dependency_exc_info is not None: raise MissingDependencyException( - f"""{type(self).__name__} recognized the input as a potential .pptx file, but the dependencies needed to read .pptx files have not been installed. To resolve this error, include the optional dependency [pptx] or [all] when installing MarkItDown. For example: - -* pip install markitdown[pptx] -* pip install markitdown[all] -* pip install markitdown[pptx, docx, ...] -* etc.""" + MISSING_DEPENDENCY_MESSAGE.format( + converter=type(self).__name__, + extension=".pptx", + feature="pptx", + ) ) from _dependency_exc_info[1].with_traceback( _dependency_exc_info[2] ) # Restore the original traceback