Skip to content

[NFC] Apply ruff-format to import_load_lib pythonization test #19000

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 10, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
178 changes: 93 additions & 85 deletions bindings/pyroot/pythonizations/test/import_load_libs.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import unittest
import re
import os
import re
import unittest


class ImportLoadLibs(unittest.TestCase):
Expand All @@ -11,72 +11,72 @@ class ImportLoadLibs(unittest.TestCase):
# The whitelist is a list of regex expressions that mark wanted libraries
# Note that the regex has to result in an exact match with the library name.
known_libs = [
# libCore and dependencies
'libCore',
'libm',
'liblz4',
'libxxhash',
'liblzma',
'libzstd',
'libz',
'libpthread',
'libc',
'libdl',
'libpcre',
'libpcre2-8',
# libCling and dependencies
'libCling.*',
'librt',
'libncurses.*',
'libtinfo', # by libncurses (on some older platforms)
# libTree and dependencies
'libTree',
'libThread',
'libRIO',
'libNet',
'libImt',
'libMathCore',
'libMultiProc',
'libssl',
'libcrypt.*', # by libssl
'oqsprovider', # loaded by libssl on e.g. centos10
'liboqs', # used by above
'libtbb',
'libtbb_debug',
'libtbbmalloc',
'liburing', # by libRIO if uring option is enabled
# On centos7 libssl links against kerberos pulling in all dependencies below, removed with libssl1.1.0
'libgssapi_krb5',
'libkrb5',
'libk5crypto',
'libkrb5support',
'libselinux',
'libkeyutils',
'libcom_err',
'libresolv',
# cppyy and Python libraries
'libcppyy.*',
'libROOTPythonizations.*',
'libpython.*',
'libutil.*',
'.*cpython.*',
'_.*',
'.*module',
'operator',
'cStringIO',
'binascii',
'libbz2',
'libexpat',
'ISO8859-1',
# System libraries and others
'libnss_.*',
'ld.*',
'libffi',
'libgcc_s',
# AddressSanitizer runtime and ROOT configuration
'libclang_rt.asan-.*',
'libROOTSanitizerConfig',
]
# libCore and dependencies
"libCore",
"libm",
"liblz4",
"libxxhash",
"liblzma",
"libzstd",
"libz",
"libpthread",
"libc",
"libdl",
"libpcre",
"libpcre2-8",
# libCling and dependencies
"libCling.*",
"librt",
"libncurses.*",
"libtinfo", # by libncurses (on some older platforms)
# libTree and dependencies
"libTree",
"libThread",
"libRIO",
"libNet",
"libImt",
"libMathCore",
"libMultiProc",
"libssl",
"libcrypt.*", # by libssl
"oqsprovider", # loaded by libssl on e.g. centos10
"liboqs", # used by above
"libtbb",
"libtbb_debug",
"libtbbmalloc",
"liburing", # by libRIO if uring option is enabled
# On centos7 libssl links against kerberos pulling in all dependencies below, removed with libssl1.1.0
"libgssapi_krb5",
"libkrb5",
"libk5crypto",
"libkrb5support",
"libselinux",
"libkeyutils",
"libcom_err",
"libresolv",
# cppyy and Python libraries
"libcppyy.*",
"libROOTPythonizations.*",
"libpython.*",
"libutil.*",
".*cpython.*",
"_.*",
".*module",
"operator",
"cStringIO",
"binascii",
"libbz2",
"libexpat",
"ISO8859-1",
# System libraries and others
"libnss_.*",
"ld.*",
"libffi",
"libgcc_s",
# AddressSanitizer runtime and ROOT configuration
"libclang_rt.asan-.*",
"libROOTSanitizerConfig",
]

# Verbose mode of the test
verbose = False
Expand All @@ -86,47 +86,55 @@ def test_import(self):
Test libraries loaded after importing ROOT
"""
import ROOT

libs = str(ROOT.gSystem.GetLibraries())

if self.verbose:
print("Initial output from ROOT.gSystem.GetLibraries():\n" + libs)

# Split paths
libs = libs.split(' ')
libs = libs.split(" ")

# Get library name without full path and .so* suffix
libs = [os.path.basename(l).split('.so')[0] for l in libs \
if not l.startswith('-l') and not l.startswith('-L')]
libs = [
os.path.basename(lib).split(".so")[0]
for lib in libs
if not lib.startswith("-l") and not lib.startswith("-L")
]

# Check that the loaded libraries are white listed
bad_libs = []
good_libs = []
matched_re = []
for l in libs:
for lib in libs:
matched = False
for r in self.known_libs:
m = re.match(r, l)
for known_lib in self.known_libs:
m = re.match(known_lib, lib)
if m:
if m.group(0) == l:
if m.group(0) == lib:
matched = True
good_libs.append(l)
matched_re.append(r)
good_libs.append(lib)
matched_re.append(known_lib)
break
if not matched:
bad_libs.append(l)
bad_libs.append(lib)

if self.verbose:
print('Found whitelisted libraries after importing ROOT with the shown regex match:')
for l, r in zip(good_libs, matched_re):
print(' - {} ({})'.format(l, r))
print("Found whitelisted libraries after importing ROOT with the shown regex match:")
for lib, matched_lib in zip(good_libs, matched_re):
print(" - {} ({})".format(lib, matched_lib))
import sys

sys.stdout.flush()

if bad_libs:
raise Exception('Found not whitelisted libraries after importing ROOT:' \
+ '\n - ' + '\n - '.join(bad_libs) \
+ '\nIf the test fails with a library that is loaded on purpose, please add it to the whitelist.')
raise Exception(
"Found not whitelisted libraries after importing ROOT:"
+ "\n - "
+ "\n - ".join(bad_libs)
+ "\nIf the test fails with a library that is loaded on purpose, please add it to the whitelist."
)


if __name__ == '__main__':
if __name__ == "__main__":
unittest.main()
Loading