Skip to content

Commit d551333

Browse files
authored
Merge pull request #24 from haddocking/more-releas-prep
Add docs/cli.md
2 parents 72d578c + ab7da7d commit d551333

File tree

5 files changed

+85
-2
lines changed

5 files changed

+85
-2
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,3 +73,4 @@ IDEAS.md
7373
/docs/alphafold_files/
7474
/docs/pdb_files/
7575
/docs/density_filtered/
76+
/docs/cli.md

docs/hooks.py

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
"""MkDocs hooks for generating CLI documentation."""
2+
3+
import argparse
4+
import io
5+
import logging
6+
from pathlib import Path
7+
8+
from protein_detective.cli import make_parser
9+
10+
logger = logging.getLogger("mkdocs.plugins.argparse")
11+
12+
13+
def generate_cli_docs() -> str:
14+
"""Generate CLI documentation markdown."""
15+
parser = make_parser()
16+
17+
# Capture main help
18+
help_output = io.StringIO()
19+
parser.print_help(help_output)
20+
main_help = help_output.getvalue()
21+
22+
# Start building markdown
23+
markdown_lines = [
24+
"# CLI Reference\n",
25+
"Documentation for the `protein-detective` CLI commands.\n",
26+
"## Main Command\n",
27+
"```shell",
28+
"protein-detective --help",
29+
main_help,
30+
"```\n## Subcommands\n",
31+
]
32+
33+
# Get subcommands and their help
34+
subparsers_actions = [action for action in parser._actions if isinstance(action, argparse._SubParsersAction)]
35+
36+
if subparsers_actions:
37+
subparsers_action = subparsers_actions[0]
38+
for sub_command, subparser in subparsers_action.choices.items():
39+
# Capture subcommand help
40+
help_output = io.StringIO()
41+
subparser.print_help(help_output)
42+
subcommand_help = help_output.getvalue()
43+
44+
markdown_lines.extend(
45+
[
46+
f"### {sub_command}\n",
47+
"```shell",
48+
f"$ protein-detective {sub_command} --help",
49+
subcommand_help,
50+
"```\n",
51+
]
52+
)
53+
54+
return "\n".join(markdown_lines)
55+
56+
57+
def on_pre_build(**_kwargs):
58+
"""Generate CLI documentation before building the docs."""
59+
docs_content = generate_cli_docs()
60+
61+
# Check if content has changed before writing
62+
docs_dir = Path(__file__).parent
63+
cli_md_path = docs_dir / "cli.md"
64+
65+
# Only write if content is different to avoid rebuild loops
66+
if not cli_md_path.exists() or cli_md_path.read_text() != docs_content:
67+
cli_md_path.write_text(docs_content)
68+
logger.info("CLI documentation generated/updated successfully")
69+
else:
70+
logger.info("CLI documentation unchanged, skipping write")

mkdocs.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@ site_name: Protein Detective
22
site_url: https://bonvinlab.org/protein_detective
33
repo_url: https://github.com/haddocking/protein-detective
44
watch: [mkdocs.yml, README.md, src/protein_detective]
5+
exclude_docs: |
6+
hooks.py
7+
hooks:
8+
- docs/hooks.py
59
theme:
610
name: mkdocs
711
color_mode: auto
@@ -33,6 +37,7 @@ markdown_extensions:
3337

3438
nav:
3539
- Home: index.md
40+
- CLI Reference: cli.md
3641
- Notebooks:
3742
- Retrieve: uniprot.ipynb
3843
- AlphaFold: alphafold.ipynb

src/protein_detective/cli.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -132,13 +132,18 @@ def handle_prune_pdbs(args):
132132
print(f"Written {nr_files} PDB files to {single_chain_dir} directory.")
133133

134134

135-
def main():
136-
parser = argparse.ArgumentParser(description="Protein Detective CLI")
135+
def make_parser() -> argparse.ArgumentParser:
136+
parser = argparse.ArgumentParser(description="Protein Detective CLI", prog="protein-detective")
137137
subparsers = parser.add_subparsers(dest="command", required=True)
138138
add_search_parser(subparsers)
139139
add_retrieve_parser(subparsers)
140140
add_density_filter_parser(subparsers)
141141
add_prune_pdbs_parser(subparsers)
142+
return parser
143+
144+
145+
def main():
146+
parser = make_parser()
142147

143148
args = parser.parse_args()
144149

src/protein_detective/workflow.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
"""Workflow steps"""
2+
13
from dataclasses import dataclass
24
from pathlib import Path
35
from typing import Literal

0 commit comments

Comments
 (0)