Skip to content

Commit 9289f73

Browse files
committed
Refactor file manipulations to use pathlib
1 parent a2ab830 commit 9289f73

File tree

2 files changed

+11
-11
lines changed

2 files changed

+11
-11
lines changed

src/axelrod_fortran/player.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ def strategy(self, opponent):
115115

116116
def _release_shared_library(self):
117117
# While this looks like we're checking that the shared library file
118-
# isn't deleted, the exception is actually thrown in the manager
118+
# isn't deleted, the exception is actually thrown if the manager
119119
# thread closes before the player class is garbage collected, which
120120
# tends to happen at the end of a script.
121121
try:

src/axelrod_fortran/shared_library_manager.py

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
from ctypes.util import find_library
44
from multiprocessing.managers import BaseManager
55
import os
6+
from pathlib import Path
67
import platform
78
import shutil
89
import subprocess
@@ -59,13 +60,11 @@ def create_library_copy(self):
5960
# Copy the library file to a new (temp) location.
6061
temp_directory = tempfile.gettempdir()
6162
copy_number = len(self.filenames)
62-
new_filename = os.path.join(
63-
temp_directory,
64-
"{}-{}-{}".format(
65-
self.prefix,
66-
str(copy_number),
67-
self.shared_library_name)
68-
)
63+
filename = "{}-{}-{}".format(
64+
self.prefix,
65+
str(copy_number),
66+
self.shared_library_name)
67+
new_filename = Path(temp_directory) / filename
6968
if self.verbose:
7069
print("Loading {}".format(new_filename))
7170
shutil.copy2(self.library_path, new_filename)
@@ -107,10 +106,11 @@ def release(self, name, index):
107106
def __del__(self):
108107
"""Cleanup temp files on object deletion."""
109108
for filename in self.filenames:
110-
if os.path.exists(filename):
109+
path = Path(filename)
110+
if path.exists():
111111
if self.verbose:
112-
print("deleting", filename)
113-
os.remove(filename)
112+
print("deleting", str(path))
113+
os.remove(str(path))
114114

115115

116116
# Setup up thread safe library manager.

0 commit comments

Comments
 (0)