mirror of
https://github.com/ankitects/anki.git
synced 2025-09-19 06:22:22 -04:00

Closes #3787, and is a step towards #3081 and #4022 This change breaks our PyOxidizer bundling process. While we probably could update it to work with the new venvs & lockfile, my intention is to use this as a base to try out a uv-based packager/installer. Still to do: - move mpv distribution to a wheel - build the new uv-based installer. Some notes about the changes: - Use uv for python download + venv installation - Drop python/requirements* in favour of pyproject files / uv.lock - Bumped to latest Python 3.9 version. The move to 3.13 should be a fairly trivial change when we're ready. - Dropped the old write_wheel.py in favour of uv/hatchling. This has the unfortunate side-effect of dropping leading zeros in our wheels, which we could try hack around in the future. - Switch to Qt 6.7 for the dev repo, as it's the first PyQt version with a Linux/ARM WebEngine wheel. - Unified our macOS deployment target with minimum required for ARM. - Dropped unused fluent python files - Dropped unused python license generation - Dropped helpers to run under Qt 5, as our wheels were already requiring Qt 6 to install.
51 lines
2 KiB
Python
51 lines
2 KiB
Python
# Copyright: Ankitects Pty Ltd and contributors
|
|
# License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
|
|
|
import os
|
|
import sys
|
|
from pathlib import Path
|
|
from typing import Any, Dict
|
|
|
|
from hatchling.builders.hooks.plugin.interface import BuildHookInterface
|
|
|
|
|
|
class CustomBuildHook(BuildHookInterface):
|
|
"""Build hook to copy generated files into both sdist and wheel."""
|
|
|
|
PLUGIN_NAME = "custom"
|
|
|
|
def initialize(self, version: str, build_data: Dict[str, Any]) -> None:
|
|
"""Initialize the build hook."""
|
|
force_include = build_data.setdefault("force_include", {})
|
|
|
|
# Look for generated files in out/qt/_aqt
|
|
project_root = Path(self.root).parent
|
|
generated_root = project_root / "out" / "qt" / "_aqt"
|
|
|
|
if not os.environ.get("ANKI_WHEEL_TAG"):
|
|
# On Windows, uv invokes this build hook during the initial uv sync,
|
|
# when the tag has not been declared by our build script.
|
|
return
|
|
|
|
assert generated_root.exists(), "you should build with --wheel"
|
|
self._add_aqt_files(force_include, generated_root)
|
|
|
|
def _add_aqt_files(self, force_include: Dict[str, str], aqt_root: Path) -> None:
|
|
"""Add _aqt files to the build."""
|
|
for path in aqt_root.rglob("*"):
|
|
if path.is_file() and not self._should_exclude(path):
|
|
relative_path = path.relative_to(aqt_root)
|
|
# Place files under _aqt/ in the distribution
|
|
dist_path = "_aqt" / relative_path
|
|
force_include[str(path)] = str(dist_path)
|
|
|
|
def _should_exclude(self, path: Path) -> bool:
|
|
"""Check if a file should be excluded from the wheel."""
|
|
# Match the exclusions from write_wheel.py exclude_aqt function
|
|
if path.suffix in [".ui", ".scss", ".map", ".ts"]:
|
|
return True
|
|
if path.name.startswith("tsconfig"):
|
|
return True
|
|
if "/aqt/data" in str(path):
|
|
return True
|
|
return False
|