Skip to content

Commit 8d9b59b

Browse files
add nanosvg package (#50)
1 parent 950d288 commit 8d9b59b

File tree

6 files changed

+112
-0
lines changed

6 files changed

+112
-0
lines changed

build.sh

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,9 @@ fi
3434
if [[ -n "${BUILD_SH_IN_MANYLINUX:-}" ]]; then
3535
export PATH="/opt/python/cp312-cp312/bin:$PATH"
3636

37+
# cached *-src repos may be owned by the host runner user; tell git to trust them
38+
git config --global --add safe.directory '*'
39+
3740
./setup.sh
3841

3942
if [[ -z "${BUILD_SH_REUSE_MANYLINUX_ARTIFACTS:-}" ]]; then

nanosvg/build.sh

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
#!/usr/bin/env bash
2+
set -e
3+
4+
DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" >/dev/null && pwd)"
5+
cd "$DIR"
6+
7+
COMMIT="5cefd9847949af6df13f65027fd43af5a7513633"
8+
INSTALL_DIR="$DIR/nanosvg/install"
9+
10+
# Clone/update source
11+
if [ ! -d "nanosvg-src/.git" ]; then
12+
rm -rf nanosvg-src
13+
git clone --depth 1 https://github.com/memononen/nanosvg.git nanosvg-src
14+
fi
15+
git -C nanosvg-src fetch --depth 1 origin "$COMMIT"
16+
git -C nanosvg-src checkout --force FETCH_HEAD
17+
18+
# Copy headers
19+
rm -rf "$INSTALL_DIR"
20+
mkdir -p "$INSTALL_DIR/include"
21+
cp nanosvg-src/src/nanosvg.h "$INSTALL_DIR/include/"
22+
cp nanosvg-src/src/nanosvgrast.h "$INSTALL_DIR/include/"
23+
24+
echo "Installed nanosvg to $INSTALL_DIR"
25+
du -sh "$INSTALL_DIR"

nanosvg/nanosvg/__init__.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import os
2+
3+
DIR = os.path.join(os.path.dirname(__file__), "install")
4+
INCLUDE_DIR = os.path.join(DIR, "include")
5+
LIB_DIR = DIR # header-only; no libraries
6+
7+
8+
def smoketest():
9+
assert os.path.isfile(os.path.join(INCLUDE_DIR, "nanosvg.h")), "nanosvg.h not found"
10+
assert os.path.isfile(os.path.join(INCLUDE_DIR, "nanosvgrast.h")), "nanosvgrast.h not found"

nanosvg/pyproject.toml

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
[build-system]
2+
requires = ["setuptools>=64", "wheel"]
3+
build-backend = "setuptools.build_meta"
4+
5+
[project]
6+
name = "nanosvg"
7+
version = "0.0.1"
8+
description = "NanoSVG: simple SVG parser and rasterizer"
9+
requires-python = ">=3.8"
10+
11+
[tool.setuptools.packages.find]
12+
include = ["nanosvg*"]
13+
14+
[tool.setuptools.package-data]
15+
nanosvg = ["install/**/*"]

nanosvg/setup.py

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
import os
2+
import platform
3+
import subprocess
4+
5+
from setuptools.command.build_py import build_py
6+
7+
try:
8+
from wheel.bdist_wheel import bdist_wheel
9+
except ImportError:
10+
bdist_wheel = None
11+
12+
13+
class BuildNanosvg(build_py):
14+
"""Run build.sh to download nanosvg headers before collecting package data."""
15+
16+
def run(self):
17+
pkg_dir = os.path.dirname(os.path.abspath(__file__))
18+
build_script = os.path.join(pkg_dir, "build.sh")
19+
subprocess.check_call(["bash", build_script], cwd=pkg_dir)
20+
21+
super().run()
22+
23+
24+
cmdclass = {"build_py": BuildNanosvg}
25+
26+
if bdist_wheel is not None:
27+
28+
class PlatformWheel(bdist_wheel):
29+
"""Produce a platform-specific, Python-version-agnostic wheel."""
30+
31+
def finalize_options(self):
32+
super().finalize_options()
33+
self.root_is_pure = False
34+
35+
def get_tag(self):
36+
system = platform.system()
37+
machine = platform.machine()
38+
39+
if system == "Linux":
40+
plat = f"linux_{machine}"
41+
elif system == "Darwin":
42+
plat = "macosx_11_0_arm64"
43+
else:
44+
plat = f"{system.lower()}_{machine}"
45+
46+
return "py3", "none", plat
47+
48+
cmdclass["bdist_wheel"] = PlatformWheel
49+
50+
51+
def setup():
52+
from setuptools import setup as _setup
53+
54+
_setup(cmdclass=cmdclass)
55+
56+
57+
if __name__ == "__main__":
58+
setup()

pyproject.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ members = [
1111
"json11",
1212
"libjpeg",
1313
"libyuv",
14+
"nanosvg",
1415
"ncurses",
1516
"python3-dev",
1617
"raylib",

0 commit comments

Comments
 (0)