Skip to content

Commit 7f38b65

Browse files
committed
Only run HTTP with --serve; use --open for browser
1 parent 91a073a commit 7f38b65

2 files changed

Lines changed: 15 additions & 6 deletions

File tree

README.md

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,14 @@ The script uses only the standard library and `requests`, so in most
99
environments (e.g. Ubuntu) you can just run the script in your shell:
1010

1111
```
12+
# Open docs in web browser
13+
./fetch_python_docs.py --open
14+
# Start the web server but don't open anything
1215
./fetch_python_docs.py --serve
16+
# Just downlaod/extract docs
17+
./fetch_python_docs.py
1318
```
1419

15-
Omit `--serve` to only download and extract.
16-
1720
## Why not just use `pydoc -b`?
1821

1922
The color scheme.

fetch_python_docs.py

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,12 @@
1818
parser = argparse.ArgumentParser(
1919
description="Idempotently download/serve Python docs from a local copy"
2020
)
21-
parser.add_argument("--serve", action="store_true")
21+
parser.add_argument(
22+
"--serve", action="store_true", help="Serve docs over HTTP on port 8004"
23+
)
24+
parser.add_argument(
25+
"--open", action="store_true", help="Serve and open the docs in the browser"
26+
)
2227
parsed = parser.parse_args()
2328

2429
major, minor, *_ = sys.version_info
@@ -46,14 +51,15 @@
4651
f.extractall(path=HERE, filter="data") # Extracting HERE creates outdir
4752
assert (outdir / "index.html").is_file()
4853

49-
if parsed.serve:
54+
if parsed.serve or parsed.open:
5055
# Use a different port from 8000 to avoid conflicting with other
5156
# instances of http.server
5257
server = subprocess.Popen(
5358
[sys.executable, "-m", "http.server", "-d", outdir.absolute(), "8004"]
5459
)
55-
time.sleep(0.5)
56-
webbrowser.open("http://localhost:8004")
60+
if parsed.open:
61+
time.sleep(0.5)
62+
webbrowser.open("http://localhost:8004")
5763

5864
try:
5965
server.wait()

0 commit comments

Comments
 (0)