Skip to content

Commit

Permalink
use pydantic when available
Browse files Browse the repository at this point in the history
  • Loading branch information
obfusk committed Nov 24, 2024
1 parent 8ed0356 commit 3fbba86
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 21 deletions.
1 change: 1 addition & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
51 changes: 30 additions & 21 deletions scripts/build.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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"
Expand Down Expand Up @@ -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(
Expand All @@ -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(
Expand Down

0 comments on commit 3fbba86

Please sign in to comment.