Commit 9ddc893f authored by Sli's avatar Sli

documentation: add autoreload and build for documentation server

parent 98c834b3
Pipeline #2078 passed with stage
in 45 minutes and 21 seconds
......@@ -25,13 +25,12 @@
import os
import sys
import signal
from http.server import test, CGIHTTPRequestHandler
from django.core.management.base import BaseCommand
# TODO Django 2.2 : implement autoreload following
# https://stackoverflow.com/questions/42907285/django-autoreload-add-watched-file
from django.utils import autoreload
class Command(BaseCommand):
......@@ -45,15 +44,15 @@ class Command(BaseCommand):
"addrport", nargs="?", help="Optional port number, or ipaddr:port"
)
def handle(self, *args, **kwargs):
os.chdir("doc")
def build_documentation(self):
os.chdir(os.path.join(self.project_dir, "doc"))
err = os.system("make html")
if err != 0:
self.stdout.write("A build error occured, exiting")
sys.exit(err)
self.stdout.write("A build error occured")
os.chdir("_build/html")
def start_server(self, **kwargs):
os.chdir(os.path.join(self.project_dir, "doc", "_build/html"))
addr = self.default_addr
port = self.default_port
if kwargs["addrport"]:
......@@ -69,3 +68,25 @@ class Command(BaseCommand):
sys.exit(0)
test(HandlerClass=CGIHTTPRequestHandler, port=int(port), bind=addr)
def build_and_start_server(self, **kwargs):
self.build_documentation()
self.start_server(**kwargs)
def handle(self, *args, **kwargs):
self.project_dir = os.getcwd()
signal.signal(signal.SIGTERM, lambda *args: sys.exit(0))
try:
if os.environ.get(autoreload.DJANGO_AUTORELOAD_ENV) == "true":
reloader = autoreload.get_reloader()
reloader.watch_dir(os.path.join(self.project_dir, "doc"), "**/*.rst")
autoreload.logger.info(
"Watching for file changes with %s", reloader.__class__.__name__
)
autoreload.start_django(reloader, self.build_and_start_server, **kwargs)
else:
exit_code = autoreload.restart_with_reloader()
sys.exit(exit_code)
except KeyboardInterrupt:
pass
......@@ -106,10 +106,15 @@ La documentation est automatiquement mise en ligne sur readthedocs à chaque env
Pour l'utiliser en local ou globalement pour la modifier, il existe une commande du site qui génère la documentation et lance un serveur la rendant accessible à l'adresse http://localhost:8080.
Cette commande génère la documentation à chacune de ses modifications, inutile de relancer le serveur à chaque fois.
.. sourcecode:: bash
./manage.py documentation
# Il est possible de spécifier un port et une adresse d'écoute différente
./manage.py documentation adresse:port
Lancer les tests
----------------
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment