clan-app: Fix default.nix

This commit is contained in:
Qubasa
2025-01-08 18:43:20 +01:00
parent e3b54e62de
commit c6d5eb5037
9 changed files with 83 additions and 111 deletions

View File

@@ -1,16 +1,16 @@
{
python3Full,
runCommand,
setuptools,
copyDesktopItems,
clan-cli,
makeDesktopItem,
webview-ui,
webview-lib,
fontconfig,
pythonRuntime,
}:
let
source = ./.;
desktop-file = makeDesktopItem {
name = "org.clan.app";
exec = "clan-app %u";
@@ -25,24 +25,29 @@ let
];
pyDeps = ps: [
ps.tkinter
];
# Dependencies required for running tests
pyTestDeps =
ps:
with ps;
[
(python3Full.pkgs.toPythonModule pytest)
# Testing framework
pytest-cov # Generate coverage reports
pytest-subprocess # fake the real subprocess behavior to make your tests more independent.
pytest-xdist # Run tests in parallel on multiple cores
pytest-timeout # Add timeouts to your tests
ps.pytest
ps.pytest-cov # Generate coverage reports
ps.pytest-subprocess # fake the real subprocess behavior to make your tests more independent.
ps.pytest-xdist # Run tests in parallel on multiple cores
ps.pytest-timeout # Add timeouts to your tests
]
++ pytest.propagatedBuildInputs;
++ ps.pytest.propagatedBuildInputs;
clan-cli-module = [ (python3Full.pkgs.toPythonModule clan-cli) ];
clan-cli-module = [
(pythonRuntime.pkgs.toPythonModule (clan-cli.override { inherit pythonRuntime; }))
];
in
python3Full.pkgs.buildPythonApplication rec {
pythonRuntime.pkgs.buildPythonApplication {
name = "clan-app";
src = source;
format = "pyproject";
@@ -51,7 +56,7 @@ python3Full.pkgs.buildPythonApplication rec {
preFixup = ''
makeWrapperArgs+=(
--set FONTCONFIG_FILE ${fontconfig.out}/etc/fonts/fonts.conf
--set WEBUI_PATH "$out/${python3Full.sitePackages}/clan_app/.webui"
--set WEBUI_PATH "$out/${pythonRuntime.sitePackages}/clan_app/.webui"
--set WEBVIEW_LIB_DIR "${webview-lib}/lib"
# This prevents problems with mixed glibc versions that might occur when the
# cli is called through a browser built against another glibc
@@ -62,7 +67,7 @@ python3Full.pkgs.buildPythonApplication rec {
# Deps needed only at build time
nativeBuildInputs = [
setuptools
(pythonRuntime.withPackages (ps: [ ps.setuptools ]))
copyDesktopItems
fontconfig
];
@@ -71,8 +76,9 @@ python3Full.pkgs.buildPythonApplication rec {
# same values for your Python package within Nix largely stems from ensuring
# that all necessary dependencies are consistently available both
# at build time and runtime,
buildInputs = clan-cli-module ++ runtimeDependencies;
propagatedBuildInputs = buildInputs;
propagatedBuildInputs = [
(pythonRuntime.withPackages (ps: clan-cli-module ++ (pyDeps ps)))
] ++ runtimeDependencies;
# also re-expose dependencies so we test them in CI
passthru = {
@@ -81,7 +87,7 @@ python3Full.pkgs.buildPythonApplication rec {
runCommand "clan-app-pytest"
{
buildInputs = runtimeDependencies ++ [
(python3Full.withPackages (ps: clan-cli-module ++ (pyTestDeps ps)))
(pythonRuntime.withPackages (ps: clan-cli-module ++ (pyTestDeps ps) ++ (pyDeps ps)))
fontconfig
];
}
@@ -105,7 +111,7 @@ python3Full.pkgs.buildPythonApplication rec {
echo "STARTING ..."
export WEBVIEW_LIB_DIR="${webview-lib}/lib"
export NIX_STATE_DIR=$TMPDIR/nix IN_NIX_SANDBOX=1
python3 -m pytest -s -m "not impure" ./tests
python -m pytest -s -m "not impure" ./tests
touch $out
'';
};
@@ -113,11 +119,12 @@ python3Full.pkgs.buildPythonApplication rec {
# Additional pass-through attributes
passthru.desktop-file = desktop-file;
passthru.devshellDeps = ps: (pyTestDeps ps);
passthru.devshellPyDeps = ps: (pyTestDeps ps) ++ (pyDeps ps);
passthru.pythonRuntime = pythonRuntime;
postInstall = ''
mkdir -p $out/${python3Full.sitePackages}/clan_app/.webui
cp -r ${webview-ui}/lib/node_modules/@clan/webview-ui/dist/* $out/${python3Full.sitePackages}/clan_app/.webui
mkdir -p $out/${pythonRuntime.sitePackages}/clan_app/.webui
cp -r ${webview-ui}/lib/node_modules/@clan/webview-ui/dist/* $out/${pythonRuntime.sitePackages}/clan_app/.webui
mkdir -p $out/share/icons/hicolor
cp -r ./clan_app/assets/white-favicons/* $out/share/icons/hicolor
'';

View File

@@ -17,8 +17,9 @@
inherit (config.packages) clan-app webview-lib;
inherit self';
};
packages.clan-app = pkgs.python3.pkgs.callPackage ./default.nix {
packages.clan-app = pkgs.callPackage ./default.nix {
inherit (config.packages) clan-cli webview-ui webview-lib;
pythonRuntime = pkgs.python3;
};
checks = config.packages.clan-app.tests;

View File

@@ -36,6 +36,3 @@ disallow_untyped_calls = true
disallow_untyped_defs = true
no_implicit_optional = true
[[tool.mypy.overrides]]
module = "clan_cli.*"
ignore_missing_imports = true

View File

@@ -5,7 +5,6 @@
ruff,
gtk4,
webview-lib,
python3Full,
self',
}:
@@ -14,14 +13,14 @@ mkShell {
inputsFrom = [ self'.devShells.default ];
buildInputs = [
(python3Full.withPackages (
(clan-app.pythonRuntime.withPackages (
ps:
with ps;
[
ruff
mypy
]
++ (clan-app.devshellDeps ps)
++ (clan-app.devshellPyDeps ps)
))
];