Skip to content

Commit 61fc0ee

Browse files
committed
Move over to Pathlib
1 parent ca3e0ba commit 61fc0ee

File tree

1 file changed

+7
-7
lines changed

1 file changed

+7
-7
lines changed

IsoSpecPy/isoFFI.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import cffi
2-
import os
32
import platform
43
import sys
54
import glob
5+
from pathlib import Path
66
if False:
77
import IsoSpecCppPy
88

@@ -143,10 +143,10 @@ def __init__(self):
143143
extern const bool elem_table_Radioactive[NUMBER_OF_ISOTOPIC_ENTRIES];
144144
''');
145145

146-
mod_dir = os.path.dirname(os.path.abspath(__file__))
146+
mod_dir = Path(__file__).resolve().parent
147147
dprint("mod_dir:", mod_dir)
148148

149-
if os.path.exists(os.path.join(mod_dir, '..', 'setup.py')):
149+
if (mod_dir.parent / 'setup.py').exists():
150150
raise ImportError('''Attempted to load IsoSpecPy module from its build directory. This usually
151151
won't work and is generally a Bad Idea. Please cd somewhere else, or, if you're really
152152
sure you want to do that, edit the source and disable this check.''')
@@ -181,16 +181,16 @@ def cprod(ll1, ll2):
181181
dprint("Constructed paths to check:", paths_to_check)
182182
dpc = []
183183

184-
for dirpath in [mod_dir, mod_dir + '/..']:
185-
dpc.extend([os.path.join(dirpath, p) for p in paths_to_check])
184+
for dirpath in [mod_dir, mod_dir.parent]:
185+
dpc.extend([dirpath / p for p in paths_to_check])
186186

187187
paths_to_check = dpc
188188
dprint("Final paths to check before globbing:", paths_to_check)
189189
paths_to_check = sum(map(glob.glob, paths_to_check), [])
190190
dprint("Final paths to check after globbing:", paths_to_check)
191191
try:
192192
import importlib
193-
paths_to_check.insert(0, importlib.util.find_spec("IsoSpecCppPy").origin)
193+
paths_to_check.insert(0, Path(importlib.util.find_spec("IsoSpecCppPy").origin))
194194
dprint("Also trying to load IsoSpecCppPy from:", paths_to_check[0])
195195
except (ImportError, AttributeError):
196196
pass
@@ -201,7 +201,7 @@ def cprod(ll1, ll2):
201201
for libpath in set(paths_to_check):
202202
try:
203203
dprint("Trying to load libIsoSpec++.so from:", libpath)
204-
self.clib = self.ffi.dlopen(libpath)
204+
self.clib = self.ffi.dlopen(str(libpath))
205205
self.libpath = libpath
206206
dprint("Successfully loaded libIsoSpec++.so from:", libpath)
207207
break

0 commit comments

Comments
 (0)