Skip to content

Commit 1718fb1

Browse files
authored
Merge pull request #2 from mmacy/examples-add
autogen examples pages
2 parents a91c142 + 6f43b91 commit 1718fb1

File tree

12 files changed

+84
-2
lines changed

12 files changed

+84
-2
lines changed

docs/connect.md

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
11
# Connect
22

3-
--8<-- "./README.md:connect"
3+
--8<-- "./README.md:connect"
4+
5+
## Examples
6+
7+
```python
8+
--8<-- "./examples/demo.py"
9+
```

docs/examples/assistant.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# assistant.py
2+
3+
```python
4+
--8<-- "./examples/assistant.py"
5+
```

docs/examples/async_demo.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# async_demo.py
2+
3+
```python
4+
--8<-- "./examples/async_demo.py"
5+
```

docs/examples/audio.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# audio.py
2+
3+
```python
4+
--8<-- "./examples/audio.py"
5+
```

docs/examples/azure.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# azure.py
2+
3+
```python
4+
--8<-- "./examples/azure.py"
5+
```

docs/examples/azure_ad.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# azure_ad.py
2+
3+
```python
4+
--8<-- "./examples/azure_ad.py"
5+
```

docs/examples/demo.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# demo.py
2+
3+
```python
4+
--8<-- "./examples/demo.py"
5+
```

docs/examples/module_client.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# module_client.py
2+
3+
```python
4+
--8<-- "./examples/module_client.py"
5+
```

docs/examples/picture.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# picture.py
2+
3+
```python
4+
--8<-- "./examples/picture.py"
5+
```

docs/examples/streaming.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# streaming.py
2+
3+
```python
4+
--8<-- "./examples/streaming.py"
5+
```

mkdocs.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ plugins:
8080
handlers:
8181
python:
8282
paths: [src]
83-
load_external_modules: true # 'true' picks up __all__ from __init__.py files
83+
load_external_modules: false # 'true' picks up __all__ from __init__.py files
8484
import:
8585
- https://docs.python.org/3/objects.inv
8686
- https://docs.pydantic.dev/2.4/objects.inv
@@ -127,4 +127,5 @@ nav:
127127
- error-handling.md
128128
- debugging.md
129129
- advanced.md
130+
- Examples: examples/
130131
- API reference: reference/

scripts/gen_examples_md.py

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
#!/usr/bin/env python3
2+
3+
import argparse
4+
import os
5+
import glob
6+
7+
def main():
8+
parser = argparse.ArgumentParser(description="Generate Markdown files for Python scripts.")
9+
parser.add_argument("--dir", "-d", default="./examples", help="Directory to search for Python files.")
10+
parser.add_argument("--out-dir", "-o", default="./docs/examples", help="Directory to output Markdown files.")
11+
args = parser.parse_args()
12+
13+
# Ensure output directory exists
14+
os.makedirs(args.out_dir, exist_ok=True)
15+
16+
# Get list of *.py files in the specified directory
17+
python_files = glob.glob(os.path.join(args.dir, "*.py"))
18+
19+
for py_file in python_files:
20+
py_file_name = os.path.basename(py_file)
21+
md_file_name = os.path.splitext(py_file_name)[0] + ".md"
22+
md_file_path = os.path.join(args.out_dir, md_file_name)
23+
24+
# Create and write to the corresponding *.md file
25+
with open(md_file_path, 'w') as md_file:
26+
md_file.write(f"# {py_file_name}\n\n")
27+
md_file.write(f"```python\n--8<-- \"./examples/{py_file_name}\"\n```")
28+
29+
if __name__ == "__main__":
30+
main()

0 commit comments

Comments
 (0)