File tree Expand file tree Collapse file tree 1 file changed +9
-16
lines changed Expand file tree Collapse file tree 1 file changed +9
-16
lines changed Original file line number Diff line number Diff line change 1- import os
21import pickle
32import sys
43from collections import Counter
4+ from pathlib import Path
55
66from pytensor .configdefaults import config
77
1212dirs : list = []
1313if len (sys .argv ) > 1 :
1414 for compiledir in sys .argv [1 :]:
15- dirs .extend (os . path . join ( compiledir , d ) for d in os . listdir (compiledir ))
15+ dirs .extend (x . resolve ( ) for x in Path (compiledir ). iterdir ( ))
1616else :
17- dirs = os .listdir (config .compiledir )
18- dirs = [os .path .join (config .compiledir , d ) for d in dirs ]
17+ dirs = [x .resolve () for x in config .compiledir .iterdir ()]
1918keys : Counter [bytes ] = Counter () # key -> nb seen
2019mods : dict = {}
2120for dir in dirs :
22- key = None
21+ if not dir .is_dir ():
22+ continue
2323 try :
24- with open (os .path .join (dir , "key.pkl" ), "rb" ) as f :
25- key = f .read ()
24+ key = (dir / "key.pkl" ).read_bytes ()
2625 keys [key ] += 1
27- del f
28- except OSError :
26+ except FileNotFoundError :
2927 # print dir, "don't have a key.pkl file"
3028 pass
3129 try :
32- path = os .path .join (dir , "mod.cpp" )
33- with open (path ) as fmod :
34- mod = fmod .read ()
30+ mod = (dir / "mod.cpp" ).read_text (encoding = "utf-8" )
3531 mods .setdefault (mod , ())
3632 mods [mod ] += (key ,)
37- del mod
38- del fmod
39- del path
40- except OSError :
33+ except FileNotFoundError :
4134 print (dir , "don't have a mod.cpp file" )
4235
4336if DISPLAY_DUPLICATE_KEYS :
You can’t perform that action at this time.
0 commit comments