Repository: numba/numba

Issue:
get_numba_envvar doesn't seem to return the right value
If the env var value is found, Instead of returning the value, the function returns the default value.

https://github.com/numba/numba/blob/42050e4a306e53f332fbaecf45248c54fae752e5/numba/cuda/envvars.py#L32



Discussion:

Patch:
diff --git a/numba/cuda/envvars.py b/numba/cuda/envvars.py
index dfe29759e..57a806732 100644
--- a/numba/cuda/envvars.py
+++ b/numba/cuda/envvars.py
@@ -29,4 +29,4 @@ def get_numba_envvar(envvar, default=None):
     if value is None:
         return get_numbapro_envvar('NUMBAPRO_' + envvar, default=default)
     else:
-        return default
+        return value


Test patch:
diff --git a/numba/cuda/tests/nocuda/test_library_lookup.py b/numba/cuda/tests/nocuda/test_library_lookup.py
index 6f7881d9c..697c6f3d7 100644
--- a/numba/cuda/tests/nocuda/test_library_lookup.py
+++ b/numba/cuda/tests/nocuda/test_library_lookup.py
@@ -18,6 +18,8 @@ from numba.cuda.cuda_paths import (
     _get_cudalib_dir_path_decision,
     get_system_ctk,
 )
+from numba.cuda import envvars
+from numba.tests.support import override_env_config
 
 
 has_cuda = nvvm.is_available()
@@ -282,3 +284,28 @@ def _fake_non_conda_env():
     Monkeypatch sys.prefix to hide the fact we are in a conda-env
     """
     sys.prefix = ''
+
+
+class TestMisc(SerialMixin, unittest.TestCase):
+    """Test basic envvars lookup related functions
+    """
+    def test_get_numba_envvar(self):
+        # Make up an env-var that is not already defined.
+        # This makes a string with the following regex pattern "NUMBA_0+"
+        env = "0"
+        while f"NUMBA_{env}" in os.environ:
+            env += "0"
+        default = "the default"
+
+        # Check that we are getting the default
+        got = envvars.get_numba_envvar(env, default=default)
+        self.assertIs(got, default)
+
+        # Check that we are reading the env-var correctly
+        with override_env_config(f"NUMBA_{env}", "my value"):
+            got = envvars.get_numba_envvar(env, default=default)
+            self.assertEqual(got, "my value")
+
+
+if __name__ == '__main__':
+    unittest.main()