You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
There is a need for refactoring some setup.py code into functions.
This will make it easier to maintain.
Below is an example of functions that can be made to move out the Homebrew logic to functions.
defget_homebrew_info():
""" Checks if Homebrew is installed and retrieves its version. Returns: tuple: A tuple containing (Homebrew version) or None if Homebrew is not installed. """try:
homebrew_version_output=check_output("brew --version", shell=True).decode()
match=search(r"Homebrew (\d+\.\d+\.\d+)", homebrew_version_output)
ifmatch:
returnmatch.group(1)
else:
returnNoneexceptCalledProcessError:
returnNonedefget_homebrew_net_snmp_info():
""" Retrieves net-snmp and its OpenSSL dependency information from Homebrew. Returns: tuple: A tuple containing (homebrew_version, net_snmp_version, openssl_version, libdirs, incdirs) or None if net-snmp is not installed via Homebrew. Or None if Homebrew is not installed. """homebrew_version=get_homebrew_info()
ifnothomebrew_version:
returnNonetry:
brew_output=check_output("brew list net-snmp", shell=True).decode()
lines=brew_output.splitlines()
# Extract net-snmp versionpattern=r"/opt/homebrew/Cellar/net-snmp/(\d+\.\d+\.\d+)/"match=search(pattern, lines[0])
ifnotmatch:
returnNonenet_snmp_version=match.group(1)
# Get include directoryinclude_dir=next((lforlinlinesif"include/net-snmp"inl), None)
ifnotinclude_dir:
returnNoneincdirs= [include_dir[: include_dir.index("include/net-snmp") +7]]
# Get library directory (macOS specific)libdirs= []
ifplatform.system() =="Darwin":
lib_dir=next((lforlinlinesif"lib/libnetsnmp.dylib"inl), None)
ifnotlib_dir:
returnNonelibdirs.append(lib_dir[: lib_dir.index("lib/libnetsnmp.dylib") +3])
# Get OpenSSL dependency informationbrew_info_output=check_output("brew info net-snmp", shell=True).decode()
openssl_version=next(
(
line.split()[0]
forlineinbrew_info_output.splitlines()
if"/openssl@3/"inline
),
None,
)
ifnotopenssl_version:
returnNoneopenssl_info_output=check_output(
f"brew info {openssl_version}", shell=True
).decode()
openssl_path=openssl_info_output.splitlines()[4].split("(")[0].strip()
libdirs.append(openssl_path+"/lib")
incdirs.append(openssl_path+"/include")
returnhomebrew_version, net_snmp_version, openssl_version, libdirs, incdirsexceptCalledProcessError:
returnNone
The text was updated successfully, but these errors were encountered:
There is a need for refactoring some setup.py code into functions.
This will make it easier to maintain.
Below is an example of functions that can be made to move out the Homebrew logic to functions.
The text was updated successfully, but these errors were encountered: