add mdbook package (#71)

This commit is contained in:
Adeeb Shihadeh
2026-04-14 16:10:03 -07:00
committed by GitHub
parent 2f5b981c19
commit 79fefe6558
6 changed files with 141 additions and 0 deletions

3
.gitignore vendored
View File

@@ -27,3 +27,6 @@ gcc-arm-none-eabi/gcc_arm_none_eabi/toolchain/
# downloaded git-lfs # downloaded git-lfs
git-lfs/git_lfs/bin/ git-lfs/git_lfs/bin/
# downloaded mdbook
mdbook/mdbook/bin/

46
mdbook/build.sh Executable file
View File

@@ -0,0 +1,46 @@
#!/usr/bin/env bash
set -e
DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" >/dev/null && pwd)"
cd "$DIR"
VERSION="0.5.2"
INSTALL_DIR="$DIR/mdbook/bin"
VERSION_FILE="$INSTALL_DIR/.version"
# Skip if already at correct version
if [ -f "$VERSION_FILE" ] && [ "$(cat "$VERSION_FILE")" = "$VERSION" ]; then
echo "mdbook $VERSION already present, skipping."
exit 0
fi
OS="$(uname -s)"
ARCH="$(uname -m)"
case "${OS}-${ARCH}" in
Linux-x86_64) TARGET="x86_64-unknown-linux-musl" ;;
Linux-aarch64) TARGET="aarch64-unknown-linux-musl" ;;
Darwin-arm64) TARGET="aarch64-apple-darwin" ;;
*)
echo "Unsupported platform: ${OS}-${ARCH}" >&2
exit 1
;;
esac
FILENAME="mdbook-v${VERSION}-${TARGET}.tar.gz"
URL="https://github.com/rust-lang/mdBook/releases/download/v${VERSION}/${FILENAME}"
echo "Downloading $FILENAME ..."
curl -fSL -o "$FILENAME" "$URL"
echo "Extracting ..."
mkdir -p "$INSTALL_DIR"
tar -xzf "$FILENAME" -C "$INSTALL_DIR" mdbook
chmod +x "$INSTALL_DIR/mdbook"
rm -f "$FILENAME"
echo "$VERSION" > "$VERSION_FILE"
echo "Installed mdbook to $INSTALL_DIR"
du -sh "$INSTALL_DIR"

15
mdbook/mdbook/__init__.py Normal file
View File

@@ -0,0 +1,15 @@
import os
import sys
BIN_DIR = os.path.join(os.path.dirname(__file__), "bin")
def _run():
binary = os.path.join(BIN_DIR, "mdbook")
os.execvp(binary, [binary] + sys.argv[1:])
def smoketest():
import subprocess
binary = os.path.join(BIN_DIR, "mdbook")
subprocess.run([binary, "--version"], check=True)

18
mdbook/pyproject.toml Normal file
View File

@@ -0,0 +1,18 @@
[build-system]
requires = ["setuptools>=64", "wheel"]
build-backend = "setuptools.build_meta"
[project]
name = "mdbook"
version = "0.5.2"
description = "mdBook command-line tool for creating books from Markdown"
requires-python = ">=3.8"
[project.scripts]
mdbook = "mdbook:_run"
[tool.setuptools.packages.find]
include = ["mdbook*"]
[tool.setuptools.package-data]
mdbook = ["bin/**/*"]

58
mdbook/setup.py Normal file
View File

@@ -0,0 +1,58 @@
import os
import platform
import subprocess
from setuptools.command.build_py import build_py
try:
from wheel.bdist_wheel import bdist_wheel
except ImportError:
bdist_wheel = None
class BuildMdbook(build_py):
"""Run build.sh to download mdbook before collecting package data."""
def run(self):
pkg_dir = os.path.dirname(os.path.abspath(__file__))
build_script = os.path.join(pkg_dir, "build.sh")
subprocess.check_call(["bash", build_script], cwd=pkg_dir)
super().run()
cmdclass = {"build_py": BuildMdbook}
if bdist_wheel is not None:
class PlatformWheel(bdist_wheel):
"""Produce a platform-specific, Python-version-agnostic wheel."""
def finalize_options(self):
super().finalize_options()
self.root_is_pure = False
def get_tag(self):
system = platform.system()
machine = platform.machine()
if system == "Linux":
plat = f"linux_{machine}"
elif system == "Darwin":
plat = "macosx_11_0_arm64"
else:
plat = f"{system.lower()}_{machine}"
return "py3", "none", plat
cmdclass["bdist_wheel"] = PlatformWheel
def setup():
from setuptools import setup as _setup
_setup(cmdclass=cmdclass)
if __name__ == "__main__":
setup()

View File

@@ -13,6 +13,7 @@ members = [
"libusb", "libusb",
"libjpeg", "libjpeg",
"libyuv", "libyuv",
"mdbook",
"nanosvg", "nanosvg",
"ncurses", "ncurses",
"qt5", "qt5",