forked from haddocking/pdb-tools
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added doctools.py utility script (haddocking#47)
* Added utility script to produce tool documentation. * Fixed whitespace bc of Flake8 * Leave the bad script alone.
- Loading branch information
1 parent
01e1eb0
commit 74de6c8
Showing
12 changed files
with
65 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
#!/usr/bin/env python | ||
|
||
""" | ||
Scrapes tool headers for documentation. | ||
""" | ||
|
||
import importlib | ||
from pathlib import Path | ||
|
||
with open('descriptions.md', 'w') as handle: | ||
|
||
import pdbtools | ||
modfile = Path(pdbtools.__file__) | ||
for f in modfile.parent.iterdir(): | ||
# ignore __init__.py and others. | ||
if f.stem.startswith('_') or f.suffix != '.py': | ||
continue | ||
|
||
# Dynamically import tool to get __doc__ | ||
name = f.stem | ||
try: | ||
tool = importlib.import_module(f'pdbtools.{name}') | ||
except ModuleNotFoundError: | ||
print(f'Could not import module: {name}') | ||
continue | ||
|
||
# Parse documentation from docstrings | ||
# Preserve white-space as best as possible. | ||
# First non-empty line is always short description. | ||
# Last lines are always licensing disclaimer | ||
summary = None | ||
long_description = [] | ||
|
||
doctext = tool.__doc__.replace('<', '<').replace('>', '>') | ||
for line in doctext.split('\n'): | ||
if summary is None and not line.strip(): | ||
continue | ||
if line.startswith('This program is part of the'): | ||
break | ||
elif summary is None: | ||
summary = line | ||
else: | ||
long_description.append(line) | ||
|
||
long_description = '\n'.join(long_description) | ||
print("<div>") | ||
print('<details>') | ||
print(f"<summary><b>{name}</b><p>{summary}</p></summary>") | ||
print(f'<span style="font-family: monospace; white-space: pre;">{long_description}</span>') | ||
print('</details>') | ||
print('</div>') | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters