lordgamez commented on code in PR #1721:
URL: https://github.com/apache/nifi-minifi-cpp/pull/1721#discussion_r1559539605


##########
extensions/python/PythonDependencyInstaller.cpp:
##########
@@ -0,0 +1,166 @@
+/**
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+#include "PythonDependencyInstaller.h"
+
+#include "PythonScriptException.h"
+#include "PythonInterpreter.h"
+#include "PyException.h"
+#include "types/Types.h"
+
+namespace org::apache::nifi::minifi::extensions::python {
+
+namespace {
+
+std::string getPythonBinary(const std::shared_ptr<Configure> &configuration) {
+#if WIN32
+  std::string python_binary_ = "python";
+#else
+  std::string python_binary_ = "python3";
+#endif
+  if (auto binary = 
configuration->get(minifi::Configuration::nifi_python_env_setup_binary)) {
+    python_binary_ = *binary;
+  }
+  return python_binary_;
+}
+
+// On Windows when calling a system command using std::system, the whole 
command needs to be encapsulated in additional quotes,
+// due to the std::system passing the command to 'cmd.exe /C' which needs the 
additional quotes to handle the command as a single argument
+std::string encapsulateCommandInQuotesIfNeeded(const std::string& command) {
+#if WIN32
+    return "\"" + command + "\"";
+#else
+    return command;
+#endif
+}
+
+}  // namespace
+
+PythonDependencyInstaller::PythonDependencyInstaller(const 
std::shared_ptr<Configure> &configuration) {
+  python_binary_ = getPythonBinary(configuration);
+  std::string automatic_install_str;
+  install_python_packages_automatically_ =
+    
configuration->get(Configuration::nifi_python_install_packages_automatically, 
automatic_install_str) && 
utils::string::toBool(automatic_install_str).value_or(false);
+  if (auto path = 
configuration->get(minifi::Configuration::nifi_python_virtualenv_directory)) {
+    virtualenv_path_ = *path;
+    logger_->log_debug("Python virtualenv path was specified at: {}", 
virtualenv_path_.string());
+  } else {
+    logger_->log_debug("No valid python virtualenv path was specified");
+  }
+  if (auto python_processor_dir = 
configuration->get(minifi::Configuration::nifi_python_processor_dir)) {
+    python_processor_dir_ = *python_processor_dir;
+    logger_->log_debug("Python processor dir was specified at: {}", 
python_processor_dir_.string());
+  } else {
+    logger_->log_debug("No valid python processor dir was not specified in 
properties");
+  }
+  createVirtualEnvIfSpecified();
+  addVirtualenvToPath();
+}
+
+std::vector<std::filesystem::path> 
PythonDependencyInstaller::getRequirementsFilePaths() const {
+  if (!std::filesystem::exists(python_processor_dir_)) {
+    return {};
+  }
+  std::vector<std::filesystem::path> paths;
+  for (const auto& entry : 
std::filesystem::recursive_directory_iterator(std::filesystem::path{python_processor_dir_}))
 {
+    if (std::filesystem::is_regular_file(entry.path()) && 
entry.path().filename() == "requirements.txt") {
+      paths.push_back(entry.path());
+    }
+  }
+  return paths;
+}
+
+void PythonDependencyInstaller::createVirtualEnvIfSpecified() const {
+  if (virtualenv_path_.empty()) {

Review Comment:
   Sounds good, added warning in 33e8770038e823678763c9bef60cc656c07ba16b



-- 
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