Improve build code

This commit is contained in:
Veronica Berglyd Olsen
2025-06-10 00:08:48 +02:00
parent 635493f1c1
commit d61329a4f3
5 changed files with 34 additions and 48 deletions
+2
View File
@@ -8,6 +8,8 @@ jobs:
buildLinux-AppImage: buildLinux-AppImage:
needs: buildAssets needs: buildAssets
# Needs to stay on 22.04 as long as we're using manylinux_2_28
# as libxcb-cursor0 in 22.04 supports glibc >= 2.17
runs-on: ubuntu-22.04 runs-on: ubuntu-22.04
env: env:
PYTHON_VERSION: "3.13" PYTHON_VERSION: "3.13"
+3 -4
View File
@@ -24,12 +24,11 @@ import argparse
import datetime import datetime
import email.utils import email.utils
import shutil import shutil
import subprocess
import sys import sys
from utils.common import ( from utils.common import (
ROOT_DIR, SETUP_DIR, checkAssetsExist, copyPackageFiles, copySourceCode, ROOT_DIR, SETUP_DIR, checkAssetsExist, copyPackageFiles, copySourceCode,
extractVersion, makeCheckSum, toUpload, writeFile extractVersion, makeCheckSum, systemCall, toUpload, writeFile
) )
SIGN_KEY = "D6A9F6B8F227CF7C6F6D1EE84DBBE4B734B0BD08" SIGN_KEY = "D6A9F6B8F227CF7C6F6D1EE84DBBE4B734B0BD08"
@@ -134,10 +133,10 @@ def makeDebianPackage(
signArgs = [f"-k{signKey}"] signArgs = [f"-k{signKey}"]
if sourceBuild: if sourceBuild:
subprocess.call(["debuild", "-S", *signArgs], cwd=outDir) systemCall(["debuild", "-S", *signArgs], cwd=outDir)
toUpload(bldDir / f"{bldPkg}.tar.xz") toUpload(bldDir / f"{bldPkg}.tar.xz")
else: else:
subprocess.call(["dpkg-buildpackage", *signArgs], cwd=outDir) systemCall(["dpkg-buildpackage", *signArgs], cwd=outDir)
shutil.copyfile(bldDir / f"{bldPkg}.tar.xz", bldDir / f"{bldPkg}.debian.tar.xz") shutil.copyfile(bldDir / f"{bldPkg}.tar.xz", bldDir / f"{bldPkg}.debian.tar.xz")
toUpload(bldDir / f"{bldPkg}.debian.tar.xz") toUpload(bldDir / f"{bldPkg}.debian.tar.xz")
toUpload(bldDir / f"{bldPkg}_all.deb") toUpload(bldDir / f"{bldPkg}_all.deb")
+5 -20
View File
@@ -23,7 +23,6 @@ from __future__ import annotations
import argparse import argparse
import compileall import compileall
import shutil import shutil
import subprocess
import sys import sys
import urllib.request import urllib.request
import zipfile import zipfile
@@ -32,7 +31,7 @@ from pathlib import Path
from utils.common import ( from utils.common import (
ROOT_DIR, SETUP_DIR, copySourceCode, extractVersion, readFile, ROOT_DIR, SETUP_DIR, copySourceCode, extractVersion, readFile,
removeRedundantQt, writeFile removeRedundantQt, systemCall, writeFile
) )
@@ -89,20 +88,11 @@ def embedPython(bldDir: Path, outDir: Path) -> None:
def installRequirements(libDir: Path) -> None: def installRequirements(libDir: Path) -> None:
"""Install dependencies.""" """Install dependencies."""
print("Install dependencies ...") print("Install dependencies ...")
systemCall([
try: sys.executable, "-m", "pip", "install", "-r", "requirements.txt", "--target", libDir
subprocess.call([ ])
sys.executable, "-m",
"pip", "install", "-r", "requirements.txt", "--target", str(libDir)
])
except Exception as exc:
print("Failed with error:")
print(str(exc))
sys.exit(1)
print("Done") print("Done")
print("") print("")
return return
@@ -162,12 +152,7 @@ def main(args: argparse.Namespace) -> None:
writeFile(ROOT_DIR / "setup.iss", issData) writeFile(ROOT_DIR / "setup.iss", issData)
print("") print("")
try: systemCall(["iscc", "setup.iss"])
subprocess.call(["iscc", "setup.iss"])
except Exception as exc:
print("Inno Setup failed with error:")
print(str(exc))
sys.exit(1)
print("") print("")
print("Done") print("Done")
+21 -21
View File
@@ -51,11 +51,11 @@ def extractVersion(beQuiet: bool = False) -> tuple[str, str, str]:
if aLine.startswith("__date__"): if aLine.startswith("__date__"):
relDate = getValue(aLine) relDate = getValue(aLine)
except Exception as exc: except Exception as exc:
print(f"Could not read file: {initFile}") print(f"Could not read file: {initFile}", flush=True)
print(str(exc)) print(str(exc), flush=True)
if not beQuiet: if not beQuiet:
print(f"novelWriter version: {numVers} ({hexVers}) at {relDate}") print(f"novelWriter version: {numVers} ({hexVers}) at {relDate}", flush=True)
return numVers, hexVers, relDate return numVers, hexVers, relDate
@@ -78,16 +78,16 @@ def copySourceCode(dst: Path) -> None:
for item in src.glob("**/*"): for item in src.glob("**/*"):
relSrc = item.relative_to(ROOT_DIR) relSrc = item.relative_to(ROOT_DIR)
if item.suffix in (".pyc", ".pyo"): if item.suffix in (".pyc", ".pyo"):
print("Ignored:", relSrc) print("Ignored:", relSrc, flush=True)
continue continue
if item.parent.is_dir() and item.parent.name != "__pycache__": if item.parent.is_dir() and item.parent.name != "__pycache__":
dstDir = dst / relSrc.parent dstDir = dst / relSrc.parent
if not dstDir.exists(): if not dstDir.exists():
dstDir.mkdir(parents=True) dstDir.mkdir(parents=True)
print("Created:", dstDir.relative_to(ROOT_DIR)) print("Created:", dstDir.relative_to(ROOT_DIR), flush=True)
if item.is_file(): if item.is_file():
shutil.copyfile(item, dst / relSrc) shutil.copyfile(item, dst / relSrc)
print("Copied:", relSrc) print("Copied:", relSrc, flush=True)
return return
@@ -96,7 +96,7 @@ def copyPackageFiles(dst: Path, setupPy: bool = False) -> None:
copyFiles = ["LICENSE.md", "CREDITS.md", "pyproject.toml"] copyFiles = ["LICENSE.md", "CREDITS.md", "pyproject.toml"]
for copyFile in copyFiles: for copyFile in copyFiles:
shutil.copyfile(copyFile, dst / copyFile) shutil.copyfile(copyFile, dst / copyFile)
print("Copied:", copyFile) print("Copied:", copyFile, flush=True)
writeFile(dst / "MANIFEST.in", ( writeFile(dst / "MANIFEST.in", (
"include LICENSE.md\n" "include LICENSE.md\n"
@@ -137,10 +137,10 @@ def makeCheckSum(sumFile: str, cwd: Path | None = None) -> str:
shaFile = cwd / f"{sumFile}.sha256" shaFile = cwd / f"{sumFile}.sha256"
with open(shaFile, mode="w", encoding="utf-8") as fOut: with open(shaFile, mode="w", encoding="utf-8") as fOut:
subprocess.call(["shasum", "-a", "256", sumFile], stdout=fOut, cwd=cwd) subprocess.call(["shasum", "-a", "256", sumFile], stdout=fOut, cwd=cwd)
print(f"SHA256 Sum: {shaFile}") print(f"SHA256 Sum: {shaFile}", flush=True)
except Exception as exc: except Exception as exc:
print("Could not generate sha256 file") print("Could not generate sha256 file", flush=True)
print(str(exc)) print(str(exc), flush=True)
return "" return ""
return str(shaFile) return str(shaFile)
@@ -154,17 +154,17 @@ def checkAssetsExist() -> bool:
sampleZip = ROOT_DIR / "novelwriter" / "assets" / "sample.zip" sampleZip = ROOT_DIR / "novelwriter" / "assets" / "sample.zip"
if sampleZip.is_file(): if sampleZip.is_file():
print(f"Found: {sampleZip}") print(f"Found: {sampleZip}", flush=True)
hasSample = True hasSample = True
pdfManual = ROOT_DIR / "novelwriter" / "assets" / "manual.pdf" pdfManual = ROOT_DIR / "novelwriter" / "assets" / "manual.pdf"
if pdfManual.is_file(): if pdfManual.is_file():
print(f"Found: {pdfManual}") print(f"Found: {pdfManual}", flush=True)
hasManual = True hasManual = True
i18nAssets = ROOT_DIR / "novelwriter" / "assets" / "i18n" i18nAssets = ROOT_DIR / "novelwriter" / "assets" / "i18n"
if len(list(i18nAssets.glob("*.qm"))) > 0: if len(list(i18nAssets.glob("*.qm"))) > 0:
print(f"Found: {i18nAssets}/*.qm") print(f"Found: {i18nAssets}/*.qm", flush=True)
hasQmData = True hasQmData = True
return hasSample and hasManual and hasQmData return hasSample and hasManual and hasQmData
@@ -187,29 +187,29 @@ def readFile(file: Path) -> str:
def writeFile(file: Path, text: str) -> int: def writeFile(file: Path, text: str) -> int:
"""Write string to file.""" """Write string to file."""
result = file.write_text(text, encoding="utf-8") result = file.write_text(text, encoding="utf-8")
print("Wrote:", file.relative_to(ROOT_DIR)) print("Wrote:", file.relative_to(ROOT_DIR), flush=True)
return result return result
def freshFolder(path: Path) -> None: def freshFolder(path: Path) -> None:
"""Make sure a folder exists and is empty.""" """Make sure a folder exists and is empty."""
if path.exists(): if path.exists():
print("Removing:", str(path)) print("Removing:", str(path), flush=True)
shutil.rmtree(path) shutil.rmtree(path)
path.mkdir() path.mkdir()
return return
def systemCall(cmd: list, cwd: Path | str | None = None, env: dict | None = None) -> None: def systemCall(cmd: list, cwd: Path | str | None = None, env: dict | None = None) -> int:
"""Make a system call using subprocess.""" """Make a system call using subprocess."""
if isinstance(cwd, Path): if isinstance(cwd, Path):
cwd = str(cwd) cwd = str(cwd)
try: try:
subprocess.call([str(c) for c in cmd], cwd=cwd, env=env) code = subprocess.call([str(c) for c in cmd], cwd=cwd, env=env)
except Exception as exc: except Exception as exc:
print("ERROR:", str(exc)) print("ERROR:", str(exc), flush=True)
sys.exit(1) sys.exit(1)
return return code
def removeRedundantQt(qtBase: Path) -> None: def removeRedundantQt(qtBase: Path) -> None:
@@ -218,12 +218,12 @@ def removeRedundantQt(qtBase: Path) -> None:
def unlinkIfFound(file: Path) -> None: def unlinkIfFound(file: Path) -> None:
if file.is_file(): if file.is_file():
file.unlink() file.unlink()
print("Deleted:", file.relative_to(ROOT_DIR)) print("Deleted:", file.relative_to(ROOT_DIR), flush=True)
def deleteFolder(folder: Path) -> None: def deleteFolder(folder: Path) -> None:
if folder.is_dir(): if folder.is_dir():
shutil.rmtree(folder) shutil.rmtree(folder)
print("Deleted:", folder.relative_to(ROOT_DIR)) print("Deleted:", folder.relative_to(ROOT_DIR), flush=True)
def unlinkIfPrefix(folder: Path, prefix: tuple[str, ...]) -> None: def unlinkIfPrefix(folder: Path, prefix: tuple[str, ...]) -> None:
if folder.is_dir(): if folder.is_dir():
+3 -3
View File
@@ -25,7 +25,7 @@ import os
import shutil import shutil
import subprocess import subprocess
from utils.common import ROOT_DIR from utils.common import ROOT_DIR, systemCall
def updateDocsTranslationSources(args: argparse.Namespace) -> None: def updateDocsTranslationSources(args: argparse.Namespace) -> None:
@@ -40,7 +40,7 @@ def updateDocsTranslationSources(args: argparse.Namespace) -> None:
locsDir.mkdir(exist_ok=True) locsDir.mkdir(exist_ok=True)
print("Generating POT Files") print("Generating POT Files")
subprocess.call(["make", "gettext"], cwd=docsDir) systemCall(["make", "gettext"], cwd=docsDir)
print("") print("")
lang = args.lang lang = args.lang
@@ -55,7 +55,7 @@ def updateDocsTranslationSources(args: argparse.Namespace) -> None:
print("") print("")
for code in update: for code in update:
subprocess.call(["sphinx-intl", "update", "-p", "build/gettext", "-l", code], cwd=docsDir) systemCall(["sphinx-intl", "update", "-p", "build/gettext", "-l", code], cwd=docsDir)
print("") print("")
print("Done") print("Done")