clan-app: Fix python3Full and python3 incompatibilities. 'pytest' not found and devshell bugs

This commit is contained in:
Qubasa
2025-01-07 00:10:34 +01:00
parent 6a7da4ef11
commit 0db9944699
4 changed files with 38 additions and 85 deletions

View File

@@ -3,14 +3,8 @@
runCommand, runCommand,
setuptools, setuptools,
copyDesktopItems, copyDesktopItems,
wrapGAppsHook4,
clan-cli, clan-cli,
makeDesktopItem, 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-ui,
webview-lib, webview-lib,
fontconfig, fontconfig,
@@ -26,33 +20,27 @@ let
mimeTypes = [ "x-scheme-handler/clan" ]; 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 # Runtime binary dependencies required by the application
runtimeDependencies = [ runtimeDependencies = [
webview-lib
]; ];
# Deps including python packages from the local project
allPythonDeps = [ (python3Full.pkgs.toPythonModule clan-cli) ] ++ externalPythonDeps;
# Dependencies required for running tests # Dependencies required for running tests
externalTestDeps = pyTestDeps =
externalPythonDeps ps:
++ runtimeDependencies with ps;
++ [ [
pytest # Testing framework (python3Full.pkgs.toPythonModule pytest)
# Testing framework
pytest-cov # Generate coverage reports pytest-cov # Generate coverage reports
pytest-subprocess # fake the real subprocess behavior to make your tests more independent. pytest-subprocess # fake the real subprocess behavior to make your tests more independent.
pytest-xdist # Run tests in parallel on multiple cores pytest-xdist # Run tests in parallel on multiple cores
pytest-timeout # Add timeouts to your tests 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 in
python3Full.pkgs.buildPythonApplication rec { python3Full.pkgs.buildPythonApplication rec {
name = "clan-app"; name = "clan-app";
@@ -76,22 +64,15 @@ python3Full.pkgs.buildPythonApplication rec {
nativeBuildInputs = [ nativeBuildInputs = [
setuptools setuptools
copyDesktopItems copyDesktopItems
wrapGAppsHook4 fontconfig
]; ];
# The necessity of setting buildInputs and propagatedBuildInputs to the # The necessity of setting buildInputs and propagatedBuildInputs to the
# same values for your Python package within Nix largely stems from ensuring # same values for your Python package within Nix largely stems from ensuring
# that all necessary dependencies are consistently available both # that all necessary dependencies are consistently available both
# at build time and runtime, # at build time and runtime,
buildInputs = allPythonDeps ++ runtimeDependencies; buildInputs = clan-cli-module ++ runtimeDependencies;
propagatedBuildInputs = propagatedBuildInputs = buildInputs;
allPythonDeps
++ runtimeDependencies
++ [
# TODO: see postFixup clan-cli/default.nix:L188
clan-cli.propagatedBuildInputs
];
# also re-expose dependencies so we test them in CI # also re-expose dependencies so we test them in CI
passthru = { passthru = {
@@ -99,9 +80,10 @@ python3Full.pkgs.buildPythonApplication rec {
clan-app-pytest = clan-app-pytest =
runCommand "clan-app-pytest" runCommand "clan-app-pytest"
{ {
buildInputs = buildInputs ++ externalTestDeps; buildInputs = runtimeDependencies ++ [
propagatedBuildInputs = propagatedBuildInputs ++ externalTestDeps; (python3Full.withPackages (ps: clan-cli-module ++ (pyTestDeps ps)))
inherit nativeBuildInputs; fontconfig
];
} }
'' ''
cp -r ${source} ./src cp -r ${source} ./src
@@ -121,9 +103,9 @@ python3Full.pkgs.buildPythonApplication rec {
fc-list fc-list
echo "STARTING ..." 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 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 touch $out
''; '';
}; };
@@ -131,10 +113,7 @@ python3Full.pkgs.buildPythonApplication rec {
# Additional pass-through attributes # Additional pass-through attributes
passthru.desktop-file = desktop-file; passthru.desktop-file = desktop-file;
passthru.externalPythonDeps = externalPythonDeps; passthru.devshellDeps = ps: (pyTestDeps ps);
passthru.externalTestDeps = externalTestDeps;
passthru.runtimeDependencies = runtimeDependencies;
passthru.testDependencies = testDependencies;
postInstall = '' postInstall = ''
mkdir -p $out/${python3Full.sitePackages}/clan_app/.webui mkdir -p $out/${python3Full.sitePackages}/clan_app/.webui

View File

@@ -1,56 +1,29 @@
{ {
lib,
glib,
gsettings-desktop-schemas, gsettings-desktop-schemas,
stdenv,
clan-app, clan-app,
mkShell, mkShell,
ruff, ruff,
desktop-file-utils,
xdg-utils,
mypy,
python3,
gtk4, gtk4,
libadwaita,
webview-lib, webview-lib,
clang, python3Full,
self', self',
}: }:
let
devshellTestDeps =
clan-app.externalTestDeps
++ (with python3.pkgs; [
rope
mypy
setuptools
wheel
pip
]);
in
mkShell { mkShell {
inherit (clan-app) nativeBuildInputs propagatedBuildInputs;
inputsFrom = [ self'.devShells.default ]; inputsFrom = [ self'.devShells.default ];
buildInputs = buildInputs = [
[ (python3Full.withPackages (
glib ps:
ruff with ps;
gtk4 [
clang ruff
webview-lib.dev mypy
webview-lib ]
gtk4.dev # has the demo called 'gtk4-widget-factory' ++ (clan-app.devshellDeps ps)
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
]);
shellHook = '' shellHook = ''
export GIT_ROOT=$(git rev-parse --show-toplevel) export GIT_ROOT=$(git rev-parse --show-toplevel)

View File

@@ -1,8 +1,5 @@
import time
from wayland import GtkProc from wayland import GtkProc
def test_open(app: GtkProc) -> None: def test_open(app: GtkProc) -> None:
time.sleep(0.5)
assert app.poll() is None assert app.poll() is None

View File

@@ -21,7 +21,11 @@ GtkProc = NewType("GtkProc", Popen)
@pytest.fixture @pytest.fixture
def app() -> Generator[GtkProc, None, None]: 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) yield GtkProc(rapp)
# Cleanup: Terminate your application # Cleanup: Terminate your application
rapp.terminate() rapp.terminate()