Skip to content

Commit 0ea0da6

Browse files
authored
docs cli improvements (#534)
- allow changes to mkdocs.yaml to be auto detected and applied during `rats-docs serve` - allow `--dev-addr` to be specified in `rats-docs serve` for when we run more than one site at a time this should close #448
1 parent 1f20820 commit 0ea0da6

2 files changed

Lines changed: 16 additions & 10 deletions

File tree

rats-devtools/src/rats/docs/_app.py

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ class AppConfigs:
2424

2525

2626
class Application(apps.AppContainer, cli.Container, apps.PluginMixin):
27+
_dev_addr: str = "127.0.0.1:8000"
28+
2729
def execute(self) -> None:
2830
cli.create_group(click.Group("rats-docs"), self).main()
2931

@@ -62,11 +64,18 @@ def _mkdocs_serve(self) -> None:
6264
category=DeprecationWarning,
6365
stacklevel=2,
6466
)
65-
self.serve()
67+
self.serve("127.0.0.1:8000")
6668

6769
@cli.command()
68-
def serve(self) -> None:
70+
@click.option(
71+
"--dev-addr",
72+
default="127.0.0.1:8000",
73+
help="address to listen to when running local dev site",
74+
show_default=True,
75+
)
76+
def serve(self, dev_addr: str) -> None:
6977
"""Serve the mkdocs site for the project and monitor files for changes."""
78+
self._dev_addr = dev_addr
7079
self._do_mkdocs_things("serve")
7180

7281
def _do_mkdocs_things(self, cmd: str) -> None:
@@ -77,7 +86,8 @@ def _do_mkdocs_things(self, cmd: str) -> None:
7786
mkdocs_config = docs_component.find_path("mkdocs.yaml")
7887
mkdocs_staging_path = docs_component.find_path("dist/docs")
7988
site_dir_path = docs_component.find_path("dist/site")
80-
mkdocs_staging_config = docs_component.find_path("dist/mkdocs.yaml")
89+
# we append the filename because symlinks get resolved by `find_path()`
90+
mkdocs_staging_config = docs_component.find_path("dist") / "mkdocs.yaml"
8191
# clear any stale state
8292
docs_component.create_or_empty(mkdocs_staging_path)
8393
# start with the contents of our root-docs
@@ -91,14 +101,16 @@ def _do_mkdocs_things(self, cmd: str) -> None:
91101

92102
# replace the mkdocs config with a fresh version
93103
mkdocs_staging_config.unlink(missing_ok=True)
94-
docs_component.copy(mkdocs_config, mkdocs_staging_config)
104+
docs_component.symlink(mkdocs_config, mkdocs_staging_config)
95105

96106
args = [
97107
"--config-file",
98108
str(mkdocs_staging_config),
99109
]
100110
if cmd == "build":
101111
args.extend(["--site-dir", str(site_dir_path.resolve())])
112+
if cmd == "serve":
113+
args.extend(["--dev-addr", self._dev_addr])
102114

103115
docs_component.run("mkdocs", cmd, *args)
104116

rats-devtools/src/rats/projects/_component_tools.py

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import logging
22
import subprocess
33
import sys
4-
import warnings
54
from collections.abc import Mapping
65
from os import symlink
76
from pathlib import Path
@@ -118,11 +117,6 @@ def run(self, *args: str) -> None:
118117
self.exe(*args)
119118

120119
def poetry(self, *args: str) -> None:
121-
warnings.warn(
122-
"this method is deprecated, use the more general `run()` method instead.",
123-
DeprecationWarning,
124-
stacklevel=2,
125-
)
126120
if not self.is_poetry_detected():
127121
raise RuntimeError(f"cannot run poetry commands in component: {self.component_name()}")
128122

0 commit comments

Comments
 (0)