From 3fbba8691ebefa8c9e26763241aa2b669f61603b Mon Sep 17 00:00:00 2001 From: "FC (Fay) Stegerman" Date: Sun, 24 Nov 2024 23:35:25 +0100 Subject: [PATCH] use pydantic when available --- .github/workflows/ci.yml | 1 + requirements.txt | 1 + scripts/build.py | 51 +++++++++++++++++++++++----------------- 3 files changed, 32 insertions(+), 21 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index ddb2101b..c82aecc3 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -47,6 +47,7 @@ jobs: run: | python3 -m pip install --upgrade pip python3 -m pip install -r requirements.txt + python3 -m pip freeze python3 -m pip install flake8 pylint mypy types-{requests,PyYAML} jsonschema - name: Checkout test recipes run: git checkout origin/master -- recipes/me.hackerchick.catima.yml diff --git a/requirements.txt b/requirements.txt index b7f2e9b5..02bca155 100644 --- a/requirements.txt +++ b/requirements.txt @@ -4,6 +4,7 @@ click==8.1.7 git+https://github.com/obfusk/apksigcopier.git@v1.1.1 git+https://github.com/obfusk/reproducible-apk-tools.git@v0.3.0 idna==3.10 +pydantic==2.10.1 requests==2.32.3 ruamel.yaml==0.18.6 ruamel.yaml.clib==0.2.12 diff --git a/scripts/build.py b/scripts/build.py index 3962a2ba..d5f55aaa 100755 --- a/scripts/build.py +++ b/scripts/build.py @@ -16,7 +16,6 @@ import time import zipfile -from dataclasses import dataclass from enum import Enum from functools import reduce from typing import Any, Dict, List, Optional, Tuple @@ -27,6 +26,12 @@ from ruamel.yaml import YAML +try: + from pydantic.dataclasses import dataclass +except ImportError: + print("Warning: pydantic not available, validation disabled.", file=sys.stderr) + from dataclasses import dataclass # type: ignore[no-redef] + BuildBackend = Enum("BuildBackend", ["PODMAN", "DOCKER"]) # FIXME NOAPK = "none" @@ -56,20 +61,24 @@ def for_json(self) -> Dict[str, Any]: @dataclass(frozen=True) class Provisioning: """Provisioning data.""" - android_home: str - build_tools: Optional[str] - cmake: Optional[str] - cmdline_tools: Download - extra_packages: Tuple[str, ...] - image: str - jdk: str - ndk: Optional[str] - platform: Optional[str] - platform_tools: Optional[str] - tools: Optional[str] - verify_git: bool - verify_gradle_wrapper: bool - windows_like: bool + android_home: str = "/opt/sdk" + build_tools: Optional[str] = None + cmake: Optional[str] = None + cmdline_tools: Download = Download( + version="12.0", + url="https://dl.google.com/android/repository/commandlinetools-linux-11076708_latest.zip", + sha256="2d2d50857e4eb553af5a6dc3ad507a17adf43d115264b1afc116f95c92e5e258", + ) + extra_packages: Tuple[str, ...] = () + image: str = "debian:bookworm-slim" + jdk: str = "openjdk-17-jdk-headless" + ndk: Optional[str] = None + platform: Optional[str] = None + platform_tools: Optional[str] = None + tools: Optional[str] = None + verify_git: bool = True + verify_gradle_wrapper: bool = True + windows_like: bool = False def for_json(self) -> Dict[str, Any]: return dict( @@ -88,12 +97,12 @@ class BuildRecipe: apk_pattern: str apk_url: Optional[str] build: str - build_cpus: Optional[int] - build_home_dir: str - build_repo_dir: str - build_timeout: Optional[int] - build_user: str - provisioning: Provisioning + build_cpus: Optional[int] = None + build_home_dir: str = "/build" + build_repo_dir: str = "/build/repo" + build_timeout: Optional[int] = None + build_user: str = "build" + provisioning: Provisioning = Provisioning() def for_json(self) -> Dict[str, Any]: return dict(