diff --git a/setup.py b/setup.py index b86923d4..3881bbe7 100644 --- a/setup.py +++ b/setup.py @@ -17,6 +17,7 @@ compile_args = ["-std=c++17", "-Werror", "-Wno-unguarded-availability-new"] link_args = [] netsnmp_version = check_output("net-snmp-config --version", shell=True).decode() +homebrew_version = None for arg in argv: if arg.startswith("--debug"): @@ -70,69 +71,75 @@ print(f"libdirs: {libdirs}") print(f"incdirs: {incdirs}") - # Check if brew is installed via: `brew --version` it should return something like: `Homebrew 4.4.5` - homebrew_version = check_output("brew --version", shell=True).decode() - if search(r"Homebrew (\d+\.\d+\.\d+)", homebrew_version): - # Check if net-snmp is installed via Brew - try: - brew = check_output("brew list net-snmp 2>/dev/null", shell=True).decode() - lines = brew.splitlines() - include_dir = list(filter(lambda l: "include/net-snmp" in l, lines))[0] - incdirs.append(include_dir[: include_dir.index("include/net-snmp") + 7]) - - if platform == "darwin": - lib_dir = list(filter(lambda l: "lib/libnetsnmp.dylib" in l, lines))[0] - libdirs.append(lib_dir[: lib_dir.index("lib/libnetsnmp.dylib") + 3]) - - # The homebrew version also depends on the Openssl keg - brew = check_output("brew info net-snmp", shell=True).decode() - openssl_ver = list( - filter( - lambda o: "openssl" in o, - *map( - str.split, - filter( - lambda l: "openssl" in l, - str(brew.replace("'", "")).split("\n"), + try: + # Check if brew is installed via: `brew --version` it should return something like: `Homebrew 4.4.5` + homebrew_version = check_output("brew --version", shell=True).decode() + if search(r"Homebrew (\d+\.\d+\.\d+)", homebrew_version): + # Check if net-snmp is installed via Brew + try: + brew = check_output("brew list net-snmp 2>/dev/null", shell=True).decode() + lines = brew.splitlines() + include_dir = list(filter(lambda l: "include/net-snmp" in l, lines))[0] + incdirs.append(include_dir[: include_dir.index("include/net-snmp") + 7]) + + if platform == "darwin": + lib_dir = list(filter(lambda l: "lib/libnetsnmp.dylib" in l, lines))[0] + libdirs.append(lib_dir[: lib_dir.index("lib/libnetsnmp.dylib") + 3]) + + # The homebrew version also depends on the Openssl keg + brew = check_output("brew info net-snmp", shell=True).decode() + openssl_ver = list( + filter( + lambda o: "openssl" in o, + *map( + str.split, + filter( + lambda l: "openssl" in l, + str(brew.replace("'", "")).split("\n"), + ), ), - ), - ) - )[0] - - brew = check_output( - "brew info {0}".format(openssl_ver), shell=True - ).decode() - temp = brew.split("\n") - # As of 06/04/2024 brew info openssl spits out lines. the fifth one is what we care about - # This works for now, but we need a better solution - # ==> openssl@3: stable 3.3.0 (bottled) - # Cryptography and SSL/TLS Toolkit - # https://openssl.org/ - # Installed - # /opt/homebrew/Cellar/openssl@3/3.3.0 (6,977 files, 32.4MB) * - # Poured from bottle using the formulae.brew.sh API on 2024-06-04 at 21:17:37 - # From: https://github.com/Homebrew/homebrew-core/blob/HEAD/Formula/o/openssl@3.rb - # License: Apache-2.0 - # ... - # print(temp) - temp_path = str(temp[4].split("(")[0]).strip() - - libdirs.append(temp_path + "/lib") - incdirs.append(temp_path + "/include") - - print(f"libdirs: {libdirs}") - print(f"incdirs: {incdirs}") - print(f"openssl_ver: {openssl_ver}") - - except CalledProcessError: - print("A brew command failed...") - pass + ) + )[0] + + brew = check_output( + "brew info {0}".format(openssl_ver), shell=True + ).decode() + temp = brew.split("\n") + # As of 06/04/2024 brew info openssl spits out lines. the fifth one is what we care about + # This works for now, but we need a better solution + # ==> openssl@3: stable 3.3.0 (bottled) + # Cryptography and SSL/TLS Toolkit + # https://openssl.org/ + # Installed + # /opt/homebrew/Cellar/openssl@3/3.3.0 (6,977 files, 32.4MB) * + # Poured from bottle using the formulae.brew.sh API on 2024-06-04 at 21:17:37 + # From: https://github.com/Homebrew/homebrew-core/blob/HEAD/Formula/o/openssl@3.rb + # License: Apache-2.0 + # ... + # print(temp) + temp_path = str(temp[4].split("(")[0]).strip() + + libdirs.append(temp_path + "/lib") + incdirs.append(temp_path + "/include") + + print(f"libdirs: {libdirs}") + print(f"incdirs: {incdirs}") + print(f"openssl_ver: {openssl_ver}") + + except CalledProcessError: + print("A brew command failed...") + pass + + except CalledProcessError: + print("Homebrew isn't installed...") + pass print(f"in_tree: {in_tree}") print(f"compile_args: {compile_args}") print(f"link_args: {link_args}") print(f"platform: {platform}") print(f"netsnmp_version: {netsnmp_version}") +print(f"homebrew_version: {homebrew_version}") class RelinkLibraries(BuildCommand):