Skip to content

Commit f1b3e0b

Browse files
authored
Update package utils and docs (#2307)
2 parents 88ab5ae + 529b93f commit f1b3e0b

File tree

7 files changed

+182
-150
lines changed

7 files changed

+182
-150
lines changed

.github/workflows/build_assets.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ jobs:
3232
with:
3333
name: nw-assets
3434
path: |
35-
novelwriter/assets/manual.pdf
35+
novelwriter/assets/manual*.pdf
3636
novelwriter/assets/sample.zip
3737
novelwriter/assets/i18n/*.qm
3838
if-no-files-found: error

docs/source/index.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ See :ref:`a_started` for more details.
4141
:hidden:
4242

4343
Main Page <self>
44-
More Documents <https://novelwriter.io/about/docs.html>
44+
More Documents <https://novelwriter.io/more/>
4545

4646
.. toctree::
4747
:maxdepth: 1

docs/source/tech_source.rst

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -153,8 +153,9 @@ You can also build a PDF manual from the documentation using the ``pkgutils.py``
153153

154154
.. code-block:: bash
155155
156-
python pkgutils.py manual
156+
python pkgutils.py docs-pdf en
157157
158-
This will build the documentation as a PDF using LaTeX. The file will then be copied into the
159-
assets folder and made available in the **Help** menu in novelWriter. The Sphinx build system has a
160-
few extra dependencies when building the PDF. Please check the `Sphinx Docs`_ for more details.
158+
This will build the English documentation as a PDF using LaTeX. The file will then be copied into
159+
the assets folder and made available in the **Help** menu in novelWriter. Replace ``en`` with
160+
``all`` to build for all languages. The Sphinx build system has a few extra dependencies when
161+
building the PDF. Please check the `Sphinx Docs`_ for more details.

novelwriter/config.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -303,7 +303,8 @@ def hasError(self) -> bool:
303303

304304
@property
305305
def pdfDocs(self) -> Path | None:
306-
return self._manuals.get(f"manual_{self.locale.name()}", self._manuals.get("manual"))
306+
"""Return the local manual PDF file, if any exist."""
307+
return self._manuals.get(f"manual_{self.locale.bcp47Name()}", self._manuals.get("manual"))
307308

308309
@property
309310
def nwLangPath(self) -> Path:

pkgutils.py

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
import utils.build_binary
3838
import utils.build_debian
3939
import utils.build_windows
40+
import utils.docs
4041
import utils.icon_themes
4142

4243
from utils.common import ROOT_DIR, SETUP_DIR, extractVersion, readFile, stripVersion, writeFile
@@ -88,13 +89,13 @@ def cleanBuildDirs(args: argparse.Namespace) -> None:
8889
print("")
8990

9091
folders = [
91-
ROOT_DIR / "build",
9292
ROOT_DIR / "build_bin",
93-
ROOT_DIR / "dist",
93+
ROOT_DIR / "build",
94+
ROOT_DIR / "dist_appimage",
9495
ROOT_DIR / "dist_bin",
9596
ROOT_DIR / "dist_deb",
96-
ROOT_DIR / "dist_minimal",
97-
ROOT_DIR / "dist_appimage",
97+
ROOT_DIR / "dist_doc",
98+
ROOT_DIR / "dist",
9899
ROOT_DIR / "novelWriter.egg-info",
99100
]
100101

@@ -211,20 +212,21 @@ def genMacOSPlist(args: argparse.Namespace) -> None:
211212
)
212213
)
213214
cmdUpdateDocsPo.add_argument("lang", nargs="+")
214-
cmdUpdateDocsPo.set_defaults(func=utils.assets.updateDocsTranslationSources)
215+
cmdUpdateDocsPo.set_defaults(func=utils.docs.updateDocsTranslationSources)
215216

216-
# Build Docs i18n Files
217-
cmdBuildU18nDocs = parsers.add_parser(
218-
"docs-lrelease", help="Build the translated PDF manual files."
217+
# Build PDF Docs
218+
cmdBuildPdfDocs = parsers.add_parser(
219+
"docs-pdf", help="Build the PDF manual files."
219220
)
220-
cmdBuildU18nDocs.add_argument("lang", nargs="+")
221-
cmdBuildU18nDocs.set_defaults(func=utils.assets.buildDocsTranslationAssets)
221+
cmdBuildPdfDocs.add_argument("lang", nargs="+")
222+
cmdBuildPdfDocs.set_defaults(func=utils.docs.buildPdfDocAssets)
222223

223-
# Build Manual
224-
cmdBuildManual = parsers.add_parser(
225-
"manual", help="Build the help documentation as a PDF (requires LaTeX)."
224+
# Build HTML Docs
225+
cmdBuildHtmlDocs = parsers.add_parser(
226+
"docs-html", help="Build the HTML docs."
226227
)
227-
cmdBuildManual.set_defaults(func=utils.assets.buildPdfManual)
228+
cmdBuildHtmlDocs.add_argument("lang", nargs="+")
229+
cmdBuildHtmlDocs.set_defaults(func=utils.docs.buildHtmlDocs)
228230

229231
# Build Sample
230232
cmdBuildSample = parsers.add_parser(
@@ -234,13 +236,13 @@ def genMacOSPlist(args: argparse.Namespace) -> None:
234236

235237
# Clean Assets
236238
cmdCleanAssets = parsers.add_parser(
237-
"clean-assets", help="Delete assets built by manual, sample and qtlrelease."
239+
"clean-assets", help="Delete assets built by docs-pdf, sample and qtlrelease."
238240
)
239241
cmdCleanAssets.set_defaults(func=utils.assets.cleanBuiltAssets)
240242

241243
# Build Assets
242244
cmdBuildAssets = parsers.add_parser(
243-
"build-assets", help="Build all assets. Includes manual, sample and qtlrelease."
245+
"build-assets", help="Build all assets. Includes docs-pdf, sample and qtlrelease."
244246
)
245247
cmdBuildAssets.set_defaults(func=utils.assets.buildAllAssets)
246248

utils/assets.py

Lines changed: 5 additions & 127 deletions
Original file line numberDiff line numberDiff line change
@@ -21,59 +21,14 @@
2121
from __future__ import annotations
2222

2323
import argparse
24-
import os
2524
import subprocess
2625
import sys
2726
import zipfile
2827

2928
from pathlib import Path
3029

3130
from utils.common import ROOT_DIR, writeFile
32-
33-
34-
def buildPdfManual(args: argparse.Namespace | None = None) -> None:
35-
"""This function will build the documentation as manual.pdf."""
36-
print("")
37-
print("Building PDF Manual")
38-
print("===================")
39-
print("")
40-
41-
buildFile = ROOT_DIR / "docs" / "build" / "latex" / "manual.pdf"
42-
finalFile = ROOT_DIR / "novelwriter" / "assets" / "manual.pdf"
43-
finalFile.unlink(missing_ok=True)
44-
45-
try:
46-
subprocess.call(["make", "clean"], cwd="docs")
47-
exCode = subprocess.call(["make", "latexpdf"], cwd="docs")
48-
if exCode == 0:
49-
print("")
50-
buildFile.rename(finalFile)
51-
else:
52-
raise Exception(f"Build returned error code {exCode}")
53-
54-
print("PDF manual build: OK")
55-
print("")
56-
57-
except Exception as exc:
58-
print("PDF manual build: FAILED")
59-
print("")
60-
print(str(exc))
61-
print("")
62-
print("Dependencies:")
63-
print(" * pip install sphinx")
64-
print(" * Package latexmk")
65-
print(" * LaTeX build system")
66-
print("")
67-
print(" On Debian/Ubuntu, install: python3-sphinx latexmk texlive texlive-latex-extra")
68-
print("")
69-
sys.exit(1)
70-
71-
if not finalFile.is_file():
72-
print("No output file was found!")
73-
print("")
74-
sys.exit(1)
75-
76-
return
31+
from utils.docs import buildPdfDocAssets
7732

7833

7934
def buildSampleZip(args: argparse.Namespace | None = None) -> None:
@@ -90,7 +45,9 @@ def buildSampleZip(args: argparse.Namespace | None = None) -> None:
9045

9146
if srcSample.is_dir():
9247
dstSample.unlink(missing_ok=True)
93-
with zipfile.ZipFile(dstSample, "w") as zipObj:
48+
with zipfile.ZipFile(
49+
dstSample, mode="w", compression=zipfile.ZIP_DEFLATED, compresslevel=3
50+
) as zipObj:
9451
print("Compressing: nwProject.nwx")
9552
zipObj.write(srcSample / "nwProject.nwx", "nwProject.nwx")
9653
for doc in (srcSample / "content").iterdir():
@@ -249,84 +206,6 @@ def buildTranslationAssets(args: argparse.Namespace | None = None) -> None:
249206
return
250207

251208

252-
def updateDocsTranslationSources(args: argparse.Namespace) -> None:
253-
"""Build the documentation .po files."""
254-
print("")
255-
print("Building Docs Translation Files")
256-
print("===============================")
257-
print("")
258-
259-
docsDir = ROOT_DIR / "docs"
260-
locsDir = ROOT_DIR / "docs" / "source" / "locales"
261-
locsDir.mkdir(exist_ok=True)
262-
263-
print("Generating POT Files")
264-
subprocess.call(["make", "gettext"], cwd=docsDir)
265-
print("")
266-
267-
lang = args.lang
268-
update = []
269-
if lang == ["all"]:
270-
update = [i.stem for i in locsDir.iterdir() if i.is_dir()]
271-
else:
272-
update = lang
273-
274-
print("Generating PO Files")
275-
print("Languages: ", update)
276-
print("")
277-
278-
for code in update:
279-
subprocess.call(["sphinx-intl", "update", "-p", "build/gettext", "-l", code], cwd=docsDir)
280-
print("")
281-
282-
print("Done")
283-
print("")
284-
285-
return
286-
287-
288-
def buildDocsTranslationAssets(args: argparse.Namespace | None = None) -> None:
289-
"""Build the documentation i18n PDF files."""
290-
from PyQt6.QtCore import QLocale
291-
292-
print("")
293-
print("Building Docs Manuals")
294-
print("=====================")
295-
print("")
296-
297-
docsDir = ROOT_DIR / "docs"
298-
locsDir = ROOT_DIR / "docs" / "source" / "locales"
299-
pdfFile = ROOT_DIR / "docs" / "build" / "latex" / "manual.pdf"
300-
locsDir.mkdir(exist_ok=True)
301-
302-
lang = args.lang if args else ["all"]
303-
build = []
304-
if lang == ["all"]:
305-
build = [i.stem for i in locsDir.iterdir() if i.is_dir()]
306-
else:
307-
build = lang
308-
309-
for code in build:
310-
data = (locsDir / f"authors_{code}.conf").read_text(encoding="utf-8")
311-
authors = [x for x in data.splitlines() if x and not x.startswith("#")]
312-
env = os.environ.copy()
313-
env["SPHINX_I18N_AUTHORS"] = ", ".join(authors)
314-
exCode = subprocess.call(
315-
f"make -e SPHINXOPTS=\"-D language='{code}'\" clean latexpdf",
316-
cwd=docsDir, env=env, shell=True
317-
)
318-
if exCode == 0:
319-
print("")
320-
name = f"manual_{QLocale(code).name()}.pdf"
321-
pdfFile.rename(ROOT_DIR / "novelwriter" / "assets" / name)
322-
else:
323-
raise Exception(f"Build returned error code {exCode}")
324-
325-
print("")
326-
327-
return
328-
329-
330209
def cleanBuiltAssets(args: argparse.Namespace | None = None) -> None:
331210
"""Remove assets built by this script."""
332211
print("")
@@ -350,8 +229,7 @@ def cleanBuiltAssets(args: argparse.Namespace | None = None) -> None:
350229
def buildAllAssets(args: argparse.Namespace) -> None:
351230
"""Build all assets."""
352231
cleanBuiltAssets()
353-
buildPdfManual()
354232
buildSampleZip()
355233
buildTranslationAssets()
356-
buildDocsTranslationAssets()
234+
buildPdfDocAssets()
357235
return

0 commit comments

Comments
 (0)