bundle svg
This commit is contained in:
@@ -18,11 +18,18 @@ from .constants import (
|
||||
is_free_version,
|
||||
is_full_version
|
||||
)
|
||||
from .system import install_pillow, get_system_fonts, get_font_enum_items, find_default_truetype_font
|
||||
from .system import (
|
||||
install_pillow,
|
||||
install_cairosvg_from_bundle,
|
||||
get_system_fonts,
|
||||
get_font_enum_items,
|
||||
find_default_truetype_font
|
||||
)
|
||||
|
||||
__all__ = [
|
||||
'bl_info',
|
||||
'install_pillow',
|
||||
'install_cairosvg_from_bundle',
|
||||
'get_system_fonts',
|
||||
'get_font_enum_items',
|
||||
'find_default_truetype_font',
|
||||
|
||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -87,11 +87,16 @@ def ensure_svg_raster(image_path: str, scale: float) -> RasterizationResult:
|
||||
|
||||
try:
|
||||
import cairosvg # type: ignore
|
||||
except ImportError as import_error:
|
||||
raise SVGConversionError(
|
||||
"SVG overlay support requires the 'cairosvg' package. "
|
||||
"Install it via pip (pip install cairosvg) inside Blender's Python environment."
|
||||
) from import_error
|
||||
except ImportError:
|
||||
try:
|
||||
from .system import install_cairosvg_from_bundle
|
||||
install_cairosvg_from_bundle()
|
||||
import cairosvg # type: ignore # noqa: F401
|
||||
except Exception as install_error:
|
||||
raise SVGConversionError(
|
||||
"SVG overlay support requires CairoSVG, but the bundled installation failed. "
|
||||
"Please reinstall the addon or install CairoSVG manually inside Blender's Python environment."
|
||||
) from install_error
|
||||
|
||||
# Guard against invalid scales (NaN, infinity, zero, negative)
|
||||
if not isinstance(scale, (int, float)) or not math.isfinite(scale):
|
||||
|
||||
@@ -6,9 +6,76 @@ import subprocess
|
||||
import sys
|
||||
import platform
|
||||
import os
|
||||
from pathlib import Path
|
||||
from typing import Iterable
|
||||
|
||||
_SUPPORTED_PYTHON_TAG = "cp311"
|
||||
_BUNDLED_WHEEL_DIRS = {
|
||||
"darwin": "cp311-macosx_10_9_universal2",
|
||||
"linux": "cp311-manylinux_2_28_x86_64",
|
||||
}
|
||||
_BUNDLED_CAIROSVG_PACKAGES = (
|
||||
"cairosvg==2.7.1",
|
||||
"cairocffi==1.7.1",
|
||||
"cssselect2==0.7.0",
|
||||
"tinycss2==1.2.1",
|
||||
"defusedxml==0.7.1",
|
||||
"cffi==1.17.1",
|
||||
"pycparser==2.21",
|
||||
)
|
||||
|
||||
_DEFAULT_FONT_CACHE = None
|
||||
|
||||
|
||||
def _pip_install_from_bundle(packages: Iterable[str], bundle_dir: Path) -> None:
|
||||
"""Install packages from a bundled wheel directory using pip."""
|
||||
pass
|
||||
command = [
|
||||
sys.executable,
|
||||
"-m",
|
||||
"pip",
|
||||
"install",
|
||||
"--no-index",
|
||||
"--no-cache-dir",
|
||||
"--find-links",
|
||||
str(bundle_dir),
|
||||
*packages,
|
||||
]
|
||||
subprocess.check_call(command)
|
||||
|
||||
|
||||
def _get_wheel_bundle_dir() -> Path:
|
||||
"""Return the platform-specific wheel bundle directory for the current environment."""
|
||||
pass
|
||||
python_tag = f"cp{sys.version_info.major}{sys.version_info.minor}"
|
||||
if python_tag != _SUPPORTED_PYTHON_TAG:
|
||||
pass
|
||||
raise RuntimeError(
|
||||
f"Bundled dependencies target Python {_SUPPORTED_PYTHON_TAG}, "
|
||||
f"but current interpreter reports {python_tag}."
|
||||
)
|
||||
|
||||
platform_key = platform.system().lower()
|
||||
bundle_name = _BUNDLED_WHEEL_DIRS.get(platform_key)
|
||||
if not bundle_name:
|
||||
pass
|
||||
raise RuntimeError(f"No bundled wheel directory configured for platform '{platform_key}'.")
|
||||
|
||||
wheels_root = Path(__file__).resolve().parent.parent / "wheels"
|
||||
bundle_dir = wheels_root / bundle_name
|
||||
if not bundle_dir.exists():
|
||||
pass
|
||||
raise FileNotFoundError(f"Bundled wheel directory not found: {bundle_dir}")
|
||||
|
||||
return bundle_dir
|
||||
|
||||
|
||||
def install_cairosvg_from_bundle() -> None:
|
||||
"""Install CairoSVG and its dependencies using the bundled wheels."""
|
||||
pass
|
||||
bundle_dir = _get_wheel_bundle_dir()
|
||||
_pip_install_from_bundle(_BUNDLED_CAIROSVG_PACKAGES, bundle_dir)
|
||||
|
||||
def install_pillow():
|
||||
pass
|
||||
"""Install Pillow if not available"""
|
||||
|
||||
Reference in New Issue
Block a user