Copilot commented on code in PR #1958:
URL: https://github.com/apache/nifi-minifi-cpp/pull/1958#discussion_r2030790767


##########
extensions/python/pythonlibloader/PythonLibLoader.cpp:
##########
@@ -37,8 +37,13 @@ class PythonLibLoader {
     if (auto python_binary = 
config->get(minifi::Configure::nifi_python_env_setup_binary)) {
       python_command = python_binary.value();
     }
+#if defined(__APPLE__)
+    std::string command = python_command +
+      R"###( -c "import sysconfig, os, glob; v = sysconfig.get_config_vars(); 
lib_dir = v['LIBDIR']; so_paths = glob.glob(f'{lib_dir}/*.dylib'); 
print(list(filter(os.path.exists, so_paths))[0])")###";
+#else
     std::string command = python_command +
       R"###( -c "import sysconfig, os, glob; v = sysconfig.get_config_vars(); 
lib_dir = v['LIBDIR']; ld_lib = v['LDLIBRARY']; so_paths = 
glob.glob(f'{lib_dir}/*{ld_lib}*'); 
so_paths.extend(glob.glob(f'{lib_dir}/*/*{ld_lib}*')); 
print(list(filter(os.path.exists, so_paths))[0])")###";

Review Comment:
   Consider checking that the filtered list is non-empty before accessing index 
0 to prevent potential runtime errors if no dynamic libraries are found.
   ```suggestion
         R"###( -c "import sysconfig, os, glob; v = 
sysconfig.get_config_vars(); lib_dir = v['LIBDIR']; so_paths = 
list(filter(os.path.exists, glob.glob(f'{lib_dir}/*.dylib'))); 
print(so_paths[0] if so_paths else '')")###";
   #else
       std::string command = python_command +
         R"###( -c "import sysconfig, os, glob; v = 
sysconfig.get_config_vars(); lib_dir = v['LIBDIR']; ld_lib = v['LDLIBRARY']; 
so_paths = list(filter(os.path.exists, glob.glob(f'{lib_dir}/*{ld_lib}*'))); 
so_paths.extend(glob.glob(f'{lib_dir}/*/*{ld_lib}*')); print(so_paths[0] if 
so_paths else '')")###";
   ```



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to