File tree Expand file tree Collapse file tree 1 file changed +12
-18
lines changed Expand file tree Collapse file tree 1 file changed +12
-18
lines changed Original file line number Diff line number Diff line change 1
- import os
2
1
import pickle
3
2
import sys
3
+ from pathlib import Path
4
4
5
5
from pytensor .configdefaults import config
6
6
11
11
dirs = []
12
12
if len (sys .argv ) > 1 :
13
13
for compiledir in sys .argv [1 :]:
14
- dirs .extend ([os . path . join ( compiledir , d ) for d in os . listdir (compiledir )])
14
+ dirs .extend ([x . resolve ( ) for x in Path (compiledir ). iterdir ( )])
15
15
else :
16
- dirs = os .listdir (config .compiledir )
17
- dirs = [os .path .join (config .compiledir , d ) for d in dirs ]
16
+ dirs = [x .resolve () for x in config .compiledir .iterdir ()]
18
17
keys : dict = {} # key -> nb seen
19
18
mods : dict = {}
20
19
for dir in dirs :
21
- key = None
20
+ if not dir .is_dir ():
21
+ continue
22
22
try :
23
- with open (os .path .join (dir , "key.pkl" )) as f :
24
- key = f .read ()
23
+ key = (dir / "key.pkl" ).read_bytes ()
25
24
keys .setdefault (key , 0 )
26
25
keys [key ] += 1
27
- del f
28
- except OSError :
26
+ except FileNotFoundError :
29
27
# print dir, "don't have a key.pkl file"
30
28
pass
31
29
try :
32
- path = os .path .join (dir , "mod.cpp" )
33
- if not os .path .exists (path ):
34
- path = os .path .join (dir , "mod.cu" )
35
- with open (path ) as f :
36
- mod = f .read ()
30
+ path = dir / "mod.cpp"
31
+ if not path .exists ():
32
+ path = dir / "mod.cu"
33
+ mod = path .read_text (encoding = "utf-8" )
37
34
mods .setdefault (mod , ())
38
35
mods [mod ] += (key ,)
39
- del mod
40
- del f
41
- del path
42
- except OSError :
36
+ except FileNotFoundError :
43
37
print (dir , "don't have a mod.{cpp,cu} file" )
44
38
45
39
if DISPLAY_DUPLICATE_KEYS :
You can’t perform that action at this time.
0 commit comments