Skip to content

Commit 0b2e8da

Browse files
committed
Dynamically located shared library path
1 parent daa7431 commit 0b2e8da

File tree

1 file changed

+16
-5
lines changed

1 file changed

+16
-5
lines changed

src/axelrod_fortran/player.py

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,11 @@
22
from ctypes import cdll, c_int, c_float, byref, POINTER
33
from ctypes.util import find_library
44
import os
5+
import platform
56
import random
7+
import re
68
import shutil
9+
import subprocess
710
import tempfile
811
import uuid
912
import warnings
@@ -18,6 +21,8 @@
1821
original_actions = {C: 0, D: 1}
1922

2023

24+
path_regex = r""".*?\s=>\s(.*?{}.*?)\\"""
25+
2126
self_interaction_message = """
2227
You are playing a match with the same player against itself. However
2328
axelrod_fortran players share memory. You can initialise another instance of an
@@ -51,11 +56,17 @@ def __init__(self, shared_library_name, verbose=False):
5156
self.filenames = []
5257

5358
def find_shared_library(self, shared_library_name):
54-
## This finds only the relative path to the library, unfortunately.
55-
# reduced_name = shared_library_name.replace("lib", "").replace(".so", "")
56-
# self.library_path = find_library(reduced_name)
57-
# Hard code absolute path for testing purposes.
58-
return "/usr/lib/libstrategies.so"
59+
# Hack for Linux since find_library doesn't return the full path.
60+
if 'Linux' in platform.system():
61+
output = subprocess.check_output(["ldconfig", "-p"])
62+
for line in str(output).split(r"\n"):
63+
rhs = line.split(" => ")[-1]
64+
if shared_library_name in rhs:
65+
return rhs
66+
raise ValueError("{} not found".format(shared_library_name))
67+
else:
68+
return find_library(
69+
shared_library_name.replace("lib", "").replace(".so", ""))
5970

6071
def load_dll_copy(self):
6172
"""Load a new copy of the shared library."""

0 commit comments

Comments
 (0)