Debian Codegraph @

doc/sphinx/scripting/python-extension.rst

raw
1 Python Extension Technical Details
2 ==================================
3
4 This document covers the technical details of FontForge's Python extension
5 module, including building wheels for PyPI distribution.
6
7 Modules
8 -------
9
10 FontForge provides two Python modules:
11
12 - ``fontforge`` - Main font manipulation API
13 - ``psMat`` - PostScript matrix operations
14
15 Build Scenarios
16 ---------------
17
18 .. list-table::
19 :header-rows: 1
20
21 * - Scenario
22 - Detection
23 - GUI
24 - Install Location
25 * - Wheel (pip)
26 - ``SKBUILD`` defined
27 - OFF
28 - Wheel root
29 * - System install
30 - Manual cmake
31 - ON/OFF
32 - site-packages
33
34 Dependencies
35 ------------
36
37 Required (always linked):
38 libxml2, zlib, libiconv
39
40 Bundled in wheels:
41 FreeType, libpng, libjpeg, libtiff, libspiro, woff2
42
43 Not needed for wheels (GUI-only):
44 GLIB, Gettext/Intl, Readline
45
46 Versioning
47 ----------
48
49 The source uses ``PROJECT_VERSION = 20251009`` (YYYYMMDD format).
50 Wheels use CalVer format ``2025.10.9``.
51
52 ``fontforge.version()`` returns:
53
54 - CalVer when imported as a module (from site-packages or wheel)
55 - Numeric format when Python is embedded in the running FontForge application
56
57 CMake transformation::
58
59 string(SUBSTRING "${PROJECT_VERSION}" 0 4 _FF_YEAR)
60 string(SUBSTRING "${PROJECT_VERSION}" 4 2 _FF_MONTH)
61 string(SUBSTRING "${PROJECT_VERSION}" 6 2 _FF_DAY)
62 math(EXPR _FF_MONTH_INT "${_FF_MONTH}")
63 math(EXPR _FF_DAY_INT "${_FF_DAY}")
64 set(FONTFORGE_PYTHON_VERSION "${_FF_YEAR}.${_FF_MONTH_INT}.${_FF_DAY_INT}")
65
66 Windows MSVC Build
67 ------------------
68
69 Windows wheels require MSVC because Python.org's Windows Python is built
70 with MSVC. The MinGW build continues for the GUI application.
71
72 MSVC compatibility patterns::
73
74 // UNUSED macro
75 #ifdef _MSC_VER
76 # define UNUSED(x) x
77 #elif defined(__GNUC__)
78 # define UNUSED(x) UNUSED_ ## x __attribute__((unused))
79 #endif
80
81 DLL exports: MinGW uses ``--export-all-symbols``. MSVC needs explicit
82 ``__declspec(dllexport)`` or a DEF file.
83
84 vcpkg provides dependencies::
85
86 {
87 "name": "fontforge",
88 "dependencies": ["freetype", "libxml2", "glib", "gettext", "libiconv", "zlib"]
89 }
90
91 Build Configuration
92 -------------------
93
94 Wheels are built using scikit-build-core. See ``pyproject.toml`` for the
95 current configuration.
96
97 ::
98
99 [build-system]
100 requires = ["scikit-build-core>=0.5"]
101 build-backend = "scikit_build_core.build"
102
103 [project]
104 name = "fontforge"
105 dynamic = ["version"]
106
107 [tool.scikit-build]
108 cmake.args = ["-DENABLE_GUI=OFF", "-DENABLE_PYTHON_EXTENSION=ON"]
109 wheel.install-dir = "."
110
111 Wheel Target Platforms
112 ----------------------
113
114 The project builds wheels for:
115
116 - Linux: x86_64, aarch64 (manylinux_2_28)
117 - macOS: x86_64, arm64 (separate wheels, macOS 11.0+)
118 - Windows: x64 (MSVC)
119
120 Install Conflict Handling
121 -------------------------
122
123 App installs create ``fontforge-{version}.dist-info/`` with
124 ``INSTALLER = fontforge-app``. This allows ``pip list`` to show the install
125 and ``pip uninstall`` to work.
126
127 If a pip-installed version exists, app install skips and suggests
128 ``pip uninstall fontforge``.