QA: Fall back to the import name when a distribution is missing from the packages mapping
`_is_package_available` looks the import name up in `PACKAGE_DISTRIBUTION_MAPPING`, which is built
from `importlib.metadata.packages_distributions()`. That call can miss an installed distribution whose
dist-info carries no usable top-level record. The resulting `KeyError` was lumped in with
`PackageNotFoundError` and sent execution down the import fallback, which returns
`getattr(module, "__version__", "N/A")` -- so a perfectly installed package could be reported as
version `"N/A"`.
Callers then feed that sentinel straight to `packaging.version.parse`:
return is_available and version.parse(gguf_version) >= version.parse(min_version)
which raises `InvalidVersion`. In the quantization CI image this made
`tests/quantization/ggml/test_ggml.py` unable to even be *collected*, despite `pip freeze` reporting
`gguf==0.19.0`:
tests/quantization/ggml/test_ggml.py:40: in <module>
if is_gguf_available():
packaging.version.InvalidVersion: Invalid version: 'N/A'
Handle the `KeyError` on its own and fall back to the import name, which is the correct distribution
name for the large majority of packages, before giving up on metadata entirely. Around twenty
`is_*_available` helpers parse a version this way, so the fix belongs at this choke point rather than
in each of them.
Note that the `"N/A"` sentinel can still reach those helpers when a package has neither metadata nor
`__version__` (an editable install, say). Narrowing that is left out of this change.
See https://github.com/huggingface/transformers/actions/runs/32347015888