diff options
author | Adrian Gierakowski <agierakowski@gmail.com> | 2020-07-24 11:31:01 +0100 |
---|---|---|
committer | Adrian Gierakowski <agierakowski@gmail.com> | 2020-07-24 11:39:01 +0100 |
commit | 76437a88bb64e66b1b21d4a1da7f22ea8ccebc2d (patch) | |
tree | 10fa59caacf19f45028973d8bba025de84fda5e8 /pkgs/build-support/writers | |
parent | d9047049d29a93d3713ea8eb0d538ad7e8f823d7 (diff) | |
download | nixpkgs-76437a88bb64e66b1b21d4a1da7f22ea8ccebc2d.tar nixpkgs-76437a88bb64e66b1b21d4a1da7f22ea8ccebc2d.tar.gz nixpkgs-76437a88bb64e66b1b21d4a1da7f22ea8ccebc2d.tar.bz2 nixpkgs-76437a88bb64e66b1b21d4a1da7f22ea8ccebc2d.tar.lz nixpkgs-76437a88bb64e66b1b21d4a1da7f22ea8ccebc2d.tar.xz nixpkgs-76437a88bb64e66b1b21d4a1da7f22ea8ccebc2d.tar.zst nixpkgs-76437a88bb64e66b1b21d4a1da7f22ea8ccebc2d.zip |
writers.writePython2 and writePython3: use "bare" python if no deps are needed
`python.withPackages` has a runtime dependecy on bash since it's wrapped with `makeWrapper`. This fix avoids bash as runtime dependency when it's not needed. as discussed here: https://github.com/NixOS/nixpkgs/issues/93609#issuecomment-662880047
Diffstat (limited to 'pkgs/build-support/writers')
-rw-r--r-- | pkgs/build-support/writers/default.nix | 42 | ||||
-rw-r--r-- | pkgs/build-support/writers/test.nix | 8 |
2 files changed, 28 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: diff --git a/pkgs/build-support/writers/test.nix b/pkgs/build-support/writers/test.nix index 3cd0a080ae8..d284bda43d0 100644 --- a/pkgs/build-support/writers/test.nix +++ b/pkgs/build-support/writers/test.nix @@ -152,6 +152,14 @@ let """) print(y[0]['test']) ''; + + python2NoLibs = writePython2 "test_python2_no_libs" {} '' + print("success") + ''; + + python3NoLibs = writePython3 "test_python3_no_libs" {} '' + print("success") + ''; }; |