Skip to content

Commit 3d7659e

Browse files
tjstumfacebook-github-bot
authored andcommitted
Use packaging.version for correct version parsing (#4330)
Summary: If you use a version of numpy that has non-numeric components to the version number (e.g. a [local version identifier](https://peps.python.org/pep-0440/#local-version-identifiers)), `faiss` will not import because the hand-rolled version parsing expects only digits: ``` $ /venv/bin/python -c 'import numpy; print(numpy.__version__)' 2.0.2+hrt0 $ /venv/bin/python -c 'import faiss' Traceback (most recent call last): File "<string>", line 1, in <module> File "/venv/lib/python3.12/site-packages/faiss/__init__.py", line 17, in <module> from .loader import * File "/venv/lib/python3.12/site-packages/faiss/loader.py", line 91, in <module> instruction_sets = supported_instruction_sets() ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/venv/lib/python3.12/site-packages/faiss/loader.py", line 47, in supported_instruction_sets if Version(numpy.__version__) >= Version("1.19"): ^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/venv/lib/python3.12/site-packages/faiss/loader.py", line 13, in Version return [int(x) for x in v.split('.')] ^^^^^^ ValueError: invalid literal for int() with base 10: '2+hrt0' ``` This project depends on `packaging`, but the use was removed in #3807 (though the metadata wasn't). This restores the correct parsing of `Version`. If you'd prefer not to add this dependency, what is your suggestion for correctly parsing the numpy version (also, the `install_requires` line should be updated) Pull Request resolved: #4330 Reviewed By: mnorris11 Differential Revision: D74592146 Pulled By: junjieqi fbshipit-source-id: 258c5b499d356040ff6e373b2b635efa355c50ea
1 parent b0809a2 commit 3d7659e

File tree

1 file changed

+1
-2
lines changed

1 file changed

+1
-2
lines changed

faiss/python/loader.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,8 @@
88
import logging
99
import os
1010

11+
from packaging.version import Version
1112

12-
def Version(v):
13-
return [int(x) for x in v.split('.')]
1413

1514
def supported_instruction_sets():
1615
"""

0 commit comments

Comments
 (0)