1
+ """This script generates the rst files for the modules in the bookmarks package.
2
+
3
+ Use it in conjunction with make.bat to generate the documentation.
4
+
5
+ """
1
6
import os
2
7
3
- SOURCE = os .path .normpath (f'{ __file__ } /{ os .pardir } /{ os .pardir } /{ os .pardir } /bookmarks' ).replace ('\\ ' , '/' )
4
- DOCS_DIR = os .path .normpath (f'{ __file__ } /{ os .pardir } /modules' ).replace ('\\ ' , '/' )
8
+ PYTHON_MODULE_DIR = os .path .normpath (f'{ __file__ } /{ os .pardir } /{ os .pardir } /{ os .pardir } /bookmarks' ).replace ('\\ ' , '/' )
9
+ PYTHON_MODULE_DOCS_DIR = os .path .normpath (f'{ __file__ } /{ os .pardir } /modules' ).replace ('\\ ' , '/' )
5
10
6
- def recursive_search (path ):
7
- for entry in os .scandir (path ):
8
- if entry .is_dir ():
9
- yield from recursive_search (entry .path )
10
- else :
11
- yield entry
11
+ if not os .path .isdir (PYTHON_MODULE_DOCS_DIR ):
12
+ raise RuntimeError (f'Could not find the docs directory: { PYTHON_MODULE_DOCS_DIR } ' )
12
13
14
+ if not os .path .isdir (PYTHON_MODULE_DIR ):
15
+ raise RuntimeError (f'Could not find the source directory: { PYTHON_MODULE_DIR } ' )
13
16
14
- _source = '/' .join (SOURCE .split ('/' )[:- 1 ])
15
- contents = []
16
17
17
- for entry in recursive_search (SOURCE ):
18
- if not entry .name .endswith ('.py' ):
19
- continue
18
+ def recursive_search (_path ):
19
+ if '__pycache__' in _path :
20
+ return
21
+
22
+ print (f'>>> Searching for modules in: { _path } ' )
23
+ for _entry in os .scandir (_path ):
24
+ if _entry .is_dir ():
25
+ yield from recursive_search (_entry .path .replace ('\\ ' , '/' ))
26
+ else :
27
+ yield _entry
20
28
21
- path = entry .path .replace ('\\ ' , '/' )
22
29
23
- parent = os .path .join (path , os .pardir )
24
- basemod = os .path .normpath (parent ).replace ('\\ ' , '/' ).replace (_source , '' ).strip ('/' )
25
- basemod = basemod if basemod else 'bookmarks'
26
30
27
- if entry . name == '__init__.py ' :
28
- rst_dir = f' { DOCS_DIR } / { basemod } '
29
- rst_file = f' { rst_dir } / { basemod } .rst'
31
+ if __name__ == '__main__ ' :
32
+ print ( '>>> Generating the documentation for the bookmarks package:' )
33
+ print ( f'>>> Source: { PYTHON_MODULE_DIR } ' )
30
34
31
- if not os .path .isdir (rst_dir ):
32
- os .makedirs (rst_dir )
33
- continue
35
+ _source = '/' .join (PYTHON_MODULE_DIR .split ('/' )[:- 1 ])
36
+ contents = []
34
37
35
- basename = path .replace (_source , '' ).strip ('/' ).replace ('.py' , '.rst' )
36
- basename = basename if basename else 'bookmarks'
37
- rst_file = f'{ DOCS_DIR } /{ basename } '
38
- with open (rst_file , 'w' ) as f :
38
+ # Generate the index bookmarks.rst file
39
+ with open (f'{ PYTHON_MODULE_DOCS_DIR } /bookmarks.rst' , 'w' ) as f :
39
40
f .write (f'.. meta::\n ' )
40
41
f .write (f' :description: Developer documentation page for the Bookmarks python modules\n ' )
41
- f .write (f' :keywords: Bookmarks, bookmarksvfx, asset manager, assets, PySide, Qt5, PySide2, Python, vfx, animation, film, productivity, free, open-source, opensource, lightweight, ShotGrid, RV, FFMpeg, ffmpeg, publish, manage, digital content management, production, OpenImageIO\n ' )
42
+ f .write (
43
+ f' :keywords: Bookmarks, bookmarksvfx, pipeline, pipe, asset manager, assets, PySide, Qt, PySide,'
44
+ f'Python, vfx, animation, film, production, open-source, opensource, ShotGun, ShotGrid, RV, '
45
+ f'ffmpeg, openimageio, publish, manage, digital content management\n '
46
+ )
42
47
f .write (f'\n ' )
43
- title = '.' .join (basename .replace (".rst" , '' ).split ('/' )[1 :])
44
- f .write (f'{ title } \n ' )
45
- f .write ('=' * (len (basemod ) + 10 ) + '\n ' )
48
+ f .write (f'bookmarks\n ' )
49
+ f .write (f'=========\n ' )
46
50
f .write (f'\n ' )
47
- f .write (f'.. automodule:: { basename .replace ("/" , "." ).replace (".rst" , "" )} \n ' )
48
- f .write (' :members:\n ' )
49
- f .write (' :show-inheritance:\n ' )
51
+ f .write (f'.. automodule:: bookmarks\n ' )
52
+ f .write (f' :members:\n ' )
53
+ f .write (f' :show-inheritance:\n ' )
54
+ f .write (f'\n ' )
55
+ f .write (f'.. toctree::\n ' )
56
+ f .write (f' :glob:\n ' )
57
+ f .write (f'\n ' )
58
+ f .write (f' bookmarks/**\n ' )
59
+ f .write (f'\n ' )
60
+
61
+ for entry in recursive_search (PYTHON_MODULE_DIR ):
62
+ if not entry .name .endswith ('.py' ):
63
+ continue
64
+
65
+ path = entry .path .replace ('\\ ' , '/' )
66
+
67
+ parent = os .path .join (path , os .pardir )
68
+ basemod = os .path .normpath (parent ).replace ('\\ ' , '/' ).replace (_source , '' ).strip ('/' )
69
+ basemod = basemod if basemod else 'bookmarks'
70
+
71
+ if entry .name == '__init__.py' :
72
+ rst_dir = f'{ PYTHON_MODULE_DOCS_DIR } /{ basemod } '
73
+ rst_file = f'{ rst_dir } /{ basemod } .rst'
74
+ os .makedirs (rst_dir , exist_ok = True )
75
+ continue
76
+
77
+ basename = path .replace (_source , '' ).strip ('/' ).replace ('.py' , '.rst' )
78
+ basename = basename if basename else 'bookmarks'
79
+ rst_file = f'{ PYTHON_MODULE_DOCS_DIR } /{ basename } '
80
+
81
+ os .makedirs (os .path .dirname (rst_file ), exist_ok = True )
82
+
83
+ with open (rst_file , 'w' ) as f :
84
+ print (f'>>> Generating rst for: { path } ' )
85
+
86
+ f .write (f'.. meta::\n ' )
87
+ f .write (f' :description: Developer documentation page for the Bookmarks python modules\n ' )
88
+ f .write (
89
+ f' :keywords: Bookmarks, bookmarksvfx, pipeline, pipe, asset manager, assets, PySide, Qt, PySide,'
90
+ f'Python, vfx, animation, film, production, open-source, opensource, ShotGun, ShotGrid, RV, '
91
+ f'ffmpeg, openimageio, publish, manage, digital content management\n '
92
+ )
93
+ f .write (f'\n ' )
94
+ title = '.' .join (basename .replace (".rst" , '' ).split ('/' )[1 :])
95
+ f .write (f'{ title } \n ' )
96
+ f .write ('=' * (len (basemod ) + 10 ) + '\n ' )
97
+ f .write (f'\n ' )
98
+ f .write (f'.. automodule:: { basename .replace ("/" , "." ).replace (".rst" , "" )} \n ' )
99
+ f .write (' :members:\n ' )
100
+ f .write (' :show-inheritance:\n ' )
101
+
102
+
0 commit comments