-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathpatcher.py
37 lines (34 loc) · 1.33 KB
/
patcher.py
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
26
27
28
29
30
31
32
33
34
35
36
37
import zipfile
import argparse
import re
import tempfile
import os
import sys
from pathlib import Path
import subprocess
def main():
parser = argparse.ArgumentParser()
parser.add_argument('source')
args = parser.parse_args()
source = list(Path(args.source).glob('pyterrier_pisa*.whl'))[0]
version = re.search(r'cp([0-9]+)', str(source)).group(1)
print('------------- version ----------------')
print(version)
# with tempfile.NamedTemporaryFile() as tmpf:
# with zipfile.ZipFile(source, 'r') as zipf:
# for file in zipf.infolist():
# if re.match(r'pyterrier_pisa.libs/libtbb.*.so.2', file.filename):
# n_tbb = file.filename
if os.environ.get("PT_PISA_MANYLINUX", "False") == "True":
# tbb = Path('/tbb/tbb/lib/intel64/gcc4.8/libtbb.so.2')
pisathon_so = list(Path('/tmp/libtbb/').glob('_pisathon*-' + version + '-*'))[0]
else:
# tbb = list(Path('_skbuild/libtbb/').glob('libtbb.so.2'))[0]
pisathon_so = list(Path('_skbuild/libtbb/').glob('_pisathon*-' + version + '-*'))[0]
subprocess.run(['patchelf', '--set-rpath', '$ORIGIN/../../..', str(pisathon_so)])
with zipfile.ZipFile(source, 'a', zipfile.ZIP_DEFLATED) as zipf:
n = pisathon_so.name
zipf.write(pisathon_so, f"pyterrier_pisa/{n}")
# zipf.write(tbb, 'pyterrier_pisa.libs/libtbb.so.2')
if __name__ == '__main__':
main()