Skip to content

Commit

Permalink
Fixed bug
Browse files Browse the repository at this point in the history
  • Loading branch information
Pringled committed Oct 31, 2024
1 parent 2f800d8 commit e0d3ef7
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 9 deletions.
18 changes: 10 additions & 8 deletions model2vec/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,17 +26,19 @@ def get_tensor(self, key: str) -> np.ndarray:

def get_package_extras(package: str, extra: str) -> Iterator[str]:
"""Get the extras of the package."""
message = metadata(package)
try:
message = metadata(package)
except Exception as e:
raise ImportError(f"Could not retrieve metadata for package '{package}': {e}")

Check warning on line 32 in model2vec/utils.py

View check run for this annotation

Codecov / codecov/patch

model2vec/utils.py#L31-L32

Added lines #L31 - L32 were not covered by tests

all_packages = message.get_all("Requires-Dist") or []
for package in all_packages:
name, *rest = package.split(";", maxsplit=1)
if not rest:
continue
_, found_extra = rest[0].split("==", maxsplit=1)
# Strip off quotes
found_extra = found_extra.strip(' "')
if found_extra == extra:
yield name
if rest:
# Extract and clean the extra requirement
found_extra = rest[0].split("==")[-1].strip(" \"'")
if found_extra == extra:
yield name.strip()


def importable(module: str, extra: str) -> None:
Expand Down
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ dependencies = [
"rich",
"tqdm",
"tokenizers>=0.20",
"safetensors",
"setuptools",
]

Expand Down
4 changes: 3 additions & 1 deletion uv.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit e0d3ef7

Please sign in to comment.