Skip to content

Commit 421aae7

Browse files
committed
ci: update config and add watch dog
1 parent 9679da6 commit 421aae7

File tree

4 files changed

+64
-89
lines changed

4 files changed

+64
-89
lines changed

Taskfile.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ tasks:
1414
desc: "Clean up old build files"
1515
cmds:
1616
- echo "Cleaning build directories..."
17-
- rm -r -Force {{pyproject_dir}}/dist {{pyproject_dir}}/*.egg-info {{pyproject_dir}}/.pytest_cache
17+
- rm -r -Force {{.pyproject_dir}}/dist {{.pyproject_dir}}/*.egg-info {{.pyproject_dir}}/.pytest_cache
1818

1919
version:
2020
desc: "Run semantic-release to determine and bump the version"
@@ -40,8 +40,8 @@ tasks:
4040
package_path: "mkdocs-obsidian-wikilinks"
4141
mkdocs_path: "../mara-li"
4242
cmds:
43-
- echo "Starting Watchdog for {{package_path}} with MkDocs at {{mkdocs_path}}..."
44-
- uv python watch.py {{package_path}} {{mkdocs_path}}
43+
- echo "Starting Watchdog for {{.package_path}} with MkDocs at {{.mkdocs_path}}..."
44+
- uv python watch.py {{.package_path}} {{.mkdocs_path}}
4545

4646
release:
4747
desc: "Perform a full release: version bump, build, and publish"

pyproject.toml

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
name = "mkdocs-embed-file-plugin"
33
version = "2.0.10"
44
description = "A plugin to quote file from docs"
5-
readme = "README.md"
65
requires-python = ">=3.13"
76
dependencies = [
87
"mkdocs",
@@ -18,7 +17,7 @@ dependencies = [
1817
authors = [
1918
{ name = "Mara-Li", email = "mara-li@outlook.fr" }
2019
]
21-
license = "AGPL"
20+
license = "AGPL-3.0-or-later"
2221
readme = "README.md"
2322
keywords = [
2423
"obsidian",
@@ -54,4 +53,13 @@ packages = ["mkdocs_embed_file_plugins"]
5453
homepage = "https://github.com/ObsidianPublisher/mkdocs-embed_file-plugin"
5554

5655
[project.entry-points."mkdocs.plugins"]
57-
embed_file = "mkdocs_embed_file_plugins.plugin:EmbedFile"
56+
embed_file = "mkdocs_embed_file_plugins.plugin:EmbedFile"
57+
58+
[dependency-groups]
59+
dev = [
60+
"ruff>=0.1.0",
61+
"watchdog>=2.1.6",
62+
"python-semantic-release>=9.15.2",
63+
"build>=0.6.0",
64+
"rich>=13.9.4",
65+
]

setup.py

Lines changed: 0 additions & 59 deletions
This file was deleted.

watch.py

Lines changed: 50 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,14 @@
1+
import threading
2+
13
from watchdog.observers import Observer
24
from watchdog.events import FileSystemEventHandler
35
import subprocess
46
import os
57
import time
68
import signal
9+
from pathlib import Path
10+
from rich.console import Console
11+
from rich.panel import Panel
712

813
# parse arg
914
import argparse
@@ -12,51 +17,77 @@
1217
parser.add_argument("package_path", type = str, help = "Path to the package to watch.")
1318
parser.add_argument("mkdocs_path", type = str, help = "Path to the MkDocs folder.")
1419
args = parser.parse_args()
15-
package_path = args.package_path
16-
mkdocs_path = args.mkdocs_path
20+
package_path = Path(args.package_path)
21+
mkdocs_path = Path(args.mkdocs_path)
22+
console = Console()
1723

1824

1925
class PackageWatchHandler(FileSystemEventHandler) :
2026
def __init__(self, package_path, mkdocs_path) :
2127
self.package_path = package_path
2228
self.mkdocs_path = mkdocs_path
2329
self.mkdocs_process = None
30+
self.mkdocs_process = None
31+
self.log_thread = None
32+
self.stop_logging = False
33+
34+
def log_output(self, process) :
35+
"""Thread for logging MkDocs output with Rich."""
36+
while process.poll() is None : # Check if process is still running
37+
line = process.stdout.readline()
38+
if line :
39+
# Utilise Rich pour afficher les logs stylisés
40+
if "ERROR" in line :
41+
console.log(f"[bold red][MkDocs ERROR][/bold red]: {line.strip()}")
42+
elif "WARNING" in line :
43+
console.log(f"[bold yellow][MkDocs WARNING][/bold yellow]: {line.strip()}")
44+
else :
45+
console.log(f"[bold green][MkDocs][/bold green]: {line.strip()}")
2446

2547
def start_mkdocs(self) :
2648
"""Démarre le serveur MkDocs avec python -m mkdocs."""
27-
print("Starting MkDocs server...")
49+
console.print(Panel(f"Starting MkDocs server for {self.mkdocs_path}...", style = "bold blue"))
2850
self.mkdocs_process = subprocess.Popen(
29-
["python", "-m", "mkdocs", "serve"],
51+
["uv", "run", "mkdocs", "--color", "serve"],
3052
cwd = self.mkdocs_path,
3153
stdout = subprocess.PIPE,
32-
stderr = subprocess.PIPE,
33-
text = True,
54+
stderr = subprocess.STDOUT,
55+
universal_newlines = True,
56+
bufsize = 1,
57+
)
58+
self.stop_logging = False
59+
self.log_thread = threading.Thread(target = self.log_output, args = (self.mkdocs_process,))
60+
self.log_thread.start()
61+
console.print(
62+
Panel("MkDocs server started at [bold blue]https://127.0.0.1:8000[/bold blue].", style = "bold green")
3463
)
35-
print("MkDocs server started.")
3664

3765
def stop_mkdocs(self) :
38-
"""Arrête le serveur MkDocs proprement."""
66+
"""Stop the MkDocs server."""
3967
if self.mkdocs_process :
40-
print("Stopping MkDocs server...")
68+
console.print(Panel("Stopping MkDocs server...", style = "bold red"))
69+
self.stop_logging = True
4170
self.mkdocs_process.terminate()
4271
try :
4372
self.mkdocs_process.wait(timeout = 5)
4473
except subprocess.TimeoutExpired :
4574
os.kill(self.mkdocs_process.pid, signal.SIGKILL)
46-
print("MkDocs server stopped.")
75+
if self.log_thread :
76+
self.log_thread.join()
4777
self.mkdocs_process = None
78+
console.print(Panel("MkDocs server stopped.", style = "bold red"))
4879

4980
def restart_mkdocs(self) :
50-
"""Redémarre le serveur MkDocs."""
81+
"""Restart the MkDocs server."""
5182
self.stop_mkdocs()
5283
self.start_mkdocs()
5384

5485
def on_any_event(self, event) :
55-
"""Réagit aux modifications de fichiers."""
86+
"""React to file changes."""
5687
if event.is_directory or not event.src_path.endswith(".py") :
5788
return
58-
print(f"Change detected in {event.src_path}. Reinstalling package...")
59-
subprocess.run(["pip", "install", "-e", self.package_path], check = True)
89+
console.print(Panel(f"Change detected in {event.src_path}. Reinstalling package...", style = "bold yellow"))
90+
subprocess.run(["uv", "pip", "install", "-e", self.package_path], check = True)
6091
self.restart_mkdocs()
6192

6293

@@ -66,27 +97,22 @@ def on_any_event(self, event) :
6697

6798
# Vérifie si le dossier MkDocs existe
6899
if not os.path.isdir(mkdocs_path) :
69-
print(f"Error: MkDocs path '{mkdocs_path}' does not exist.")
100+
console.print(f"[bold red]Error:[/bold red] MkDocs path '{mkdocs_path}' does not exist.")
70101
exit(1)
71102

72103
event_handler = PackageWatchHandler(package_path, mkdocs_path)
73104
observer = Observer()
74105
observer.schedule(event_handler, package_path, recursive = True)
75106

76-
print(f"Watching for changes in {package_path}...")
77-
event_handler.start_mkdocs() # Lancer MkDocs au début
107+
console.print(f"[bold green]Watching for changes in {package_path}...[/bold green]")
108+
event_handler.start_mkdocs()
78109
observer.start()
79110

80111
try :
81112
while True :
82-
# Lire les logs de MkDocs pendant que le script tourne
83-
if event_handler.mkdocs_process :
84-
output = event_handler.mkdocs_process.stdout.readline()
85-
if output :
86-
print(f"[MkDocs]: {output.strip()}")
87113
time.sleep(1)
88114
except KeyboardInterrupt :
89-
print("Shutting down...")
115+
console.print("[bold red]Shutting down...[/bold red]")
90116
observer.stop()
91117
event_handler.stop_mkdocs()
92-
observer.join()
118+
observer.join()

0 commit comments

Comments
 (0)