From d27d17c4daac606b141d781cbd152a7e55018f79 Mon Sep 17 00:00:00 2001 From: ademhilmibozkurt Date: Wed, 11 Dec 2024 16:26:31 +0300 Subject: [PATCH 1/6] homebrew.py added, homebrew functions seperated with setup.py --- homebrew.py | 163 ++++++++++++++++++++++++++++++++++++++++++++++++++++ setup.py | 71 +---------------------- 2 files changed, 165 insertions(+), 69 deletions(-) create mode 100644 homebrew.py diff --git a/homebrew.py b/homebrew.py new file mode 100644 index 00000000..517cf70a --- /dev/null +++ b/homebrew.py @@ -0,0 +1,163 @@ +from re import search +from sys import platform +from subprocess import check_output, CalledProcessError + +class HomeBrew: + def __init__(self, libdirs: list[str], incdirs: list[str], openssl_ver: str): + self._libdirs = libdirs + self._incdirs = incdirs + self._openssl_ver = openssl_ver + + def check_brew_isinstalled(self): + # Check if brew is installed via: `brew --version` it should return something like: `Homebrew 4.4.5` + try: + homebrew_version = check_output("brew --version", shell=True).decode() + if search(r"Homebrew (\d+\.\d+\.\d+)", homebrew_version): + pass + + except CalledProcessError: + print("Homebrew isn't installed...") + pass + + def check_netsnmp_isinstalled(self) -> None: + # 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] + self._incdirs.append(include_dir[: include_dir.index("include/net-snmp") + 7]) + + except CalledProcessError: + print("net-snmp isn't installed via HomeBrew...") + pass + + def get_homebrew_net_snmp_info(self): + try: + brew = check_output("brew info net-snmp", shell=True).decode() # this may cause error + self._openssl_ver = self.get_openssl_ver(brew) + except CalledProcessError: + print("A brew command failed...") + pass + + # no need try-except. check_output may throw CalledProcessError + def brew_platform_info(self) -> None: + if platform == "darwin": + lib_dir = list(filter(lambda l: "lib/libnetsnmp.dylib" in l, lines))[0] + self._libdirs.append(lib_dir[: lib_dir.index("lib/libnetsnmp.dylib") + 3]) + + def get_openssl_ver(self, brew) -> list: + # The homebrew version also depends on the Openssl keg + openssl_ver = list( + filter( + lambda o: "openssl" in o, + *map( + str.split, + filter( + lambda l: "openssl" in l, + str(brew.replace("'", "")).split("\n"), + ), + ), + ) + )[0] + + return openssl_ver + + def append_openssl_paths(self) -> None: + try: + 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() + + self._libdirs.append(temp_path + "/lib") + self._incdirs.append(temp_path + "/include") + + except CalledProcessError: + print("A brew command failed...") + pass + +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 + +except CalledProcessError: + print("Homebrew isn't installed...") + pass + diff --git a/setup.py b/setup.py index ab46bf56..e454fb4b 100644 --- a/setup.py +++ b/setup.py @@ -9,7 +9,7 @@ from setuptools.command.build_ext import build_ext as BuildCommand import setuptools.command.build as build from setuptools import dist -from re import search +# from re import search # Determine if a base directory has been provided with the --basedir option basedir = None @@ -71,73 +71,6 @@ print(f"libdirs: {libdirs}") print(f"incdirs: {incdirs}") - 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 - - 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}") @@ -197,7 +130,7 @@ def run(self): shell=True, ) - +# this lines must stay for setup setup( ext_modules=[ Extension( From 7d0673e99f7b9f28527c27f24777037df7722c25 Mon Sep 17 00:00:00 2001 From: ademhilmibozkurt Date: Wed, 11 Dec 2024 20:22:38 +0300 Subject: [PATCH 2/6] homebrew.py was optimized, __init__.py added, homebrew added to setup.py --- __init__.py | 0 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 __init__.py diff --git a/__init__.py b/__init__.py new file mode 100644 index 00000000..e69de29b From 8829e5589f4cce40bb950fc79f4cfe69e6e58057 Mon Sep 17 00:00:00 2001 From: ademhilmibozkurt Date: Thu, 12 Dec 2024 07:36:11 +0300 Subject: [PATCH 3/6] homebrew.py added, homebrew functions seperated with setup.py --- homebrew.py | 135 +++++++++++++++------------------------------------- setup.py | 13 +++-- 2 files changed, 49 insertions(+), 99 deletions(-) diff --git a/homebrew.py b/homebrew.py index 517cf70a..6e977993 100644 --- a/homebrew.py +++ b/homebrew.py @@ -3,50 +3,61 @@ from subprocess import check_output, CalledProcessError class HomeBrew: - def __init__(self, libdirs: list[str], incdirs: list[str], openssl_ver: str): + def __init__(self, libdirs: list[str], incdirs: list[str]): self._libdirs = libdirs self._incdirs = incdirs - self._openssl_ver = openssl_ver def check_brew_isinstalled(self): # Check if brew is installed via: `brew --version` it should return something like: `Homebrew 4.4.5` try: homebrew_version = check_output("brew --version", shell=True).decode() - if search(r"Homebrew (\d+\.\d+\.\d+)", homebrew_version): - pass - + except CalledProcessError: print("Homebrew isn't installed...") pass - def check_netsnmp_isinstalled(self) -> None: + else: + if search(r"Homebrew (\d+\.\d+\.\d+)", homebrew_version): + lines: list[str] = self.check_netsnmp_isinstalled(self) + self.add_homebrew_platform_info(self, lines) + self.get_homebrew_net_snmp_info(self) + + def check_netsnmp_isinstalled(self) -> list[str]: # 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] - self._incdirs.append(include_dir[: include_dir.index("include/net-snmp") + 7]) + brew = check_output("brew list net-snmp 2>/dev/null", shell=True).decode() except CalledProcessError: print("net-snmp isn't installed via HomeBrew...") pass + else: + lines = brew.splitlines() + include_dir = list(filter(lambda l: "include/net-snmp" in l, lines))[0] + self._incdirs.append(include_dir[: include_dir.index("include/net-snmp") + 7]) + + self.get_lines(lines) + return lines + + def get_lines(self, lines): + return lines + + # no need try-except. check_output may throw CalledProcessError + def add_homebrew_platform_info(self, lines: list[str]) -> None: + if platform == "darwin": + lib_dir = list(filter(lambda l: "lib/libnetsnmp.dylib" in l, lines))[0] + self._libdirs.append(lib_dir[: lib_dir.index("lib/libnetsnmp.dylib") + 3]) + def get_homebrew_net_snmp_info(self): + # The homebrew version also depends on the Openssl keg try: brew = check_output("brew info net-snmp", shell=True).decode() # this may cause error - self._openssl_ver = self.get_openssl_ver(brew) + openssl_ver = self.get_openssl_ver(self, brew) + self.append_openssl_paths(self, openssl_ver) except CalledProcessError: print("A brew command failed...") pass - # no need try-except. check_output may throw CalledProcessError - def brew_platform_info(self) -> None: - if platform == "darwin": - lib_dir = list(filter(lambda l: "lib/libnetsnmp.dylib" in l, lines))[0] - self._libdirs.append(lib_dir[: lib_dir.index("lib/libnetsnmp.dylib") + 3]) - def get_openssl_ver(self, brew) -> list: # The homebrew version also depends on the Openssl keg openssl_ver = list( @@ -64,74 +75,15 @@ def get_openssl_ver(self, brew) -> list: return openssl_ver - def append_openssl_paths(self) -> None: + def append_openssl_paths(self, openssl_ver) -> None: try: - 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() - - self._libdirs.append(temp_path + "/lib") - self._incdirs.append(temp_path + "/include") + brew = check_output("brew info {0}".format(openssl_ver), shell=True).decode() except CalledProcessError: print("A brew command failed...") pass -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") + else: # 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) @@ -143,21 +95,12 @@ def append_openssl_paths(self) -> None: # From: https://github.com/Homebrew/homebrew-core/blob/HEAD/Formula/o/openssl@3.rb # License: Apache-2.0 # ... - # print(temp) + temp = brew.split("\n") 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 + self._libdirs.append(temp_path + "/lib") + self._incdirs.append(temp_path + "/include") + print(f"libdirs: {self._libdirs}") + print(f"incdirs: {self._incdirs}") + print(f"openssl_ver: {openssl_ver}") \ No newline at end of file diff --git a/setup.py b/setup.py index e454fb4b..77d38659 100644 --- a/setup.py +++ b/setup.py @@ -9,7 +9,7 @@ from setuptools.command.build_ext import build_ext as BuildCommand import setuptools.command.build as build from setuptools import dist -# from re import search +from homebrew import HomeBrew # Determine if a base directory has been provided with the --basedir option basedir = None @@ -71,6 +71,9 @@ print(f"libdirs: {libdirs}") print(f"incdirs: {incdirs}") + hb = HomeBrew(libdirs=libdirs, incdirs=incdirs) + hb.check_brew_isinstalled() + print(f"in_tree: {in_tree}") print(f"compile_args: {compile_args}") print(f"link_args: {link_args}") @@ -89,6 +92,9 @@ class RelinkLibraries(BuildCommand): Non-brew installations and non-macOS systems will not be affected. """ + def __init__(): + pass + def run(self): BuildCommand.run(self) if platform == "darwin": # Newer Net-SNMP dylib may not be linked to properly @@ -98,6 +104,8 @@ def run(self): ).decode() except CalledProcessError: return + + lines = hb.get_lines() lib_dir = list(filter(lambda l: "lib/libnetsnmp.dylib" in l, lines))[0] b = build.build(dist.Distribution()) # Dynamically determine build path b.finalize_options() @@ -130,7 +138,6 @@ def run(self): shell=True, ) -# this lines must stay for setup setup( ext_modules=[ Extension( @@ -187,4 +194,4 @@ def run(self): extra_link_args=link_args, ), ], -) +) \ No newline at end of file From a11d9cf1d92cf30c2b9703c0b667f9c297c48319 Mon Sep 17 00:00:00 2001 From: ademhilmibozkurt Date: Sun, 15 Dec 2024 11:24:22 +0300 Subject: [PATCH 4/6] files black formatted, properties added --- homebrew.py | 64 +++++++++++++++++++++++++++++++++-------------------- setup.py | 10 +++++---- 2 files changed, 46 insertions(+), 28 deletions(-) diff --git a/homebrew.py b/homebrew.py index 6e977993..eba83c24 100644 --- a/homebrew.py +++ b/homebrew.py @@ -2,27 +2,37 @@ from sys import platform from subprocess import check_output, CalledProcessError + class HomeBrew: - def __init__(self, libdirs: list[str], incdirs: list[str]): - self._libdirs = libdirs - self._incdirs = incdirs - - def check_brew_isinstalled(self): + def __init__(self): + self._libdirs = self.libdirs + self._incdirs = self.incdirs + self._check_brew_isinstalled() + + @property + def libdirs(self): + return self._libdirs + + @property + def incdirs(self): + return self._incdirs + + def _check_brew_isinstalled(self): # Check if brew is installed via: `brew --version` it should return something like: `Homebrew 4.4.5` try: homebrew_version = check_output("brew --version", shell=True).decode() - + except CalledProcessError: print("Homebrew isn't installed...") pass else: if search(r"Homebrew (\d+\.\d+\.\d+)", homebrew_version): - lines: list[str] = self.check_netsnmp_isinstalled(self) - self.add_homebrew_platform_info(self, lines) - self.get_homebrew_net_snmp_info(self) + lines: list[str] = self._check_netsnmp_isinstalled(self) + self._add_homebrew_platform_info(self, lines) + self._get_homebrew_net_snmp_info(self) - def check_netsnmp_isinstalled(self) -> list[str]: + def _check_netsnmp_isinstalled(self) -> list[str]: # Check if net-snmp is installed via Brew try: brew = check_output("brew list net-snmp 2>/dev/null", shell=True).decode() @@ -34,31 +44,35 @@ def check_netsnmp_isinstalled(self) -> list[str]: else: lines = brew.splitlines() include_dir = list(filter(lambda l: "include/net-snmp" in l, lines))[0] - self._incdirs.append(include_dir[: include_dir.index("include/net-snmp") + 7]) - + self._incdirs.append( + include_dir[: include_dir.index("include/net-snmp") + 7] + ) + self.get_lines(lines) return lines def get_lines(self, lines): return lines - # no need try-except. check_output may throw CalledProcessError - def add_homebrew_platform_info(self, lines: list[str]) -> None: + # no need try-except. check_output may throw CalledProcessError + def _add_homebrew_platform_info(self, lines: list[str]) -> None: if platform == "darwin": lib_dir = list(filter(lambda l: "lib/libnetsnmp.dylib" in l, lines))[0] self._libdirs.append(lib_dir[: lib_dir.index("lib/libnetsnmp.dylib") + 3]) - def get_homebrew_net_snmp_info(self): + def _get_homebrew_net_snmp_info(self): # The homebrew version also depends on the Openssl keg try: - brew = check_output("brew info net-snmp", shell=True).decode() # this may cause error - openssl_ver = self.get_openssl_ver(self, brew) - self.append_openssl_paths(self, openssl_ver) + brew = check_output( + "brew info net-snmp", shell=True + ).decode() # this may cause error + openssl_ver = self._get_openssl_ver(self, brew) + self._append_openssl_paths(self, openssl_ver) except CalledProcessError: print("A brew command failed...") pass - def get_openssl_ver(self, brew) -> list: + def _get_openssl_ver(self, brew) -> list: # The homebrew version also depends on the Openssl keg openssl_ver = list( filter( @@ -72,12 +86,14 @@ def get_openssl_ver(self, brew) -> list: ), ) )[0] - + return openssl_ver - - def append_openssl_paths(self, openssl_ver) -> None: + + def _append_openssl_paths(self, openssl_ver) -> None: try: - brew = check_output("brew info {0}".format(openssl_ver), shell=True).decode() + brew = check_output( + "brew info {0}".format(openssl_ver), shell=True + ).decode() except CalledProcessError: print("A brew command failed...") @@ -103,4 +119,4 @@ def append_openssl_paths(self, openssl_ver) -> None: print(f"libdirs: {self._libdirs}") print(f"incdirs: {self._incdirs}") - print(f"openssl_ver: {openssl_ver}") \ No newline at end of file + print(f"openssl_ver: {openssl_ver}") diff --git a/setup.py b/setup.py index 77d38659..740fa26e 100644 --- a/setup.py +++ b/setup.py @@ -71,8 +71,9 @@ print(f"libdirs: {libdirs}") print(f"incdirs: {incdirs}") - hb = HomeBrew(libdirs=libdirs, incdirs=incdirs) - hb.check_brew_isinstalled() + hb = HomeBrew() + hb.libdirs = libdirs + hb.incdirs = incdirs print(f"in_tree: {in_tree}") print(f"compile_args: {compile_args}") @@ -104,7 +105,7 @@ def run(self): ).decode() except CalledProcessError: return - + lines = hb.get_lines() lib_dir = list(filter(lambda l: "lib/libnetsnmp.dylib" in l, lines))[0] b = build.build(dist.Distribution()) # Dynamically determine build path @@ -138,6 +139,7 @@ def run(self): shell=True, ) + setup( ext_modules=[ Extension( @@ -194,4 +196,4 @@ def run(self): extra_link_args=link_args, ), ], -) \ No newline at end of file +) From fdc84855ddad845043c9ebeeb824bc7ce88fc03b Mon Sep 17 00:00:00 2001 From: ademhilmibozkurt Date: Mon, 16 Dec 2024 10:28:55 +0300 Subject: [PATCH 5/6] properties added, if block added --- homebrew.py | 18 +++++++++++++++++- setup.py | 20 ++++++++++++-------- 2 files changed, 29 insertions(+), 9 deletions(-) diff --git a/homebrew.py b/homebrew.py index eba83c24..0b5b3ca9 100644 --- a/homebrew.py +++ b/homebrew.py @@ -17,11 +17,23 @@ def libdirs(self): def incdirs(self): return self._incdirs + @property + def homebrew_version(self): + return self._homebrew_version + + @property + def homebrew_netsnmp_version(self): + return self._netsnmp_version + + @property + def homebrew_openssl_version(self): + return self._openssl_version + def _check_brew_isinstalled(self): # Check if brew is installed via: `brew --version` it should return something like: `Homebrew 4.4.5` try: homebrew_version = check_output("brew --version", shell=True).decode() - + self._homebrew_version = homebrew_version except CalledProcessError: print("Homebrew isn't installed...") pass @@ -66,8 +78,11 @@ def _get_homebrew_net_snmp_info(self): brew = check_output( "brew info net-snmp", shell=True ).decode() # this may cause error + + self._netsnmp_version = brew openssl_ver = self._get_openssl_ver(self, brew) self._append_openssl_paths(self, openssl_ver) + except CalledProcessError: print("A brew command failed...") pass @@ -86,6 +101,7 @@ def _get_openssl_ver(self, brew) -> list: ), ) )[0] + self._openssl_version = openssl_ver return openssl_ver diff --git a/setup.py b/setup.py index 740fa26e..5b3fe8e9 100644 --- a/setup.py +++ b/setup.py @@ -67,20 +67,24 @@ libdirs = [flag[2:] for flag in s_split(netsnmp_libs) if flag[:2] == "-L"] incdirs = ["ezsnmp/include/"] - print(f"libs: {libs}") - print(f"libdirs: {libdirs}") - print(f"incdirs: {incdirs}") - hb = HomeBrew() - hb.libdirs = libdirs - hb.incdirs = incdirs + if hb.libdirs and hb.incdirs: + libdirs = hb.libdirs + incdirs = hb.incdirs + homebrew_version = hb.homebrew_version + homebrew_netsnmp_version = hb.homebrew_netsnmp_version + homebrew_openssl_version = hb.homebrew_openssl_version 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}") +print(f"homebrew_version: {str(homebrew_version).strip()}") +print(f"homebrew_netsnmp_version: {homebrew_netsnmp_version}") +print(f"homebrew_openssl_version: {homebrew_openssl_version}") +print(f"libs: {libs}") +print(f"libdirs: {libdirs}") +print(f"incdirs: {incdirs}") class RelinkLibraries(BuildCommand): From d4fffedbb495408fda214d8be4514bab8c16b8fa Mon Sep 17 00:00:00 2001 From: ademhilmibozkurt Date: Tue, 17 Dec 2024 10:07:21 +0300 Subject: [PATCH 6/6] properties set None --- homebrew.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/homebrew.py b/homebrew.py index 0b5b3ca9..4f1606a2 100644 --- a/homebrew.py +++ b/homebrew.py @@ -5,8 +5,8 @@ class HomeBrew: def __init__(self): - self._libdirs = self.libdirs - self._incdirs = self.incdirs + self._libdirs = None + self._incdirs = None self._check_brew_isinstalled() @property