21
21
ROOT_PATH = Path (__file__ ).parent .resolve () / ".." / ".." / ".."
22
22
23
23
24
+ def get_diff_fpaths (
25
+ ddiff : DeepDiff , diff_type : Literal ["removed" , "added" ], fpath : Path
26
+ ):
27
+ """This function returns a list of file paths that have been removed or added
28
+
29
+ Parameters
30
+ ----------
31
+ ddiff : DeepDiff
32
+ DeepDiff object
33
+ diff_type : Literal['removed', 'added']
34
+ either 'removed' or 'added'
35
+ fpath : Path
36
+ Path
37
+
38
+ """
39
+ ddiff_fpaths = []
40
+ ddiff_items = [i for k , v in ddiff .items () for i in ddiff [k ] if diff_type in k ]
41
+ logging .debug (f"{ len (ddiff_items )} items { diff_type } in this repo..." )
42
+ for d in ddiff_items :
43
+ path = [
44
+ i
45
+ for i in d .path (output_format = "list" )
46
+ if i not in ["categories" ]
47
+ if isinstance (i , str )
48
+ ]
49
+
50
+ ## Traversing tree diff
51
+ for node in [d .t1 , d .t2 ]:
52
+ if isinstance (node , list ):
53
+ fname = [f"{ path [- 1 ]} .md" ]
54
+ path .pop ()
55
+ break
56
+ if str (node ) != "not present" :
57
+ fname = [f"{ node } .md" ]
58
+ break
59
+ path += fname
60
+
61
+ if ddiff_items :
62
+ NEW_DOC_FPATH = fpath / "/" .join (path )
63
+ logging .debug (f"\n { NEW_DOC_FPATH } ..." )
64
+ ddiff_fpaths .append (NEW_DOC_FPATH )
65
+ return ddiff_fpaths
66
+
67
+
24
68
def get_config_diff (docs_config : Dict , readme_config : Dict , fpath : Path ) -> List [Path ]:
25
69
"""This function compares the configs in the docs and the configs in the readme
26
70
@@ -42,43 +86,14 @@ def get_config_diff(docs_config: Dict, readme_config: Dict, fpath: Path) -> List
42
86
view = "tree" ,
43
87
)
44
88
45
- paths = []
46
89
if ddiff :
47
90
logging .debug (f"---------" )
48
91
logging .debug (f"Deepdiff: \n { ddiff } ..." )
49
92
50
- new_doc_items = [
51
- i for k , v in ddiff .items () for i in ddiff [k ] if "removed" in k
52
- ]
53
- ## TODO: Add new page in repo if created in ReadMe
54
- new_readme_items = [
55
- i for k , v in ddiff .items () for i in ddiff [k ] if "added" in k
56
- ]
57
- logging .debug (f"{ len (new_doc_items )} items added" )
58
- for d in new_doc_items :
59
- path = [
60
- i
61
- for i in d .path (output_format = "list" )
62
- if i not in ["categories" ]
63
- if isinstance (i , str )
64
- ]
65
-
66
- ## Traversing tree diff
67
- for node in [d .t1 , d .t2 ]:
68
- if isinstance (node , list ):
69
- fname = [f"{ path [- 1 ]} .md" ]
70
- path .pop ()
71
- break
72
- if str (node ) != "not present" :
73
- fname = [f"{ node } .md" ]
74
- break
75
-
76
- path += fname
77
-
78
- DIFF_FPATH = fpath / "/" .join (path )
79
- logging .debug (f"\n { DIFF_FPATH } ..." )
80
- paths .append (DIFF_FPATH )
81
- return paths
93
+ new_doc_fpaths = get_diff_fpaths (ddiff , "removed" , fpath )
94
+ new_readme_fpaths = get_diff_fpaths (ddiff , "added" , fpath )
95
+
96
+ return new_doc_fpaths , new_readme_fpaths
82
97
83
98
84
99
def get_frontmatter (fpath : Path ) -> Dict :
@@ -188,56 +203,56 @@ def main(args):
188
203
docs_condensed_config = docs_config .condensed_config
189
204
readme_condensed_config = readme_config .condensed_config
190
205
191
- new_fpaths = get_config_diff (
206
+ new_doc_fpaths , new_readme_fpaths = get_config_diff (
192
207
docs_config = docs_condensed_config ,
193
208
readme_config = readme_condensed_config ,
194
209
fpath = DOCS_PATH ,
195
210
)
196
211
197
- if not new_fpaths :
198
- logging .debug (f"No new updates in config ..." )
199
- else :
200
- for path in new_fpaths :
201
- category = str (path ).split ("/docs" )[1 ].split ("/" )[1 ]
202
- parent = path .parent .name
203
- logging .debug (f"Category: { category } Parent: { parent } " )
204
-
205
- # ## TODO: read slug from fname - in case slug is not the same
206
- post = get_frontmatter (path )
207
-
208
- ## Creating new frontmatter if none exists
209
-
210
- ## Getting max page order
211
- if category == parent :
212
- config_dict = readme_config .config ["categories" ][category ]
213
- page_orders = readme_config .get_page_orders (
214
- config_dict , category = True
215
- )
216
- else :
217
- config_dict = readme_config .config ["categories" ][category ][parent ]
218
- page_orders = readme_config .get_page_orders (
219
- config_dict , category = False
220
- )
221
- max_page_order = max (page_orders )
222
-
223
- ## Creating new page
224
- args = {
225
- "title" : post ["title" ],
226
- "type" : "basic" ,
227
- "category_slug" : category ,
228
- "parent_slug" : parent ,
229
- "hidden" : post ["hidden" ],
230
- "order" : max_page_order + 1 ,
231
- }
232
- logging .debug (
233
- f"Creating new ReadMe config page... \n \t { path } \n { json .dumps (args )} "
234
- )
235
- # readme_config.create(**args)
236
-
237
- logging .debug (f"Rebuilding config ... " )
238
-
239
- # # ## TODO: Inserting new item in readme config with new category only instead rebuilding full config
240
- # readme_config.build()
212
+ # if not new_doc_fpaths and not new_readme_fpaths :
213
+ # logging.debug(f"No new updates in config ...")
214
+ # elif new_doc_fpaths :
215
+ # for path in new_doc_fpaths :
216
+ # category = str(path).split("/docs")[1].split("/")[1]
217
+ # parent = path.parent.name
218
+ # logging.debug(f"Category: {category} Parent: {parent}")
219
+
220
+ # # ## TODO: read slug from fname - in case slug is not the same
221
+ # post = get_frontmatter(path)
222
+
223
+ # ## Creating new frontmatter if none exists
224
+
225
+ # ## Getting max page order
226
+ # if category == parent:
227
+ # config_dict = readme_config.config["categories"][category]
228
+ # page_orders = readme_config.get_page_orders(
229
+ # config_dict, category=True
230
+ # )
231
+ # else:
232
+ # config_dict = readme_config.config["categories"][category][parent]
233
+ # page_orders = readme_config.get_page_orders(
234
+ # config_dict, category=False
235
+ # )
236
+ # max_page_order = max(page_orders)
237
+
238
+ # ## Creating new page
239
+ # args = {
240
+ # "title": post["title"],
241
+ # "type": "basic",
242
+ # "category_slug": category,
243
+ # "parent_slug": parent,
244
+ # "hidden": post["hidden"],
245
+ # "order": max_page_order + 1,
246
+ # }
247
+ # logging.debug(
248
+ # f"Creating new ReadMe config page... \n\t{path}\n{json.dumps(args)}"
249
+ # )
250
+ # readme_config.create(**args)
251
+
252
+ # logging.debug(f"Rebuilding config ... ")
253
+
254
+ # # # ## TODO: Inserting new item in readme config with new category only instead rebuilding full config
255
+ # # readme_config.build()
241
256
242
257
243
258
if __name__ == "__main__" :
0 commit comments