|
2 | 2 | from ctypes import cdll, c_int, c_float, byref, POINTER
|
3 | 3 | from ctypes.util import find_library
|
4 | 4 | import os
|
| 5 | +import platform |
5 | 6 | import random
|
| 7 | +import re |
6 | 8 | import shutil
|
| 9 | +import subprocess |
7 | 10 | import tempfile
|
8 | 11 | import uuid
|
9 | 12 | import warnings
|
|
18 | 21 | original_actions = {C: 0, D: 1}
|
19 | 22 |
|
20 | 23 |
|
| 24 | +path_regex = r""".*?\s=>\s(.*?{}.*?)\\""" |
| 25 | + |
21 | 26 | self_interaction_message = """
|
22 | 27 | You are playing a match with the same player against itself. However
|
23 | 28 | axelrod_fortran players share memory. You can initialise another instance of an
|
@@ -51,11 +56,17 @@ def __init__(self, shared_library_name, verbose=False):
|
51 | 56 | self.filenames = []
|
52 | 57 |
|
53 | 58 | 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", "")) |
59 | 70 |
|
60 | 71 | def load_dll_copy(self):
|
61 | 72 | """Load a new copy of the shared library."""
|
|
0 commit comments