From 56d9637119ef4f05be20887ed09b2a2b760e6dae Mon Sep 17 00:00:00 2001 From: Robert Hensing Date: Sat, 8 May 2021 17:52:22 +0200 Subject: nixos/testing: Set up scope for testScript linter Our test driver exposes a bunch of variables and functions, which pyflakes doesn't recognise by default because it assumes that the test script is executed standalone. In reality however the test driver script is using exec() on the testScript. Fortunately pyflakes has $PYFLAKES_BUILTINS, which are the attributes that are globally available on all modules to be checked. Since we only have one module, using this environment variable is fine as opposed to my first approach to this, which tried to use the unstable internal API of pyflakes. The attributes are gathered by the main derivation of the test driver, because we don't want to end up defining a new attribute in the test driver module just to being confused why using it in a test will result in an error. Another way we could have gathered these attributes would be in mkDriver, which is where the linting takes place. However, we do have a different set of Python dependencies in scope and duplicating these will again just cause confusion over having it at one location only. Signed-off-by: aszlig Co-Authored-By: aszlig --- nixos/lib/testing-python.nix | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) (limited to 'nixos') diff --git a/nixos/lib/testing-python.nix b/nixos/lib/testing-python.nix index fde52ba4fc1..679c31f3e35 100644 --- a/nixos/lib/testing-python.nix +++ b/nixos/lib/testing-python.nix @@ -32,6 +32,14 @@ rec { preferLocalBuild = true; + buildPhase = '' + python < $out/test-script ${lib.optionalString (!skipLint) '' - ${python3Packages.pyflakes}/bin/pyflakes $out/test-script + PYFLAKES_BUILTINS="$( + echo -n ${lib.escapeShellArg (lib.concatStringsSep "," nodeHostNames)}, + < ${lib.escapeShellArg "${testDriver}/nix-support/driver-exports"} + )" ${python3Packages.pyflakes}/bin/pyflakes $out/test-script ''} ln -s ${testDriver}/bin/nixos-test-driver $out/bin/ @@ -195,6 +208,8 @@ rec { (node: builtins.match "^[A-z_]([A-z0-9_]+)?$" node == null) nodeNames; + nodeHostNames = map (c: c.config.system.name) (lib.attrValues driver.nodes); + in if lib.length invalidNodeNames > 0 then throw '' -- cgit 1.4.1