Improve error messages formatting in doc loaders (#4586)

# Cosmetic in errors formatting

Added appropriate spacing to the `ImportError` message in a bunch of
document loaders to enhance trace readability (including Google Drive,
Youtube, Confluence and others). This change ensures that the error
messages are not displayed as a single line block, and that the `pip
install xyz` commands can be copied to clipboard from terminal easily.

## Who can review?

@eyurtsev
parallel_dir_loader
Andrea Pinto 1 year ago committed by GitHub
parent 570d057db4
commit 1e5d25b93c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -92,7 +92,7 @@ class ConfluenceLoader(BaseLoader):
from atlassian import Confluence # noqa: F401 from atlassian import Confluence # noqa: F401
except ImportError: except ImportError:
raise ImportError( raise ImportError(
"`atlassian` package not found, please run" "`atlassian` package not found, please run "
"`pip install atlassian-python-api`" "`pip install atlassian-python-api`"
) )
@ -124,13 +124,13 @@ class ConfluenceLoader(BaseLoader):
if (api_key and not username) or (username and not api_key): if (api_key and not username) or (username and not api_key):
errors.append( errors.append(
"If one of `api_key` or `username` is provided," "If one of `api_key` or `username` is provided, "
"the other must be as well." "the other must be as well."
) )
if (api_key or username) and oauth2: if (api_key or username) and oauth2:
errors.append( errors.append(
"Cannot provide a value for `api_key` and/or" "Cannot provide a value for `api_key` and/or "
"`username` and provide a value for `oauth2`" "`username` and provide a value for `oauth2`"
) )
@ -141,8 +141,8 @@ class ConfluenceLoader(BaseLoader):
"key_cert", "key_cert",
]: ]:
errors.append( errors.append(
"You have either ommited require keys or added extra" "You have either ommited require keys or added extra "
"keys to the oauth2 dictionary. key values should be" "keys to the oauth2 dictionary. key values should be "
"`['access_token', 'access_token_secret', 'consumer_key', 'key_cert']`" "`['access_token', 'access_token_secret', 'consumer_key', 'key_cert']`"
) )
@ -192,7 +192,7 @@ class ConfluenceLoader(BaseLoader):
""" """
if not space_key and not page_ids and not label and not cql: if not space_key and not page_ids and not label and not cql:
raise ValueError( raise ValueError(
"Must specify at least one among `space_key`, `page_ids`," "Must specify at least one among `space_key`, `page_ids`, "
"`label`, `cql` parameters." "`label`, `cql` parameters."
) )
@ -338,8 +338,8 @@ class ConfluenceLoader(BaseLoader):
from bs4 import BeautifulSoup # type: ignore from bs4 import BeautifulSoup # type: ignore
except ImportError: except ImportError:
raise ImportError( raise ImportError(
"`beautifulsoup4` package not found, please run" "`beautifulsoup4` package not found, please run "
" `pip install beautifulsoup4`" "`pip install beautifulsoup4`"
) )
if include_attachments: if include_attachments:
@ -374,7 +374,7 @@ class ConfluenceLoader(BaseLoader):
from PIL import Image # noqa: F401 from PIL import Image # noqa: F401
except ImportError: except ImportError:
raise ImportError( raise ImportError(
"`pytesseract` or `pdf2image` or `Pillow` package not found," "`pytesseract` or `pdf2image` or `Pillow` package not found, "
"please run `pip install pytesseract pdf2image Pillow`" "please run `pip install pytesseract pdf2image Pillow`"
) )
@ -415,7 +415,7 @@ class ConfluenceLoader(BaseLoader):
from pdf2image import convert_from_bytes # noqa: F401 from pdf2image import convert_from_bytes # noqa: F401
except ImportError: except ImportError:
raise ImportError( raise ImportError(
"`pytesseract` or `pdf2image` package not found," "`pytesseract` or `pdf2image` package not found, "
"please run `pip install pytesseract pdf2image`" "please run `pip install pytesseract pdf2image`"
) )
@ -450,7 +450,7 @@ class ConfluenceLoader(BaseLoader):
from PIL import Image # noqa: F401 from PIL import Image # noqa: F401
except ImportError: except ImportError:
raise ImportError( raise ImportError(
"`pytesseract` or `Pillow` package not found," "`pytesseract` or `Pillow` package not found, "
"please run `pip install pytesseract Pillow`" "please run `pip install pytesseract Pillow`"
) )
@ -531,7 +531,7 @@ class ConfluenceLoader(BaseLoader):
from svglib.svglib import svg2rlg # noqa: F401 from svglib.svglib import svg2rlg # noqa: F401
except ImportError: except ImportError:
raise ImportError( raise ImportError(
"`pytesseract`, `Pillow`, or `svglib` package not found," "`pytesseract`, `Pillow`, or `svglib` package not found, "
"please run `pip install pytesseract Pillow svglib`" "please run `pip install pytesseract Pillow svglib`"
) )

