Skip to content

Commit

Permalink
initial support for Fluent
Browse files Browse the repository at this point in the history
  • Loading branch information
lilydjwg committed Jul 4, 2024
1 parent e8b23af commit 266c433
Show file tree
Hide file tree
Showing 7 changed files with 81 additions and 9 deletions.
40 changes: 32 additions & 8 deletions lilac
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ from lilac2.nomypy import BuildResult, BuildReason # type: ignore
from lilac2 import pkgbuild
from lilac2.building import build_package, MissingDependencies
from lilac2 import slogconf
from lilac2 import intl
try:
from lilac2 import db
except ImportError:
Expand Down Expand Up @@ -131,11 +132,15 @@ def packages_with_depends(
dep_building_map[pkgbase] = {
x.pkgdir.name for x in DEPMAP[pkgbase]}

l10n = intl.get_l10n('mail')
for name, deps in nonexistent.items():
repo.send_error_report(
repo.lilacinfos[name],
subject='软件包 %s 的 lilac.yaml 指定了不存在的依赖',
msg = f'软件包 {name} 的 lilac.yaml 指定了 repo_depends,然而其直接或者间接的依赖项 {deps!r} 并不在本仓库中。'
subject = l10n.format_value(
'nonexistent-deps-subject', {'pkg': name}),
msg = l10n.format_value(
'nonexistent-deps-body',
{'pkg': name, 'deps': repr(deps), 'count': len(deps)}),
)

sorter = graphlib.TopologicalSorter(dep_building_map)
Expand Down Expand Up @@ -343,8 +348,11 @@ def try_pick_some(
except Exception as e:
logger.exception('check_update_on_build')
mod = repo.lilacinfos[pkg]
l10n = intl.get_l10n('mail')
repo.send_error_report(
mod, subject='%s update_on_build 检查出错', exc=e,
mod,
subject = l10n.format_value('update_on_build-error'),
exc = e,
)
continue

Expand Down Expand Up @@ -427,15 +435,30 @@ def build_it(
msg = repr(e)
mod = repo.lilacinfos[pkg]

l10n = intl.get_l10n('mail')
if isinstance(e, MissingDependencies):
faileddeps = e.deps.intersection(failed)
# e.deps - faileddeps = failed previously
failed[pkg] = tuple(e.deps)
if e.deps == faileddeps:
msg = f'{pkg} 的依赖 {faileddeps} 打包失败了。'
msg = l10n.format_value('dependency-issue-failed', {
'pkg': pkg,
'faileddeps': str(faileddeps),
'count': len(faileddeps),
})
else:
msg = f'{pkg} 缺少依赖 {e.deps},其中 {faileddeps} 本次打包失败了。'
repo.send_error_report(mod, subject='%s 出现依赖问题', msg = msg)
msg = l10n.format_value('dependency-issue-failed-this-batch', {
'pkg': pkg,
'deps': str(e.deps),
'count_deps': len(e.deps),
'faileddeps': str(faileddeps),
'count_failed': len(faileddeps),
})
repo.send_error_report(
mod,
subject = l10n.format_value('dependency-issue-subject'),
msg = msg,
)
else:
repo.send_error_report(mod, exc=e, logfile=logfile)

Expand Down Expand Up @@ -686,10 +709,11 @@ def main(logdir: Path, pkgs_from_args: List[str]) -> None:
try:
main_may_raise(D, pkgs_from_args, logdir)
except Exception:
l10n = intl.get_l10n('main')
tb = traceback.format_exc()
logger.exception('unexpected error')
subject = '运行时错误'
msg = '调用栈如下:\n\n' + tb
subject = l10n.format_value('runtime-error')
msg = l10n.format_value('runtime-error-traceback') + '\n\n' + tb
REPO.report_error(subject, msg)

def setup() -> Path:
Expand Down
15 changes: 15 additions & 0 deletions lilac2/intl.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import os
import locale

from fluent.runtime import FluentLocalization, FluentResourceLoader

cache = {}

def get_l10n(name):
if name not in cache:
d = os.path.dirname(__file__)
loc = locale.getlocale()[0]
loader = FluentResourceLoader(f'{d}/l10n/{{locale}}')
l10n = FluentLocalization([loc, "en"], [f'{name}.ftl'], loader)
cache[name] = l10n
return cache[name]
20 changes: 20 additions & 0 deletions lilac2/l10n/en/mail.ftl
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
nonexistent-deps-subject = Non-existent dependencies is listed in lilac.yaml for { $pkg }
nonexistent-deps-body = lilac.yaml of package { $pkg } specifies repo_depends, but the (direct or indirect) {$count ->
[one] dependency { $deps } is
*[other] dependencies { $deps } are
} not in this repository.
update_on_build-error = Error while checking update_on_build for %s
dependency-issue-subject = Dependency issue for %s
dependency-issue-failed = {$count ->
[one] Dependency
*[other] Dependencies
} { $faileddeps } for { $pkg } failed to build.
dependency-issue-failed-this-batch = {$count_deps ->
[one] Dependency { $deps } for { $pkg } is
*[other] Dependencies { $deps } for { $pkg } are
} missing, among which {$count_failed ->
[one] { $faileddeps } has
*[other] { $faileddeps } have
} failed this time.
2 changes: 2 additions & 0 deletions lilac2/l10n/en/main.ftl
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
runtime-error = Runtime error
runtime-error-traceback = Traceback follows:
8 changes: 8 additions & 0 deletions lilac2/l10n/zh_CN/mail.ftl
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
nonexistent-deps-subject = 软件包 { $pkg } 的 lilac.yaml 指定了不存在的依赖
nonexistent-deps-body = 软件包 { $pkg } 的 lilac.yaml 指定了 repo_depends,然而其直接或者间接的依赖项 { $deps } 并不在本仓库中。
update_on_build-error = %s update_on_build 检查出错
dependency-issue-subject = %s 出现依赖问题
dependency-issue-failed = { $pkg } 的依赖 { $faileddeps } 打包失败了。
dependency-issue-failed-this-batch = { $pkg } 缺少依赖 { $deps },其中 { $faileddeps } 本次打包失败了。
2 changes: 2 additions & 0 deletions lilac2/l10n/zh_CN/main.ftl
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
runtime-error = 运行时错误
runtime-error-traceback = 调用栈如下:
3 changes: 2 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,11 @@
# See README.md
install_requires = [
'requests', 'lxml', 'PyYAML', 'pyalpm', 'structlog', 'python_prctl',
'fluent.runtime',
],
include_package_data = True,
package_data = {
'lilac2': ['aliases.yaml'],
'lilac2': ['aliases.yaml', 'l10n/*/*.ftl'],
},
classifiers = [
'Programming Language :: Python',
Expand Down

0 comments on commit 266c433

Please sign in to comment.