File: 0001-Load-libscalene-so-with-Python-ABI-suffix

package info (click to toggle)
scalene 1.5.51-1
  • links: PTS, VCS
  • area: main
  • in suites: trixie
  • size: 15,528 kB
  • sloc: cpp: 22,930; python: 13,403; javascript: 11,769; ansic: 817; makefile: 196; sh: 45
file content (25 lines) | stat: -rw-r--r-- 1,072 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
--- a/scalene/scalene_preload.py
+++ b/scalene/scalene_preload.py
@@ -10,6 +10,10 @@
 import scalene
 
 
+# To patch loader to use Python ABI renamed files
+from importlib.machinery import EXTENSION_SUFFIXES
+
+
 class ScalenePreload:
     @staticmethod
     def get_preload_environ(args: argparse.Namespace) -> Dict[str, str]:
@@ -67,7 +71,10 @@
                 elif library_path not in os.environ['LD_LIBRARY_PATH']:
                     env['LD_LIBRARY_PATH'] = f'{library_path}:{os.environ["LD_LIBRARY_PATH"]}'
 
-                new_ld_preload = 'libscalene.so'
+                # Debianize the path to so file which has been suffixed with arch and Python version
+                library_filename = "libscalene" + EXTENSION_SUFFIXES[0]
+                new_ld_preload = os.path.join(scalene.__path__[0], library_filename)
+
                 if "LD_PRELOAD" in os.environ and new_ld_preload not in os.environ["LD_PRELOAD"]:
                     old_ld_preload = os.environ["LD_PRELOAD"]
                     env["LD_PRELOAD"] = new_ld_preload + ":" + old_ld_preload