From 39c5b2f53752feac0fda3589f1d96277a2cdd39e Mon Sep 17 00:00:00 2001 From: Mariotaku Date: Wed, 5 Apr 2023 17:28:50 +0900 Subject: [PATCH] simplified compat check --- .github/workflows/app-submissions.yml | 17 ++---------- repogen/check_compat.py | 38 +++++++++++++++++++++++++++ repogen/downloadipk.py | 4 ++- repogen/lintpkg.py | 3 ++- repogen/pkg_info.py | 17 +++++------- repogen/pkg_registery.py | 13 +++++---- repogen/plugin.py | 4 +-- 7 files changed, 60 insertions(+), 36 deletions(-) create mode 100644 repogen/check_compat.py diff --git a/.github/workflows/app-submissions.yml b/.github/workflows/app-submissions.yml index 75b6f35..29c9e4c 100644 --- a/.github/workflows/app-submissions.yml +++ b/.github/workflows/app-submissions.yml @@ -60,20 +60,7 @@ jobs: ipkfile=/tmp/$(sha256sum "${changed_file}" | cut -d ' ' -f 1).ipk python3 -m repogen.downloadipk -i ${changed_file} -o "${ipkfile}" echo '### Compatibility Check Results' >> /tmp/lint-report.md - compat_check_args="--markdown --github-emoji --quiet" - min_os=$(yq -r '.requirements.minOs // ""' ${changed_file}) - max_os=$(yq -r '.requirements.maxOs // ""' ${changed_file}) - max_os_exclusive=$(yq -r '.requirements.maxOsExclusive // ""' ${changed_file}) - if [ ! -z "${min_os}" ]; then - compat_check_args="${compat_check_args} --min-os ${min_os}" - fi - if [ ! -z "${max_os}" ]; then - compat_check_args="${compat_check_args} --max-os ${max_os}" - fi - if [ ! -z "${max_os_exclusive}" ]; then - compat_check_args="${compat_check_args} --max-os-exclusive ${max_os_exclusive}" - fi - webosbrew-ipk-compat-checker ${compat_check_args} "${ipkfile}" >> /tmp/lint-report.md || export lint_retcode=1 + python3 -m repogen.check_compat -i ${changed_file} -p "${ipkfile}" >> /tmp/lint-report.md || export lint_retcode=1 done exit ${lint_retcode} @@ -85,7 +72,7 @@ jobs: - name: Upload Check Results if: ${{ !env.ACT && (success() || failure()) }} - uses: actions/upload-artifact@v2 + uses: actions/upload-artifact@v3 with: name: Check Results path: | diff --git a/repogen/check_compat.py b/repogen/check_compat.py new file mode 100644 index 0000000..4c6708d --- /dev/null +++ b/repogen/check_compat.py @@ -0,0 +1,38 @@ +import os +import subprocess +from pathlib import Path + +from repogen import pkg_info + + +def check(info_file: Path, package_file: Path): + info = pkg_info.from_package_info_file(info_file) + compat_check_args = ['--markdown', '--github-emoji', '--quiet'] + if 'requirements' in info: + pass + # min_os =$(yq - r '.requirements.minOs // ""' ${changed_file}) + # max_os =$(yq - r '.requirements.maxOs // ""' ${changed_file}) + # max_os_exclusive =$(yq - r '.requirements.maxOsExclusive // ""' ${changed_file}) + # if [ ! -z "${min_os}"]; then + # compat_check_args = "${compat_check_args} --min-os ${min_os}" + # + # + # fi + # if [ ! -z "${max_os}"]; then + # compat_check_args = "${compat_check_args} --max-os ${max_os}" + # fi + # if [ ! -z "${max_os_exclusive}"]; then + # compat_check_args = "${compat_check_args} --max-os-exclusive ${max_os_exclusive}" + # fi + p = subprocess.run(['webosbrew-ipk-compat-checker', *compat_check_args, str(package_file.absolute())], shell=True) + exit(p.returncode) + + +if __name__ == '__main__': + import argparse + + parser = argparse.ArgumentParser() + parser.add_argument('-i', '--info', required=True) + parser.add_argument('-p', '--package', required=True) + args = parser.parse_args() + check(Path(args.info), Path(args.package)) diff --git a/repogen/downloadipk.py b/repogen/downloadipk.py index bd7c5ed..c59ebd5 100644 --- a/repogen/downloadipk.py +++ b/repogen/downloadipk.py @@ -1,3 +1,5 @@ +from pathlib import Path + import requests from repogen import pkg_info @@ -10,7 +12,7 @@ parser.add_argument('-o', '--output', required=True) args = parser.parse_args() - pkginfo = pkg_info.from_package_info_file(args.info) + pkginfo = pkg_info.from_package_info_file(Path(args.info)) with requests.get(pkginfo['manifest']['ipkUrl'], allow_redirects=True) as resp: with open(args.output, 'wb') as f: f.write(resp.content) diff --git a/repogen/lintpkg.py b/repogen/lintpkg.py index 443abd5..28c420b 100644 --- a/repogen/lintpkg.py +++ b/repogen/lintpkg.py @@ -1,4 +1,5 @@ from os import path +from pathlib import Path from urllib.parse import urlparse from urllib.request import url2pathname from xml.etree import ElementTree @@ -91,7 +92,7 @@ def _validate_manifest_url(url: str, key: str, e: [str]): parser.add_argument('-f', '--file', required=True) args = parser.parse_args() - lint_pkginfo = pkg_info.from_package_info_file(args.file) + lint_pkginfo = pkg_info.from_package_info_file(Path(args.file)) if lint_pkginfo is None: raise ValueError('No package info') diff --git a/repogen/pkg_info.py b/repogen/pkg_info.py index c86632f..f8bf0d6 100644 --- a/repogen/pkg_info.py +++ b/repogen/pkg_info.py @@ -1,9 +1,7 @@ import locale -import os import sys from datetime import datetime -from os import path -from os.path import isfile, join +from pathlib import Path from typing import TypedDict, Optional, List, NotRequired import nh3 @@ -33,16 +31,16 @@ class PackageInfo(TypedDict): lastmodified_str: str -def from_package_info_file(info_path: str, offline=False) -> Optional[PackageInfo]: - extension = path.splitext(info_path)[1] +def from_package_info_file(info_path: Path, offline=False) -> Optional[PackageInfo]: + extension = info_path.suffix content: PackageRegistry - print(f'Parsing package info file {path.basename(info_path)}', file=sys.stderr) + print(f'Parsing package info file {info_path.name}', file=sys.stderr) if extension == '.yml': pkgid, content = parse_yml_package(info_path) elif extension == '.py': pkgid, content = load_py_package(info_path) else: - return None + raise ValueError(f'Unrecognized info format {extension}') if not ('title' in content and 'iconUri' in content and 'manifestUrl' in content): return None return from_package_info(pkgid, content, offline) @@ -106,9 +104,8 @@ def from_package_info(pkgid: str, content: PackageRegistry, offline=False): return pkginfo -def list_packages(pkgdir: str, offline: bool = False) -> List[PackageInfo]: - paths = [join(pkgdir, f) - for f in os.listdir(pkgdir) if isfile(join(pkgdir, f))] +def list_packages(pkgdir: Path, offline: bool = False) -> List[PackageInfo]: + paths: List[Path] = [pkgdir.joinpath(f) for f in pkgdir.iterdir() if f.is_file()] return sorted(filter(lambda x: x, map(lambda p: from_package_info_file(p, offline), paths)), key=lambda x: x['title']) diff --git a/repogen/pkg_registery.py b/repogen/pkg_registery.py index 6e05c14..538f9a5 100644 --- a/repogen/pkg_registery.py +++ b/repogen/pkg_registery.py @@ -1,5 +1,5 @@ import importlib -from os import path +from pathlib import Path from typing import TypedDict, NotRequired, Literal import yaml @@ -17,16 +17,15 @@ class PackageRegistry(TypedDict): funding: NotRequired[dict] -def parse_yml_package(p: str) -> (str, PackageRegistry): - pkgid = path.splitext(path.basename(p))[0] - with open(p, encoding='utf-8') as f: +def parse_yml_package(p: Path) -> (str, PackageRegistry): + with p.open(encoding='utf-8') as f: content: PackageRegistry = yaml.safe_load(f) - return pkgid, content + return p.stem, content # noinspection PyUnresolvedReferences -def load_py_package(p: str) -> (str, PackageRegistry): - pkgid = path.splitext(path.basename(p))[0] +def load_py_package(p: Path) -> (str, PackageRegistry): + pkgid = p.stem spec = importlib.util.spec_from_file_location(f"pkg.{pkgid}", p) module = importlib.util.module_from_spec(spec) spec.loader.exec_module(module) diff --git a/repogen/plugin.py b/repogen/plugin.py index 2fca10a..b9260e6 100644 --- a/repogen/plugin.py +++ b/repogen/plugin.py @@ -23,8 +23,8 @@ def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) self._md = Markdown(**self.settings['MARKDOWN']) - def read(self, filename): - info = pkg_info.from_package_info_file(filename, offline='CI' not in os.environ) + def read(self, filename: str): + info = pkg_info.from_package_info_file(Path(filename), offline='CI' not in os.environ) metadata = { 'title': info['title'], 'override_save_as': f'apps/{info["id"]}.html',