summary refs log tree commit diff
path: root/pkgs/build-support/writers/default.nix
diff options
context:
space:
mode:
authorLassulus <github@lassul.us>2020-07-25 11:43:56 +0200
committerGitHub <noreply@github.com>2020-07-25 11:43:56 +0200
commita2ba53f4e130698e7d1ab7f18ebce1883d29d29a (patch)
treeb30ff54fc0ceac216f914287274a4c143c47587b /pkgs/build-support/writers/default.nix
parent032775d0acbd901bcaf30e2e603d836a68eb016b (diff)
parent76437a88bb64e66b1b21d4a1da7f22ea8ccebc2d (diff)
downloadnixpkgs-a2ba53f4e130698e7d1ab7f18ebce1883d29d29a.tar
nixpkgs-a2ba53f4e130698e7d1ab7f18ebce1883d29d29a.tar.gz
nixpkgs-a2ba53f4e130698e7d1ab7f18ebce1883d29d29a.tar.bz2
nixpkgs-a2ba53f4e130698e7d1ab7f18ebce1883d29d29a.tar.lz
nixpkgs-a2ba53f4e130698e7d1ab7f18ebce1883d29d29a.tar.xz
nixpkgs-a2ba53f4e130698e7d1ab7f18ebce1883d29d29a.tar.zst
nixpkgs-a2ba53f4e130698e7d1ab7f18ebce1883d29d29a.zip
Merge pull request #93758 from adrian-gierakowski/improve-writers.writePython
writers.writePython2 and writePython3: use "bare" python if no deps are needed
Diffstat (limited to 'pkgs/build-support/writers/default.nix')
-rw-r--r--pkgs/build-support/writers/default.nix42
1 files changed, 20 insertions, 22 deletions
diff --git a/pkgs/build-support/writers/default.nix b/pkgs/build-support/writers/default.nix
index af492d80db0..43785546acb 100644
--- a/pkgs/build-support/writers/default.nix
+++ b/pkgs/build-support/writers/default.nix
@@ -227,6 +227,24 @@ rec {
   writePerlBin = name:
     writePerl "/bin/${name}";
 
+  # makePythonWriter takes python and compatible pythonPackages and produces python script writer,
+  # which validates the script with flake8 at build time. If any libraries are specified,
+  # python.withPackages is used as interpreter, otherwise the "bare" python is used.
+  makePythonWriter = python: pythonPackages: name: { libraries ? [], flakeIgnore ? [] }:
+  let
+    ignoreAttribute = optionalString (flakeIgnore != []) "--ignore ${concatMapStringsSep "," escapeShellArg flakeIgnore}";
+  in
+  makeScriptWriter {
+    interpreter =
+      if libraries == []
+      then "${python}/bin/python"
+      else "${python.withPackages (ps: libraries)}/bin/python"
+    ;
+    check = writeDash "python2check.sh" ''
+      exec ${pythonPackages.flake8}/bin/flake8 --show-source ${ignoreAttribute} "$1"
+    '';
+  } name;
+
   # writePython2 takes a name an attributeset with libraries and some python2 sourcecode and
   # returns an executable
   #
@@ -239,17 +257,7 @@ rec {
   #
   #   print Test.a
   # ''
-  writePython2 = name: { libraries ? [], flakeIgnore ? [] }:
-  let
-    py = pkgs.python2.withPackages (ps: libraries);
-    ignoreAttribute = optionalString (flakeIgnore != []) "--ignore ${concatMapStringsSep "," escapeShellArg flakeIgnore}";
-  in
-  makeScriptWriter {
-    interpreter = "${py}/bin/python";
-    check = writeDash "python2check.sh" ''
-      exec ${pkgs.python2Packages.flake8}/bin/flake8 --show-source ${ignoreAttribute} "$1"
-    '';
-  } name;
+  writePython2 = makePythonWriter pkgs.python2 pkgs.python2Packages;
 
   # writePython2Bin takes the same arguments as writePython2 but outputs a directory (like writeScriptBin)
   writePython2Bin = name:
@@ -267,17 +275,7 @@ rec {
   #   """)
   #   print(y[0]['test'])
   # ''
-  writePython3 = name: { libraries ? [], flakeIgnore ? [] }:
-  let
-    py = pkgs.python3.withPackages (ps: libraries);
-    ignoreAttribute = optionalString (flakeIgnore != []) "--ignore ${concatMapStringsSep "," escapeShellArg flakeIgnore}";
-  in
-  makeScriptWriter {
-    interpreter = "${py}/bin/python";
-    check = writeDash "python3check.sh" ''
-      exec ${pkgs.python3Packages.flake8}/bin/flake8 --show-source ${ignoreAttribute} "$1"
-    '';
-  } name;
+  writePython3 = makePythonWriter pkgs.python3 pkgs.python3Packages;
 
   # writePython3Bin takes the same arguments as writePython3 but outputs a directory (like writeScriptBin)
   writePython3Bin = name: