Repository: numpy/numpy

Issue:
BUG: non-numeric kernel_version on the OVH platform
<!-- Please describe the issue in detail here, and fill in the fields below -->

<!-- A short code example that reproduces the problem/missing feature. It should be
self-contained, i.e., possible to run as-is via 'python myproblem.py' -->

Hello, there is an error in the code of __ini__.py (Python3.8) , when detecting the version of the Kernel.
I found the solution but I detail the problem here to help other users.

```python 
    # We usually use madvise hugepages support, but on some old kernels it
    # is slow and thus better avoided.
    # Specifically kernel version 4.6 had a bug fix which probably fixed this:
    # https://github.com/torvalds/linux/commit/7cf91a98e607c2f935dbcc177d70011e95b8faff
    import os
    use_hugepage = os.environ.get("NUMPY_MADVISE_HUGEPAGE", None)
    if sys.platform == "linux" and use_hugepage is None:
        use_hugepage = 1
        kernel_version = os.uname().release.split(".")[:2]
        kernel_version = tuple(int(v) for v in kernel_version)
        if kernel_version < (4, 6):
            use_hugepage = 0
    elif use_hugepage is None:
        # This is not Linux, so it should not matter, just enable anyway
        use_hugepage = 1
    else:
        use_hugepage = int(use_hugepage)

    # Note that this will currently only make a difference on Linux
    core.multiarray._set_madvise_hugepage(use_hugepage)
```


<!-- Remove these sections for a feature request -->

### Error message:

<!-- If you are reporting a segfault please include a GDB traceback, which you
can generate by following
https://github.com/numpy/numpy/blob/master/doc/source/dev/development_environment.rst#debugging -->
```
# usr\local\lib\python3.8\site-packages\numpy\__init__.py

 #python3.8 test.py
['4', '19-ovh-xxxx-std-ipv6-64']
Traceback (most recent call last):
  File "test.py", line 4, in <module>
    kernel_version = tuple(int(v) for v in kernel_version)
  File "test.py", line 4, in <genexpr>
    kernel_version = tuple(int(v) for v in kernel_version)
ValueError: invalid literal for int() with base 10: '19-ovh-xxxx-std-ipv6-64'
```
### Numpy/Python version information:

<!-- Output from 'import sys, numpy; print(numpy.__version__, sys.version)' -->


To fix this error, here is the solution:


```python
      kernel_version = tuple(int(v[0:2]) for v in kernel_version) 
 ```

The `int (v [0: 2] )` truncate the string to recover the INT correctly.


Discussion:
Hi,

I'm having the same issue with the kernel shipped with OVH.
I see you are making the pull request. Thanks !
Hmmm, my error, why didn't I use looseversion here?
Oh, looking again (sorry missing things a bit more today), that is a strange version string, dropping the micro-release. But, it seems that `LooseVersion` does handle it correctly, so I think we can just use that here.  Although I guess importing distutils may be slow, so maybe just add a `try:/except:` its not very important to begin with.
I couldnt find the pull request, @nejib1 do you happen to be working on it.
@anirudh2290 There isn't a PR, could you make one? There seem to be two fixes, one given in the report and @seberg use of `LooseVersion`.

Resolving patch:
diff --git a/numpy/__init__.py b/numpy/__init__.py
--- a/numpy/__init__.py
+++ b/numpy/__init__.py
@@ -293,11 +293,18 @@ def _mac_os_check():
     import os
     use_hugepage = os.environ.get("NUMPY_MADVISE_HUGEPAGE", None)
     if sys.platform == "linux" and use_hugepage is None:
-        use_hugepage = 1
-        kernel_version = os.uname().release.split(".")[:2]
-        kernel_version = tuple(int(v) for v in kernel_version)
-        if kernel_version < (4, 6):
-            use_hugepage = 0
+        # If there is an issue with parsing the kernel version,
+        # set use_hugepages to 0. Usage of LooseVersion will handle
+        # the kernel version parsing better, but avoided since it
+        # will increase the import time. See: #16679 for related discussion.
+        try:
+            use_hugepage = 1
+            kernel_version = os.uname().release.split(".")[:2]
+            kernel_version = tuple(int(v) for v in kernel_version)
+            if kernel_version < (4, 6):
+                use_hugepage = 0
+        except ValueError:
+            use_hugepages = 0
     elif use_hugepage is None:
         # This is not Linux, so it should not matter, just enable anyway
         use_hugepage = 1


Test patch: