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,
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

View File

@@ -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)

View File

@@ -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

View File

@@ -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()