Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Fixed package extras bug #120

Merged
merged 1 commit into from
Oct 31, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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_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.