Skip to content

Commit aab4c17

Browse files
Merge pull request #382 from TeamMsgExtractor/next-release
Update documentation for RTD
2 parents 8dfff86 + dec1a48 commit aab4c17

13 files changed

+684
-395
lines changed

docs/_autogen.txt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
extract_msg.rst
2+
extract_msg.attachments.rst
3+
extract_msg.attachments.custom_att_handler.rst
4+
extract_msg.constants.rst
5+
extract_msg.encoding.rst
6+
extract_msg.msg_classes.rst
7+
extract_msg.properties.rst
8+
extract_msg.structures.rst

docs/_gen.py

Lines changed: 140 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,140 @@
1+
"""
2+
Helper script for generating the necessary RST files.
3+
"""
4+
5+
import os
6+
import pathlib
7+
8+
from typing import Dict, List, NamedTuple, Tuple
9+
10+
11+
DIRECTORY = pathlib.Path(__file__).parent
12+
13+
14+
class Package(NamedTuple):
15+
"""
16+
A class representing one of the subpackages of a module.
17+
"""
18+
modules : List[str]
19+
packages : List[str]
20+
21+
22+
23+
def _readProject(root) -> Dict[str, Dict[str, bool]]:
24+
"""
25+
Searches a project for Python files, using their locations to create a
26+
dictionary of module paths and their submodules/subpackages. Submodules/subpackages will be a dictionary, where the key is the name and the
27+
"""
28+
# This whole function could almost certainly be optimized, but I'll worry
29+
# about that some other time.
30+
root = pathlib.Path(root)
31+
rootName = root.name
32+
ret = {rootName: {}}
33+
for x in root.glob('**/*.py'):
34+
# Ignore internal files.
35+
if x.name.startswith('_'):
36+
continue
37+
38+
# Get all parent components.
39+
parents = []
40+
parent = x.parent
41+
while parent != root:
42+
parents.append(parent.name)
43+
parent = parent.parent
44+
45+
# Check if any of the parents start with an underscore. If they do,
46+
# ignore the current path.
47+
if any(y.startswith('_') for y in parents):
48+
continue
49+
50+
parents.append(rootName)
51+
52+
parents.reverse()
53+
54+
# Add the subpackages and submodules.
55+
for index, name in enumerate(parents[1:]):
56+
path = '.'.join(parents[:index + 1])
57+
if path not in ret:
58+
ret[path] = {}
59+
if name not in ret[path]:
60+
ret[path][name] = True
61+
if (path := '.'.join(parents)) not in ret:
62+
ret[path] = {}
63+
ret[path][x.name] = False
64+
65+
return ret
66+
67+
68+
def _makePackage(name : str, data : Dict[str, bool]) -> Package:
69+
return Package([f'{name}.{x}' for x in data if not data[x]], [f'{name}.{x}' for x in data if data[x]])
70+
71+
72+
def run():
73+
for x in getAutoGenerated():
74+
os.remove(DIRECTORY / x)
75+
project = readProject(DIRECTORY.parent / 'extract_msg')
76+
for x, y in project.items():
77+
generateFile(x, y)
78+
79+
writeAutoGenerated((x + '.rst' for x in project))
80+
81+
82+
def generateFile(name : str, package : Package):
83+
with open(DIRECTORY / (name + '.rst'), 'w') as f:
84+
# Header.
85+
temp = name.replace('_', '\\_') + ' package'
86+
f.write(f'{temp}\n{"=" * len(temp)}\n\n')
87+
88+
# Subpackages.
89+
if package.packages:
90+
f.write('Subpackages\n-----------\n\n')
91+
f.write('.. toctree::\n')
92+
f.write(' :maxdepth: 4\n\n')
93+
f.write(' ' + '\n '.join(package.packages))
94+
f.write('\n\n')
95+
96+
# Submodules.
97+
if package.modules:
98+
f.write('Submodules\n----------\n\n')
99+
for module in package.modules:
100+
temp = module.replace('_', '\\_') + ' module'
101+
f.write(f'{temp}\n{"-" * len(temp)}\n\n')
102+
f.write(f'.. automodule:: {module}\n')
103+
f.write(' :members:\n')
104+
f.write(' :undoc-members:\n')
105+
f.write(' :show-inheritance:\n\n')
106+
107+
# Module contents.
108+
f.write('Module contents\n---------------\n\n')
109+
f.write(f'.. automodule:: {name}\n')
110+
f.write(' :members:\n')
111+
f.write(' :undoc-members:\n')
112+
f.write(' :show-inheritance:\n')
113+
114+
115+
def getAutoGenerated() -> List[str]:
116+
"""
117+
Retrieves the list of previously autogenerated files.
118+
"""
119+
with open(DIRECTORY / '_autogen.txt', 'r') as f:
120+
return [x.strip() for x in f if x]
121+
122+
123+
def readProject(root) -> Dict[str, Package]:
124+
"""
125+
Returns a dictionary of package names to Package instances for a project.
126+
"""
127+
initialRead = _readProject(root)
128+
return {x : _makePackage(x, y) for x, y in initialRead.items()}
129+
130+
131+
def writeAutoGenerated(files : List[str]) -> None:
132+
"""
133+
Writes the _autogen.txt file.
134+
"""
135+
with open(DIRECTORY / '_autogen.txt', 'w') as f:
136+
f.write('\n'.join(files))
137+
138+
139+
if __name__ == '__main__':
140+
run()

docs/conf.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
sys.path.insert(0, os.path.abspath(".."))
1313

1414
__author__ = 'Destiny Peterson & Matthew Walker'
15-
__version__ = '0.41.0'
15+
__version__ = '0.43.0'
1616
__year__ = '2023'
1717

