Skip to content

Commit

Permalink
nix setup: run test suite during build
Browse files Browse the repository at this point in the history
  • Loading branch information
nazarewk committed Nov 21, 2023
1 parent 1d18309 commit 744d004
Showing 1 changed file with 39 additions and 20 deletions.
59 changes: 39 additions & 20 deletions nix/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
{ lib
, fetchFromGitHub
, gdk-pixbuf
, glib
, git
, glib
, gnome
, gobject-introspection
, gtk-layer-shell
Expand All @@ -14,13 +14,17 @@
, librsvg
, libwnck
, mkYarnPackage
, mypy
, nix-update-script
, python3Packages
, ruff
, stdenv
, systemd
, typos
, webkitgtk
, wrapGAppsHook
, xvfb-run
, xdg-utils
, xvfb-run
, withXorg ? true
}:
let
Expand Down Expand Up @@ -48,6 +52,15 @@ let
installPhase = ''mv -T deps/ulauncher-prefs/dist $out'';
distPhase = "true";
};

# piece of shared makeWrapperArgs modifications to reuse in multiple places
wrapperArgs = ''
"''${makeWrapperArgs[@]}"
"''${gappsWrapperArgs[@]}"
${lib.optionalString withXorg ''--prefix LD_LIBRARY_PATH : "${lib.makeLibraryPath [ libX11 ]}"''}
--set-default ULAUNCHER_DATA_DIR "$out/share/ulauncher"
--prefix WEBKIT_DISABLE_COMPOSITING_MODE : "1"
'';
in
python3Packages.buildPythonPackage {
inherit version pname src;
Expand Down Expand Up @@ -84,10 +97,15 @@ python3Packages.buildPythonPackage {
];

nativeCheckInputs = with python3Packages; [
black
mock
pytest
pytest-mock
xvfb-run
] ++ [
mypy
ruff
typos
xvfb-run # xvfb-run tests fail
];

patches = [
Expand All @@ -113,39 +131,40 @@ python3Packages.buildPythonPackage {
ln -s "${preferences}" data/preferences
'';

# https://github.com/Ulauncher/Ulauncher/issues/390
doCheck = false;
doCheck = true;

preCheck = ''
patchShebangs ul
export PYTHONPATH=$PYTHONPATH:$out/${python3Packages.python.sitePackages}
export HOME=$TMPDIR
substituteInPlace \
scripts/tests.sh \
--replace ' pytest ' ' pytest -p no:cacheprovider '
substituteInPlace \
tests/modes/shortcuts/test_RunScript.py \
--replace '#!/bin/bash' '#!${stdenv.shell}'
# this is required to run tests
ulWrapperArgs=(${wrapperArgs})
wrapProgram ul "''${ulWrapperArgs[@]}"
'';

# Simple translation of
# - https://github.com/Ulauncher/Ulauncher/blob/f5a601bdca75198a6a31b9d84433496b63530e74/test
checkPhase = ''
runHook preCheck
# skip tests in invocation that handle paths that
# aren't nix friendly (i think)
xvfb-run -s '-screen 0 1024x768x16' \
pytest -k 'not TestPath and not test_handle_key_press_event' tests
./ul test
runHook postCheck
'';

# do not double wrap
dontWrapGApps = true;
preFixup = ''
makeWrapperArgs+=(
"''${gappsWrapperArgs[@]}"
${lib.optionalString withXorg ''--prefix LD_LIBRARY_PATH : "${lib.makeLibraryPath [ libX11 ]}"''}
--set-default ULAUNCHER_DATA_DIR "$out/share/ulauncher"
--prefix WEBKIT_DISABLE_COMPOSITING_MODE : "1"
)
makeWrapperArgs=(${wrapperArgs})
'';
# TODO: try to create a Python binary wrapper to load into IntelliJ for development
# makeWrapper "${python3Packages.python}/bin/python" $out/bin/ulauncher-python "''${makeWrapperArgs[@]}"


passthru = {
updateScript = nix-update-script { };
Expand Down

0 comments on commit 744d004

Please sign in to comment.