Fix: Resolve several issues with the require dependencies decorator (#315)

Fix several issues re. the requires_dependencies decorator:
* There was a missing space between the sentences.
* Crucial brackets were missing in making the error message.
* "pygithub" was used where "github" should have been used.
This commit is contained in:
Tom Aarsen 2023-02-28 21:21:59 +01:00 committed by GitHub
parent 69661788cf
commit 1ccbc05b10
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 24 additions and 8 deletions

View File

@ -1,9 +1,20 @@
## 0.5.1-dev1
### Enhancements
### Features
### Fixes
* Fix several issues with the `requires_dependencies` decorator, including the error message
and how it was used.
## 0.5.0
### Enhancements
* Add `requires_dependencies` Python decorator to check dependencies are installed before
instantiating a class or running a function
instantiating a class or running a function
### Features

View File

@ -1 +1 @@
__version__ = "0.5.0" # pragma: no cover
__version__ = "0.5.1-dev1" # pragma: no cover

View File

@ -125,7 +125,7 @@ class GitHubIngestDoc(BaseIngestDoc):
print(f"Wrote {output_filename}")
@requires_dependencies(["pygithub"], extras="github")
@requires_dependencies(["github"], extras="github")
class GitHubConnector(BaseConnector):
def __init__(self, config: SimpleGitHubConfig):
from github import Github

View File

@ -14,7 +14,10 @@ def read_from_jsonl(filename: str) -> List[Dict]:
return [json.loads(line) for line in input_file]
def requires_dependencies(dependencies: Union[str, List[str]], extras: Optional[str] = None):
def requires_dependencies(
dependencies: Union[str, List[str]],
extras: Optional[str] = None,
):
if isinstance(dependencies, str):
dependencies = [dependencies]
@ -29,10 +32,12 @@ def requires_dependencies(dependencies: Union[str, List[str]], extras: Optional[
missing_deps.append(dep)
if len(missing_deps) > 0:
raise ImportError(
f"Following dependencies are missing: {', '.join(missing_deps)}."
+ f"Please install them using `pip install unstructured[{extras}]`."
if extras
else f"Please install them using `pip install {' '.join(missing_deps)}`.",
f"Following dependencies are missing: {', '.join(missing_deps)}. "
+ (
f"Please install them using `pip install unstructured[{extras}]`."
if extras
else f"Please install them using `pip install {' '.join(missing_deps)}`."
),
)
return func(*args, **kwargs)