File tree 1 file changed +9
-16
lines changed
1 file changed +9
-16
lines changed Original file line number Diff line number Diff line change 1
- import os
2
1
import pickle
3
2
import sys
4
3
from collections import Counter
4
+ from pathlib import Path
5
5
6
6
from pytensor .configdefaults import config
7
7
12
12
dirs : list = []
13
13
if len (sys .argv ) > 1 :
14
14
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 ( ))
16
16
else :
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 ()]
19
18
keys : Counter [bytes ] = Counter () # key -> nb seen
20
19
mods : dict = {}
21
20
for dir in dirs :
22
- key = None
21
+ if not dir .is_dir ():
22
+ continue
23
23
try :
24
- with open (os .path .join (dir , "key.pkl" ), "rb" ) as f :
25
- key = f .read ()
24
+ key = (dir / "key.pkl" ).read_bytes ()
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
- with open (path ) as fmod :
34
- mod = fmod .read ()
30
+ mod = (dir / "mod.cpp" ).read_text (encoding = "utf-8" )
35
31
mods .setdefault (mod , ())
36
32
mods [mod ] += (key ,)
37
- del mod
38
- del fmod
39
- del path
40
- except OSError :
33
+ except FileNotFoundError :
41
34
print (dir , "don't have a mod.cpp file" )
42
35
43
36
if DISPLAY_DUPLICATE_KEYS :
You can’t perform that action at this time.
0 commit comments