python3Packages.libretranslate: create static gzip and brotli files

This commit is contained in:
Izorkin
2023-07-12 12:50:43 +03:00
committed by Sandro Jäckel
parent 5329805c4a
commit c944da85cd

View File

@@ -1,8 +1,10 @@
{
lib,
pkgs,
buildPythonPackage,
fetchFromGitHub,
pytestCheckHook,
runCommand,
hatchling,
argostranslate,
flask,
@@ -15,6 +17,7 @@
expiringdict,
langdetect,
lexilang,
libretranslate,
ltpycld2,
morfessor,
appdirs,
@@ -26,6 +29,7 @@
prometheus-client,
polib,
python,
xorg,
}:
buildPythonPackage rec {
@@ -85,6 +89,26 @@ buildPythonPackage rec {
pythonImportsCheck = [ "libretranslate" ];
passthru = {
static-compressed =
runCommand "libretranslate-data-compressed"
{
nativeBuildInputs = [
pkgs.brotli
xorg.lndir
];
}
''
mkdir -p $out/share/libretranslate/static
lndir ${libretranslate}/share/libretranslate/static $out/share/libretranslate/static
# Create static gzip and brotli files
find -L $out -type f -regextype posix-extended -iregex '.*\.(css|ico|js|svg|ttf)' \
-exec gzip --best --keep --force {} ';' \
-exec brotli --best --keep --no-copy-stat {} ';'
'';
};
meta = with lib; {
description = "Free and Open Source Machine Translation API. Self-hosted, no limits, no ties to proprietary services";
homepage = "https://libretranslate.com";