Skip to content

Commit aa8e6cf

Browse files
mgornydimpase
authored andcommitted
Install cysignals-CSI-helper as package data for better portability
Rather than installing `cysignals-CSI-helper.py` into a `share` directory and then trying to figure out the correct path to it, install it as Python package data and use the standard `importlib.resources` API to access it. For Python versions older than 3.9, the `importlib_resources` backport is used instead. Fixes #200
1 parent f76d299 commit aa8e6cf

File tree

2 files changed

+11
-9
lines changed

2 files changed

+11
-9
lines changed

src/scripts/cysignals-CSI

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,11 @@ from argparse import ArgumentParser
4141
from datetime import datetime
4242
from shutil import which
4343

44+
if sys.version_info >= (3, 9):
45+
import importlib.resources as importlib_resources
46+
else:
47+
import importlib_resources
48+
4449

4550
def pid_exists(pid):
4651
"""
@@ -65,15 +70,12 @@ def gdb_commands(pid, color):
6570
cmds += b'import sys; sys.stdout.flush()\n'
6671
cmds += b'end\n'
6772
cmds += b'bt full\n'
68-
cysignals_share = os.path.join(os.path.dirname(sys.argv[0]), '..',
69-
'share', 'cysignals')
70-
script = os.path.join(cysignals_share, 'cysignals-CSI-helper.py')
71-
with open(script, 'rb') as f:
72-
cmds += b'python\n'
73-
cmds += b'color = %r; ' % color
74-
cmds += b'sys_path = %r; ' % sys.path
75-
cmds += f.read()
76-
cmds += b'end\n'
73+
script = importlib_resources.files('cysignals') / 'cysignals-CSI-helper.py'
74+
cmds += b'python\n'
75+
cmds += b'color = %r; ' % color
76+
cmds += b'sys_path = %r; ' % sys.path
77+
cmds += script.read_bytes()
78+
cmds += b'end\n'
7779
cmds += b'detach inferior 1\n'
7880
cmds += b'quit\n'
7981
return cmds

0 commit comments

Comments
 (0)