From 32bdf963a60a13a86a3a97375c87d27743657f57 Mon Sep 17 00:00:00 2001 From: Qubasa Date: Tue, 7 Jan 2025 00:10:34 +0100 Subject: [PATCH] clan-app: Fix python3Full and python3 incompatibilities. 'pytest' not found and devshell bugs --- pkgs/clan-app/default.nix | 63 +++++++++++--------------------- pkgs/clan-app/shell.nix | 51 ++++++-------------------- pkgs/clan-app/tests/test_join.py | 3 -- pkgs/clan-app/tests/wayland.py | 6 ++- 4 files changed, 38 insertions(+), 85 deletions(-) diff --git a/pkgs/clan-app/default.nix b/pkgs/clan-app/default.nix index db019b595..e518ef71d 100644 --- a/pkgs/clan-app/default.nix +++ b/pkgs/clan-app/default.nix @@ -3,14 +3,8 @@ runCommand, setuptools, copyDesktopItems, - wrapGAppsHook4, clan-cli, makeDesktopItem, - 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 webview-ui, webview-lib, fontconfig, @@ -26,33 +20,27 @@ let mimeTypes = [ "x-scheme-handler/clan" ]; }; - # Dependencies that are directly used in the project but nor from internal python packages - externalPythonDeps = [ - - ]; - # Runtime binary dependencies required by the application runtimeDependencies = [ - webview-lib + ]; - # Deps including python packages from the local project - allPythonDeps = [ (python3Full.pkgs.toPythonModule clan-cli) ] ++ externalPythonDeps; - # Dependencies required for running tests - externalTestDeps = - externalPythonDeps - ++ runtimeDependencies - ++ [ - pytest # Testing framework + 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 - ]; + ] + ++ pytest.propagatedBuildInputs; + + clan-cli-module = [ (python3Full.pkgs.toPythonModule clan-cli) ]; - # Dependencies required for running tests - testDependencies = runtimeDependencies ++ allPythonDeps ++ externalTestDeps; in python3Full.pkgs.buildPythonApplication rec { name = "clan-app"; @@ -76,22 +64,15 @@ python3Full.pkgs.buildPythonApplication rec { nativeBuildInputs = [ setuptools copyDesktopItems - wrapGAppsHook4 + fontconfig ]; # The necessity of setting buildInputs and propagatedBuildInputs to the # 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 = allPythonDeps ++ runtimeDependencies; - propagatedBuildInputs = - allPythonDeps - ++ runtimeDependencies - ++ [ - - # TODO: see postFixup clan-cli/default.nix:L188 - clan-cli.propagatedBuildInputs - ]; + buildInputs = clan-cli-module ++ runtimeDependencies; + propagatedBuildInputs = buildInputs; # also re-expose dependencies so we test them in CI passthru = { @@ -99,9 +80,10 @@ python3Full.pkgs.buildPythonApplication rec { clan-app-pytest = runCommand "clan-app-pytest" { - buildInputs = buildInputs ++ externalTestDeps; - propagatedBuildInputs = propagatedBuildInputs ++ externalTestDeps; - inherit nativeBuildInputs; + buildInputs = runtimeDependencies ++ [ + (python3Full.withPackages (ps: clan-cli-module ++ (pyTestDeps ps))) + fontconfig + ]; } '' cp -r ${source} ./src @@ -121,9 +103,9 @@ python3Full.pkgs.buildPythonApplication rec { fc-list echo "STARTING ..." - export WEBVIEW_LIB_DIR "${webview-lib}/lib" + export WEBVIEW_LIB_DIR="${webview-lib}/lib" export NIX_STATE_DIR=$TMPDIR/nix IN_NIX_SANDBOX=1 - ${python3Full}/bin/python3 -m pytest -s -m "not impure" ./tests + python3 -m pytest -s -m "not impure" ./tests touch $out ''; }; @@ -131,10 +113,7 @@ python3Full.pkgs.buildPythonApplication rec { # Additional pass-through attributes passthru.desktop-file = desktop-file; - passthru.externalPythonDeps = externalPythonDeps; - passthru.externalTestDeps = externalTestDeps; - passthru.runtimeDependencies = runtimeDependencies; - passthru.testDependencies = testDependencies; + passthru.devshellDeps = ps: (pyTestDeps ps); postInstall = '' mkdir -p $out/${python3Full.sitePackages}/clan_app/.webui diff --git a/pkgs/clan-app/shell.nix b/pkgs/clan-app/shell.nix index 9015e6d4e..9d0cac805 100644 --- a/pkgs/clan-app/shell.nix +++ b/pkgs/clan-app/shell.nix @@ -1,56 +1,29 @@ { - lib, - glib, gsettings-desktop-schemas, - stdenv, clan-app, mkShell, ruff, - desktop-file-utils, - xdg-utils, - mypy, - python3, gtk4, - libadwaita, webview-lib, - clang, + python3Full, self', }: -let - devshellTestDeps = - clan-app.externalTestDeps - ++ (with python3.pkgs; [ - rope - mypy - setuptools - wheel - pip - ]); -in mkShell { - inherit (clan-app) nativeBuildInputs propagatedBuildInputs; inputsFrom = [ self'.devShells.default ]; - buildInputs = - [ - glib - ruff - gtk4 - clang - webview-lib.dev - webview-lib - gtk4.dev # has the demo called 'gtk4-widget-factory' - libadwaita.devdoc # has the demo called 'adwaita-1-demo' - ] - ++ devshellTestDeps - - # Dependencies for testing for linux hosts - ++ (lib.optionals stdenv.isLinux [ - xdg-utils # install desktop files - desktop-file-utils # verify desktop files - ]); + buildInputs = [ + (python3Full.withPackages ( + ps: + with ps; + [ + ruff + mypy + ] + ++ (clan-app.devshellDeps ps) + )) + ]; shellHook = '' export GIT_ROOT=$(git rev-parse --show-toplevel) diff --git a/pkgs/clan-app/tests/test_join.py b/pkgs/clan-app/tests/test_join.py index fff6de20c..a41f3fe02 100644 --- a/pkgs/clan-app/tests/test_join.py +++ b/pkgs/clan-app/tests/test_join.py @@ -1,8 +1,5 @@ -import time - from wayland import GtkProc def test_open(app: GtkProc) -> None: - time.sleep(0.5) assert app.poll() is None diff --git a/pkgs/clan-app/tests/wayland.py b/pkgs/clan-app/tests/wayland.py index 2e96688a5..9fa73961c 100644 --- a/pkgs/clan-app/tests/wayland.py +++ b/pkgs/clan-app/tests/wayland.py @@ -21,7 +21,11 @@ GtkProc = NewType("GtkProc", Popen) @pytest.fixture def app() -> Generator[GtkProc, None, None]: - rapp = Popen([sys.executable, "-m", "clan_app"], text=True) + cmd = [sys.executable, "-m", "clan_app"] + print(f"Running: {cmd}") + rapp = Popen( + cmd, text=True, stdout=sys.stdout, stderr=sys.stderr, start_new_session=True + ) yield GtkProc(rapp) # Cleanup: Terminate your application rapp.terminate()