Skip to content

Commit

Permalink
simplified compat check
Browse files Browse the repository at this point in the history
  • Loading branch information
mariotaku committed Apr 5, 2023
1 parent d48ab6d commit 39c5b2f
Show file tree
Hide file tree
Showing 7 changed files with 60 additions and 36 deletions.
17 changes: 2 additions & 15 deletions .github/workflows/app-submissions.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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}
Expand All @@ -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: |
Expand Down
38 changes: 38 additions & 0 deletions repogen/check_compat.py
Original file line number Diff line number Diff line change
@@ -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))
4 changes: 3 additions & 1 deletion repogen/downloadipk.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from pathlib import Path

import requests

from repogen import pkg_info
Expand All @@ -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)
Expand Down
3 changes: 2 additions & 1 deletion repogen/lintpkg.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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')

Expand Down
17 changes: 7 additions & 10 deletions repogen/pkg_info.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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'])

Expand Down
13 changes: 6 additions & 7 deletions repogen/pkg_registery.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import importlib
from os import path
from pathlib import Path
from typing import TypedDict, NotRequired, Literal

import yaml
Expand All @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions repogen/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down

0 comments on commit 39c5b2f

Please sign in to comment.