1818

@@ -27,7 +27,7 @@
2727
extensions = ["sphinx.ext.todo", "sphinx.ext.viewcode", "sphinx.ext.autodoc"]
2828

2929
templates_path = ['_templates']
30-
exclude_patterns = ['_build', 'Thumbs.db', '.DS_Store']
30+
exclude_patterns = ['_build', 'Thumbs.db', '.DS_Store', '_autogen.txt']
3131

3232
# -- Options for HTML output -------------------------------------------------
3333
# https://www.sphinx-doc.org/en/master/usage/configuration.html#options-for-html-output
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
extract\_msg.attachments.custom\_att\_handler package
2+
=====================================================
3+
4+
Submodules
5+
----------
6+
7+
extract\_msg.attachments.custom\_att\_handler.custom\_handler.py module
8+
-----------------------------------------------------------------------
9+
10+
.. automodule:: extract_msg.attachments.custom_att_handler.custom_handler.py
11+
:members:
12+
:undoc-members:
13+
:show-inheritance:
14+
15+
extract\_msg.attachments.custom\_att\_handler.outlook\_image\_dib.py module
16+
---------------------------------------------------------------------------
17+
18+
.. automodule:: extract_msg.attachments.custom_att_handler.outlook_image_dib.py
19+
:members:
20+
:undoc-members:
21+
:show-inheritance:
22+
23+
Module contents
24+
---------------
25+
26+
.. automodule:: extract_msg.attachments.custom_att_handler
27+
:members:
28+
:undoc-members:
29+
:show-inheritance:

docs/extract_msg.attachments.rst

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
extract\_msg.attachments package
2+
================================
3+
4+
Subpackages
5+
-----------
6+
7+
.. toctree::
8+
:maxdepth: 4
9+
10+
extract_msg.attachments.custom_att_handler
11+
12+
Submodules
13+
----------
14+
15+
extract\_msg.attachments.attachment.py module
16+
---------------------------------------------
17+
18+
.. automodule:: extract_msg.attachments.attachment.py
19+
:members:
20+
:undoc-members:
21+
:show-inheritance:
22+
23+
extract\_msg.attachments.attachment\_base.py module
24+
---------------------------------------------------
25+
26+
.. automodule:: extract_msg.attachments.attachment_base.py
27+
:members:
28+
:undoc-members:
29+
:show-inheritance:
30+
31+
extract\_msg.attachments.broken\_att.py module
32+
----------------------------------------------
33+
34+
.. automodule:: extract_msg.attachments.broken_att.py
35+
:members:
36+
:undoc-members:
37+
:show-inheritance:
38+
39+
extract\_msg.attachments.custom\_att.py module
40+
----------------------------------------------
41+
42+
.. automodule:: extract_msg.attachments.custom_att.py
43+
:members:
44+
:undoc-members:
45+
:show-inheritance:
46+
47+
extract\_msg.attachments.emb\_msg\_att.py module
48+
------------------------------------------------
49+
50+
.. automodule:: extract_msg.attachments.emb_msg_att.py
51+
:members:
52+
:undoc-members:
53+
:show-inheritance:
54+
55+
extract\_msg.attachments.signed\_att.py module
56+
----------------------------------------------
57+
58+
.. automodule:: extract_msg.attachments.signed_att.py
59+
:members:
60+
:undoc-members:
61+
:show-inheritance:
62+
63+
extract\_msg.attachments.unsupported\_att.py module
64+
---------------------------------------------------
65+
66+
.. automodule:: extract_msg.attachments.unsupported_att.py
67+
:members:
68+
:undoc-members:
69+
:show-inheritance:
70+
71+
extract\_msg.attachments.web\_att.py module
72+
-------------------------------------------
73+
74+
.. automodule:: extract_msg.attachments.web_att.py
75+
:members:
76+
:undoc-members:
77+
:show-inheritance:
78+
79+
Module contents
80+
---------------
81+
82+
.. automodule:: extract_msg.attachments
83+
:members:
84+
:undoc-members:
85+
:show-inheritance:

docs/extract_msg.constants.rst

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
extract\_msg.constants package
2+
==============================
3+
4+
Submodules
5+
----------
6+
7+
extract\_msg.constants.ps.py module
8+
-----------------------------------
9+
10+
.. automodule:: extract_msg.constants.ps.py
11+
:members:
12+
:undoc-members:
13+
:show-inheritance:
14+
15+
extract\_msg.constants.re.py module
16+
-----------------------------------
17+
18+
.. automodule:: extract_msg.constants.re.py
19+
:members:
20+
:undoc-members:
21+
:show-inheritance:
22+
23+
extract\_msg.constants.st.py module
24+
-----------------------------------
25+
26+
.. automodule:: extract_msg.constants.st.py
27+
:members:
28+
:undoc-members:
29+
:show-inheritance:
30+
31+
Module contents
32+
---------------
33+
34+
.. automodule:: extract_msg.constants
35+
:members:
36+
:undoc-members:
37+
:show-inheritance:

docs/extract_msg.dev_classes.rst

Lines changed: 0 additions & 29 deletions
This file was deleted.

docs/extract_msg.encoding.rst

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
extract\_msg.encoding package
2+
=============================
3+
4+
Submodules
5+
----------
6+
7+
extract\_msg.encoding.utils.py module
8+
-------------------------------------
9+
10+
.. automodule:: extract_msg.encoding.utils.py
11+
:members:
12+
:undoc-members:
13+
:show-inheritance:
14+
15+
Module contents
16+
---------------
17+
18+
.. automodule:: extract_msg.encoding
19+
:members:
20+
:undoc-members:
21+
:show-inheritance:

0 commit comments

Comments
 (0)