File tree 1 file changed +9
-4
lines changed
1 file changed +9
-4
lines changed Original file line number Diff line number Diff line change 9
9
import os
10
10
import io
11
11
12
+
12
13
def get_header (exfile : Path ) -> str :
13
14
text = exfile .read_text (encoding = "utf-8" )
14
15
header = re .search (r"^---$(.+?)^---$" , text , flags = re .M | re .S )
15
16
if header is None :
16
17
raise Exception (f"{ exfile } does not contain a YAML header" )
17
18
if header .start () != 0 :
18
- raise Exception (f"{ exfile } has a YAML block, which is not at the beginning of the file but at postion { header .start ()} " )
19
+ raise Exception (
20
+ f"{ exfile } has a YAML block, which is not at the beginning of the file but at postion { header .start ()} "
21
+ )
19
22
return header .group (1 )
20
23
24
+
21
25
def find_duplicates (lst : List [Tuple [Path , str ]]) -> List [Tuple [str , List [Path ]]]:
22
26
count = {}
23
27
for path , id in lst :
24
28
count .setdefault (id , [])
25
29
count [id ].append (path )
26
- duplicates = { i : l for i , l in count .items () if len (l ) > 1 }
27
- return list (duplicates )
30
+ duplicates = {i : l for i , l in count .items () if len (l ) > 1 }
31
+ return list (duplicates .items ())
32
+
28
33
29
34
if __name__ == "__main__" :
30
35
os .chdir (Path (__file__ ).parent )
31
- exercises = Path ("../../exercises" ).glob ("*/*/*/*.md" )
36
+ exercises = Path ("../../exercises" ).glob ("*/*/*/*.md" )
32
37
headers = [(p , yaml .safe_load (io .StringIO (get_header (p )))) for p in exercises ]
33
38
noid = [(p , h ) for p , h in headers if "id" not in h ]
34
39
ids = [(p , h ["id" ]) for p , h in headers if "id" in h ]
You can’t perform that action at this time.
0 commit comments