@ -68,10 +68,10 @@ class GoogleDriveLoader(BaseLoader, BaseModel):
from google_auth_oauthlib.flow import InstalledAppFlow from google_auth_oauthlib.flow import InstalledAppFlow
except ImportError: except ImportError:
raise ImportError( raise ImportError(
"You must run" "You must run "
"`pip install --upgrade " "`pip install --upgrade "
"google-api-python-client google-auth-httplib2 " "google-api-python-client google-auth-httplib2 "
"google-auth-oauthlib`" "google-auth-oauthlib` "
"to use the Google Drive loader." "to use the Google Drive loader."
) )

@ -40,8 +40,8 @@ class ImageCaptionLoader(BaseLoader):
from transformers import BlipForConditionalGeneration, BlipProcessor from transformers import BlipForConditionalGeneration, BlipProcessor
except ImportError: except ImportError:
raise ValueError( raise ValueError(
"transformers package not found, please install with" "`transformers` package not found, please install with "
"`pip install transformers`" "`pip install transformers`."
) )
processor = BlipProcessor.from_pretrained(self.blip_processor) processor = BlipProcessor.from_pretrained(self.blip_processor)
@ -67,7 +67,7 @@ class ImageCaptionLoader(BaseLoader):
from PIL import Image from PIL import Image
except ImportError: except ImportError:
raise ValueError( raise ValueError(
"PIL package not found, please install with `pip install pillow`" "`PIL` package not found, please install with `pip install pillow`"
) )
try: try:

@ -197,7 +197,7 @@ class OneDriveLoader(BaseLoader, BaseModel):
file = drive.get_item(object_id) file = drive.get_item(object_id)
if not file: if not file:
logging.warning( logging.warning(
"There isn't a file with" "There isn't a file with "
f"object_id {object_id} in drive {drive}." f"object_id {object_id} in drive {drive}."
) )
continue continue

@ -194,7 +194,7 @@ class PDFMinerLoader(BasePDFLoader):
from pdfminer.high_level import extract_text # noqa:F401 from pdfminer.high_level import extract_text # noqa:F401
except ImportError: except ImportError:
raise ValueError( raise ValueError(
"pdfminer package not found, please install it with " "`pdfminer` package not found, please install it with "
"`pip install pdfminer.six`" "`pip install pdfminer.six`"
) )
@ -222,7 +222,7 @@ class PDFMinerPDFasHTMLLoader(BasePDFLoader):
from pdfminer.high_level import extract_text_to_fp # noqa:F401 from pdfminer.high_level import extract_text_to_fp # noqa:F401
except ImportError: except ImportError:
raise ValueError( raise ValueError(
"pdfminer package not found, please install it with " "`pdfminer` package not found, please install it with "
"`pip install pdfminer.six`" "`pip install pdfminer.six`"
) )
@ -256,7 +256,7 @@ class PyMuPDFLoader(BasePDFLoader):
import fitz # noqa:F401 import fitz # noqa:F401
except ImportError: except ImportError:
raise ValueError( raise ValueError(
"PyMuPDF package not found, please install it with " "`PyMuPDF` package not found, please install it with "
"`pip install pymupdf`" "`pip install pymupdf`"
) )

@ -22,7 +22,7 @@ class S3FileLoader(BaseLoader):
import boto3 import boto3
except ImportError: except ImportError:
raise ValueError( raise ValueError(
"Could not import boto3 python package. " "Could not import `boto3` python package. "
"Please install it with `pip install boto3`." "Please install it with `pip install boto3`."
) )
s3 = boto3.client("s3") s3 = boto3.client("s3")

@ -76,7 +76,7 @@ class WebBaseLoader(BaseLoader):
self.session.headers = dict(headers) self.session.headers = dict(headers)
except ImportError: except ImportError:
logger.info( logger.info(
"fake_useragent not found, using default user agent." "fake_useragent not found, using default user agent. "
"To get a realistic header for requests, `pip install fake_useragent`." "To get a realistic header for requests, `pip install fake_useragent`."
) )

@ -70,8 +70,8 @@ class GoogleApiClient:
"You must run" "You must run"
"`pip install --upgrade " "`pip install --upgrade "
"google-api-python-client google-auth-httplib2 " "google-api-python-client google-auth-httplib2 "
"google-auth-oauthlib" "google-auth-oauthlib "
"youtube-transcript-api`" "youtube-transcript-api` "
"to use the Google Drive loader" "to use the Google Drive loader"
) )
@ -239,8 +239,8 @@ class GoogleApiYoutubeLoader(BaseLoader):
"You must run" "You must run"
"`pip install --upgrade " "`pip install --upgrade "
"google-api-python-client google-auth-httplib2 " "google-api-python-client google-auth-httplib2 "
"google-auth-oauthlib" "google-auth-oauthlib "
"youtube-transcript-api`" "youtube-transcript-api` "
"to use the Google Drive loader" "to use the Google Drive loader"
) )
@ -305,7 +305,7 @@ class GoogleApiYoutubeLoader(BaseLoader):
raise ImportError( raise ImportError(
"You must run" "You must run"
"`pip install --upgrade " "`pip install --upgrade "
"youtube-transcript-api`" "youtube-transcript-api` "
"to use the youtube loader" "to use the youtube loader"
) )

Loading…
Cancel
Save