szaszm commented on code in PR #1681: URL: https://github.com/apache/nifi-minifi-cpp/pull/1681#discussion_r1522706091
########## bootstrap/package_manager.py: ########## @@ -0,0 +1,325 @@ +# 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. +import glob +import os +import platform +import subprocess +import sys +import re +from typing import Dict, Set + +from distro import distro + + +def _query_yes_no(question: str, no_confirm: bool) -> bool: + valid = {"yes": True, "y": True, "ye": True, "no": False, "n": False} + + if no_confirm: + print("Running {} with noconfirm".format(question)) + return True + while True: + print("{} [y/n]".format(question)) + choice = input().lower() + if choice in valid: + return valid[choice] + else: + print("Please respond with 'yes' or 'no' " "(or 'y' or 'n').") + + +def _run_command_with_confirm(command: str, no_confirm: bool) -> bool: + if _query_yes_no("Running {}".format(command), no_confirm): + return os.system(command) == 0 + + +class PackageManager(object): + def __init__(self, no_confirm): + self.no_confirm = no_confirm + pass + + def install(self, dependencies: Dict[str, Set[str]]) -> bool: + raise Exception("NotImplementedException") + + def install_compiler(self) -> str: + raise Exception("NotImplementedException") + + def _install(self, dependencies: Dict[str, Set[str]], replace_dict: Dict[str, Set[str]], install_cmd: str) -> bool: + dependencies.update({k: v for k, v in replace_dict.items() if k in dependencies}) + dependencies = self._filter_out_installed_packages(dependencies) + dependencies_str = " ".join(str(value) for value_set in dependencies.values() for value in value_set) + if not dependencies_str or dependencies_str.isspace(): + return True + return _run_command_with_confirm(f"{install_cmd} {dependencies_str}", self.no_confirm) + + def _get_installed_packages(self) -> Set[str]: + raise Exception("NotImplementedException") + + def _filter_out_installed_packages(self, dependencies: Dict[str, Set[str]]): + installed_packages = self._get_installed_packages() + filtered_packages = {k: (v - installed_packages) for k, v in dependencies.items()} + for installed_package in installed_packages: + filtered_packages.pop(installed_package, None) + return filtered_packages + + def run_cmd(self, cmd: str) -> bool: + result = subprocess.run(f"{cmd}", shell=True, text=True) + return result.returncode == 0 + + +class BrewPackageManager(PackageManager): + def __init__(self, no_confirm): + PackageManager.__init__(self, no_confirm) + + def install(self, dependencies: Dict[str, Set[str]]) -> bool: + return self._install(dependencies=dependencies, + install_cmd="brew install", + replace_dict={"patch": set(), + "jni": {"maven"}}) + + def install_compiler(self) -> str: + self.install({"compiler": {"llvm"}}) + return "" Review Comment: I checked last week, and it was working as well as without the new python bootstrap. (Which still doesn't build on my mac, but that's not your fault.) -- 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: issues-unsubscr...@nifi.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org