annotate tasks/task_generate_doc.py @ 20:a24d362796be

use python module to run sphinx: this way we are sure to run the right version with right Python environment.
author Goffi <goffi@goffi.org>
date Tue, 30 Nov 2021 17:38:36 +0100
parents b5fc67c97c50
children 5fd933e238bb
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
6
9ce41ef66dfa python 3 port
Goffi <goffi@goffi.org>
parents: 0
diff changeset
1 #!/ur/bin/env python3
0
09d66acc7c73 initial commit, website first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
2
20
a24d362796be use python module to run sphinx:
Goffi <goffi@goffi.org>
parents: 7
diff changeset
3 import sys
0
09d66acc7c73 initial commit, website first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
4 import os.path
09d66acc7c73 initial commit, website first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
5 from sat.core.i18n import _
09d66acc7c73 initial commit, website first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
6 from sat.core.log import getLogger
09d66acc7c73 initial commit, website first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
7 from sat.tools.common import regex
7
b5fc67c97c50 tasks: updated tasks following changes in Libervia
Goffi <goffi@goffi.org>
parents: 6
diff changeset
8 from libervia.server.tasks import task
0
09d66acc7c73 initial commit, website first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
9
09d66acc7c73 initial commit, website first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
10
7
b5fc67c97c50 tasks: updated tasks following changes in Libervia
Goffi <goffi@goffi.org>
parents: 6
diff changeset
11 log = getLogger(__name__)
0
09d66acc7c73 initial commit, website first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
12
09d66acc7c73 initial commit, website first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
13
7
b5fc67c97c50 tasks: updated tasks following changes in Libervia
Goffi <goffi@goffi.org>
parents: 6
diff changeset
14 class Task(task.Task):
b5fc67c97c50 tasks: updated tasks following changes in Libervia
Goffi <goffi@goffi.org>
parents: 6
diff changeset
15 DOC_DIRS_DEFAULT = ('doc', 'docs')
0
09d66acc7c73 initial commit, website first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
16
7
b5fc67c97c50 tasks: updated tasks following changes in Libervia
Goffi <goffi@goffi.org>
parents: 6
diff changeset
17 def prepare(self):
b5fc67c97c50 tasks: updated tasks following changes in Libervia
Goffi <goffi@goffi.org>
parents: 6
diff changeset
18 to_watch = set()
b5fc67c97c50 tasks: updated tasks following changes in Libervia
Goffi <goffi@goffi.org>
parents: 6
diff changeset
19 # root documentation
b5fc67c97c50 tasks: updated tasks following changes in Libervia
Goffi <goffi@goffi.org>
parents: 6
diff changeset
20 self.doc_path = self.getConfig("doc_path")
b5fc67c97c50 tasks: updated tasks following changes in Libervia
Goffi <goffi@goffi.org>
parents: 6
diff changeset
21 if self.doc_path is not None:
b5fc67c97c50 tasks: updated tasks following changes in Libervia
Goffi <goffi@goffi.org>
parents: 6
diff changeset
22 to_watch.add(self.doc_path)
b5fc67c97c50 tasks: updated tasks following changes in Libervia
Goffi <goffi@goffi.org>
parents: 6
diff changeset
23 # sub docs will be generated before the root documentation
b5fc67c97c50 tasks: updated tasks following changes in Libervia
Goffi <goffi@goffi.org>
parents: 6
diff changeset
24 self.sub_docs = self.getConfig("sub_docs_dict", value_type="path")
b5fc67c97c50 tasks: updated tasks following changes in Libervia
Goffi <goffi@goffi.org>
parents: 6
diff changeset
25 if self.sub_docs is not None:
b5fc67c97c50 tasks: updated tasks following changes in Libervia
Goffi <goffi@goffi.org>
parents: 6
diff changeset
26 for d in list(self.sub_docs.values()):
b5fc67c97c50 tasks: updated tasks following changes in Libervia
Goffi <goffi@goffi.org>
parents: 6
diff changeset
27 to_watch.add(d)
b5fc67c97c50 tasks: updated tasks following changes in Libervia
Goffi <goffi@goffi.org>
parents: 6
diff changeset
28 self.WATCH_DIRS = list(to_watch)
0
09d66acc7c73 initial commit, website first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
29
7
b5fc67c97c50 tasks: updated tasks following changes in Libervia
Goffi <goffi@goffi.org>
parents: 6
diff changeset
30 async def start(self):
b5fc67c97c50 tasks: updated tasks following changes in Libervia
Goffi <goffi@goffi.org>
parents: 6
diff changeset
31 if self.doc_path is None:
b5fc67c97c50 tasks: updated tasks following changes in Libervia
Goffi <goffi@goffi.org>
parents: 6
diff changeset
32 # we check if there is documentation inside the site
b5fc67c97c50 tasks: updated tasks following changes in Libervia
Goffi <goffi@goffi.org>
parents: 6
diff changeset
33 for dirname in self.DOC_DIRS_DEFAULT:
b5fc67c97c50 tasks: updated tasks following changes in Libervia
Goffi <goffi@goffi.org>
parents: 6
diff changeset
34 path = os.path.join(self.site_path, dirname)
b5fc67c97c50 tasks: updated tasks following changes in Libervia
Goffi <goffi@goffi.org>
parents: 6
diff changeset
35 conf_file = os.path.join(path, 'conf.py')
b5fc67c97c50 tasks: updated tasks following changes in Libervia
Goffi <goffi@goffi.org>
parents: 6
diff changeset
36 if os.path.isdir(path) and os.path.exists(conf_file):
b5fc67c97c50 tasks: updated tasks following changes in Libervia
Goffi <goffi@goffi.org>
parents: 6
diff changeset
37 self.doc_path = path
b5fc67c97c50 tasks: updated tasks following changes in Libervia
Goffi <goffi@goffi.org>
parents: 6
diff changeset
38 break
0
09d66acc7c73 initial commit, website first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
39
7
b5fc67c97c50 tasks: updated tasks following changes in Libervia
Goffi <goffi@goffi.org>
parents: 6
diff changeset
40 if self.doc_path is None and self.sub_docs is None:
b5fc67c97c50 tasks: updated tasks following changes in Libervia
Goffi <goffi@goffi.org>
parents: 6
diff changeset
41 log.info("No documentation found for {site_name}, skipping".format(
b5fc67c97c50 tasks: updated tasks following changes in Libervia
Goffi <goffi@goffi.org>
parents: 6
diff changeset
42 site_name = self.site_name))
b5fc67c97c50 tasks: updated tasks following changes in Libervia
Goffi <goffi@goffi.org>
parents: 6
diff changeset
43 return
0
09d66acc7c73 initial commit, website first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
44
7
b5fc67c97c50 tasks: updated tasks following changes in Libervia
Goffi <goffi@goffi.org>
parents: 6
diff changeset
45 # we first generate the sub documentations
b5fc67c97c50 tasks: updated tasks following changes in Libervia
Goffi <goffi@goffi.org>
parents: 6
diff changeset
46 for name, sub_doc_path in list(self.sub_docs.items()):
b5fc67c97c50 tasks: updated tasks following changes in Libervia
Goffi <goffi@goffi.org>
parents: 6
diff changeset
47 sub_dir = regex.pathEscape(name or '')
b5fc67c97c50 tasks: updated tasks following changes in Libervia
Goffi <goffi@goffi.org>
parents: 6
diff changeset
48 build_path = os.path.join(self.build_path, 'doc', sub_dir)
20
a24d362796be use python module to run sphinx:
Goffi <goffi@goffi.org>
parents: 7
diff changeset
49 await self.runCommand(
a24d362796be use python module to run sphinx:
Goffi <goffi@goffi.org>
parents: 7
diff changeset
50 sys.executable, "-m", "sphinx", sub_doc_path, build_path,
a24d362796be use python module to run sphinx:
Goffi <goffi@goffi.org>
parents: 7
diff changeset
51 )
0
09d66acc7c73 initial commit, website first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
52
7
b5fc67c97c50 tasks: updated tasks following changes in Libervia
Goffi <goffi@goffi.org>
parents: 6
diff changeset
53 # then the root one
b5fc67c97c50 tasks: updated tasks following changes in Libervia
Goffi <goffi@goffi.org>
parents: 6
diff changeset
54 if self.doc_path is not None:
b5fc67c97c50 tasks: updated tasks following changes in Libervia
Goffi <goffi@goffi.org>
parents: 6
diff changeset
55 build_path = os.path.join(self.build_path, 'doc')
20
a24d362796be use python module to run sphinx:
Goffi <goffi@goffi.org>
parents: 7
diff changeset
56 await self.runCommand(
a24d362796be use python module to run sphinx:
Goffi <goffi@goffi.org>
parents: 7
diff changeset
57 sys.executable, "-m", "sphinx", self.doc_path, build_path,
a24d362796be use python module to run sphinx:
Goffi <goffi@goffi.org>
parents: 7
diff changeset
58 )
7
b5fc67c97c50 tasks: updated tasks following changes in Libervia
Goffi <goffi@goffi.org>
parents: 6
diff changeset
59
b5fc67c97c50 tasks: updated tasks following changes in Libervia
Goffi <goffi@goffi.org>
parents: 6
diff changeset
60 log.info(_("documentation has been generated"))