From 4e42f6bcb3506355cb84a71b9a8af501e936b976 Mon Sep 17 00:00:00 2001 From: "Markus S. Wamser" Date: Fri, 10 Dec 2021 22:03:06 +0100 Subject: [PATCH 1/2] writers.writePython2: remove --- .../manual/release-notes/rl-2205.section.md | 2 ++ pkgs/build-support/writers/aliases.nix | 35 +++++++++++++++++++ pkgs/build-support/writers/default.nix | 31 +++++----------- pkgs/build-support/writers/test.nix | 27 -------------- 4 files changed, 46 insertions(+), 49 deletions(-) create mode 100644 pkgs/build-support/writers/aliases.nix diff --git a/nixos/doc/manual/release-notes/rl-2205.section.md b/nixos/doc/manual/release-notes/rl-2205.section.md index 2c75718bb1ed..aceb4134bbba 100644 --- a/nixos/doc/manual/release-notes/rl-2205.section.md +++ b/nixos/doc/manual/release-notes/rl-2205.section.md @@ -34,6 +34,8 @@ In addition to numerous new and upgraded packages, this release has the followin - `pkgs.claws-mail-gtk2`, representing Claws Mail's older release version three, was removed in order to get rid of Python 2. Please switch to `claws-mail`, which is Claws Mail's latest release based on GTK+3 and Python 3. +- The `writers.writePython2` and corrersponding `writers.writePython2Bin` convenience functions to create executable Python 2 scripts in the store were removed in preparation of removal of the Python 2 interpreter. + ## Other Notable Changes {#sec-release-22.05-notable-changes} - The option [services.redis.servers](#opt-services.redis.servers) was added diff --git a/pkgs/build-support/writers/aliases.nix b/pkgs/build-support/writers/aliases.nix new file mode 100644 index 000000000000..fb108a6fd857 --- /dev/null +++ b/pkgs/build-support/writers/aliases.nix @@ -0,0 +1,35 @@ +lib: prev: + +let + # Removing recurseForDerivation prevents derivations of aliased attribute + # set to appear while listing all the packages available. + removeRecurseForDerivations = alias: with lib; + if alias.recurseForDerivations or false then + removeAttrs alias ["recurseForDerivations"] + else alias; + + # Disabling distribution prevents top-level aliases for non-recursed package + # sets from building on Hydra. + removeDistribute = alias: with lib; + if isDerivation alias then + dontDistribute alias + else alias; + + # Make sure that we are not shadowing something from + # writers. + checkInPkgs = n: alias: if builtins.hasAttr n prev + then throw "Alias ${n} is still in writers" + else alias; + + mapAliases = aliases: + lib.mapAttrs (n: alias: removeDistribute + (removeRecurseForDerivations + (checkInPkgs n alias))) + aliases; + +in +mapAliases ({ + /* Cleanup before 22.05, Added 2021-12-11 */ + writePython2 = "Python 2 is EOL and the use of writers.writePython2 is deprecated."; + writePython2Bin = "Python 2 is EOL and the use of writers.writePython2Bin is deprecated."; +}) diff --git a/pkgs/build-support/writers/default.nix b/pkgs/build-support/writers/default.nix index 3797df56afa5..e16c00534f83 100644 --- a/pkgs/build-support/writers/default.nix +++ b/pkgs/build-support/writers/default.nix @@ -1,7 +1,9 @@ -{ pkgs, buildPackages, lib, stdenv, libiconv, gawk, gnused, gixy }: +{ pkgs, config, buildPackages, lib, stdenv, libiconv, gawk, gnused, gixy }: -with lib; -rec { +let + aliases = if (config.allowAliases or true) then (import ./aliases.nix lib) else prev: {}; + + writers = with lib; rec { # Base implementation for non-compiled executables. # Takes an interpreter, for example `${pkgs.bash}/bin/bash` # @@ -245,24 +247,6 @@ rec { ''); } name; - # writePython2 takes a name an attributeset with libraries and some python2 sourcecode and - # returns an executable - # - # Example: - # writePython2 "test_python2" { libraries = [ pkgs.python2Packages.enum ]; } '' - # from enum import Enum - # - # class Test(Enum): - # a = "success" - # - # print Test.a - # '' - writePython2 = makePythonWriter pkgs.python2 pkgs.python2Packages; - - # writePython2Bin takes the same arguments as writePython2 but outputs a directory (like writeScriptBin) - writePython2Bin = name: - writePython2 "/bin/${name}"; - # writePython3 takes a name an attributeset with libraries and some python3 sourcecode and # returns an executable # @@ -280,4 +264,7 @@ rec { # writePython3Bin takes the same arguments as writePython3 but outputs a directory (like writeScriptBin) writePython3Bin = name: writePython3 "/bin/${name}"; -} + +}; +in +writers // (aliases writers) diff --git a/pkgs/build-support/writers/test.nix b/pkgs/build-support/writers/test.nix index 69bc7dd2c61a..8b7007e38699 100644 --- a/pkgs/build-support/writers/test.nix +++ b/pkgs/build-support/writers/test.nix @@ -3,7 +3,6 @@ , lib , nodePackages , perlPackages -, python2Packages , python3Packages , runCommand , writers @@ -54,17 +53,6 @@ let print "success\n" if true; ''; - python2 = writePython2Bin "test-writers-python2-bin" { libraries = [ python2Packages.enum ]; } '' - from enum import Enum - - - class Test(Enum): - a = "success" - - - print Test.a - ''; - python3 = writePython3Bin "test-writers-python3-bin" { libraries = [ python3Packages.pyyaml ]; } '' import yaml @@ -111,17 +99,6 @@ let print "success\n" if true; ''; - python2 = writePython2 "test-writers-python2" { libraries = [ python2Packages.enum ]; } '' - from enum import Enum - - - class Test(Enum): - a = "success" - - - print Test.a - ''; - python3 = writePython3 "test-writers-python3" { libraries = [ python3Packages.pyyaml ]; } '' import yaml @@ -131,10 +108,6 @@ let print(y[0]['test']) ''; - python2NoLibs = writePython2 "test-writers-python2-no-libs" {} '' - print("success") - ''; - python3NoLibs = writePython3 "test-writers-python3-no-libs" {} '' print("success") ''; From b93e478777f80dc259a003228130e4c1f8666d35 Mon Sep 17 00:00:00 2001 From: "Markus S. Wamser" Date: Sat, 11 Dec 2021 14:02:38 +0100 Subject: [PATCH 2/2] writers.PyPy{2,3}: init --- .../from_md/release-notes/rl-2205.section.xml | 23 ++++++++- .../manual/release-notes/rl-2205.section.md | 5 +- pkgs/build-support/writers/default.nix | 36 +++++++++++++ pkgs/build-support/writers/test.nix | 50 +++++++++++++++++++ 4 files changed, 112 insertions(+), 2 deletions(-) diff --git a/nixos/doc/manual/from_md/release-notes/rl-2205.section.xml b/nixos/doc/manual/from_md/release-notes/rl-2205.section.xml index 2a65b2f11a88..d02f951a03ca 100644 --- a/nixos/doc/manual/from_md/release-notes/rl-2205.section.xml +++ b/nixos/doc/manual/from_md/release-notes/rl-2205.section.xml @@ -83,11 +83,22 @@ release based on GTK+3 and Python 3. + + + The writers.writePython2 and corresponding + writers.writePython2Bin convenience + functions to create executable Python 2 scripts in the store + were removed in preparation of removal of the Python 2 + interpreter. Scripts have to be converted to Python 3 for use + with writers.writePython3 or + writers.writePyPy2 needs to be used. + +
Other Notable Changes - + The option @@ -113,6 +124,16 @@ socket /run/redis-${serverName}/redis.sock. + + + The + writers.writePyPy2/writers.writePyPy3 + and corresponding + writers.writePyPy2Bin/writers.writePyPy3Bin + convenience functions to create executable Python 2/3 scripts + using the PyPy interpreter were added. + +
diff --git a/nixos/doc/manual/release-notes/rl-2205.section.md b/nixos/doc/manual/release-notes/rl-2205.section.md index aceb4134bbba..11e5462b3316 100644 --- a/nixos/doc/manual/release-notes/rl-2205.section.md +++ b/nixos/doc/manual/release-notes/rl-2205.section.md @@ -34,7 +34,8 @@ In addition to numerous new and upgraded packages, this release has the followin - `pkgs.claws-mail-gtk2`, representing Claws Mail's older release version three, was removed in order to get rid of Python 2. Please switch to `claws-mail`, which is Claws Mail's latest release based on GTK+3 and Python 3. -- The `writers.writePython2` and corrersponding `writers.writePython2Bin` convenience functions to create executable Python 2 scripts in the store were removed in preparation of removal of the Python 2 interpreter. +- The `writers.writePython2` and corresponding `writers.writePython2Bin` convenience functions to create executable Python 2 scripts in the store were removed in preparation of removal of the Python 2 interpreter. + Scripts have to be converted to Python 3 for use with `writers.writePython3` or `writers.writePyPy2` needs to be used. ## Other Notable Changes {#sec-release-22.05-notable-changes} @@ -53,3 +54,5 @@ In addition to numerous new and upgraded packages, this release has the followin are only accessible by default to the members of the Unix group `redis-${serverName}` through the Unix socket `/run/redis-${serverName}/redis.sock`. + +- The `writers.writePyPy2`/`writers.writePyPy3` and corresponding `writers.writePyPy2Bin`/`writers.writePyPy3Bin` convenience functions to create executable Python 2/3 scripts using the PyPy interpreter were added. diff --git a/pkgs/build-support/writers/default.nix b/pkgs/build-support/writers/default.nix index e16c00534f83..30301e3b2e54 100644 --- a/pkgs/build-support/writers/default.nix +++ b/pkgs/build-support/writers/default.nix @@ -247,6 +247,24 @@ let ''); } name; + # writePyPy2 takes a name an attributeset with libraries and some pypy2 sourcecode and + # returns an executable + # + # Example: + # writePyPy2 "test_pypy2" { libraries = [ pkgs.pypy2Packages.enum ]; } '' + # from enum import Enum + # + # class Test(Enum): + # a = "success" + # + # print Test.a + # '' + writePyPy2 = makePythonWriter pkgs.pypy2 pkgs.pypy2Packages; + + # writePyPy2Bin takes the same arguments as writePyPy2 but outputs a directory (like writeScriptBin) + writePyPy2Bin = name: + writePyPy2 "/bin/${name}"; + # writePython3 takes a name an attributeset with libraries and some python3 sourcecode and # returns an executable # @@ -265,6 +283,24 @@ let writePython3Bin = name: writePython3 "/bin/${name}"; + # writePyPy3 takes a name an attributeset with libraries and some pypy3 sourcecode and + # returns an executable + # + # Example: + # writePyPy3 "test_pypy3" { libraries = [ pkgs.pypy3Packages.pyyaml ]; } '' + # import yaml + # + # y = yaml.load(""" + # - test: success + # """) + # print(y[0]['test']) + # '' + writePyPy3 = makePythonWriter pkgs.pypy3 pkgs.pypy3Packages; + + # writePyPy3Bin takes the same arguments as writePyPy3 but outputs a directory (like writeScriptBin) + writePyPy3Bin = name: + writePyPy3 "/bin/${name}"; + }; in writers // (aliases writers) diff --git a/pkgs/build-support/writers/test.nix b/pkgs/build-support/writers/test.nix index 8b7007e38699..decd7e42d5cc 100644 --- a/pkgs/build-support/writers/test.nix +++ b/pkgs/build-support/writers/test.nix @@ -3,7 +3,9 @@ , lib , nodePackages , perlPackages +, pypy2Packages , python3Packages +, pypy3Packages , runCommand , writers , writeText @@ -53,6 +55,17 @@ let print "success\n" if true; ''; + pypy2 = writePyPy2Bin "test-writers-pypy2-bin" { libraries = [ pypy2Packages.enum ]; } '' + from enum import Enum + + + class Test(Enum): + a = "success" + + + print Test.a + ''; + python3 = writePython3Bin "test-writers-python3-bin" { libraries = [ python3Packages.pyyaml ]; } '' import yaml @@ -61,6 +74,15 @@ let """) print(y[0]['test']) ''; + + pypy3 = writePyPy3Bin "test-writers-pypy3-bin" { libraries = [ pypy3Packages.pyyaml ]; } '' + import yaml + + y = yaml.load(""" + - test: success + """) + print(y[0]['test']) + ''; }; simple = { @@ -99,6 +121,17 @@ let print "success\n" if true; ''; + pypy2 = writePyPy2 "test-writers-pypy2" { libraries = [ pypy2Packages.enum ]; } '' + from enum import Enum + + + class Test(Enum): + a = "success" + + + print Test.a + ''; + python3 = writePython3 "test-writers-python3" { libraries = [ python3Packages.pyyaml ]; } '' import yaml @@ -108,9 +141,26 @@ let print(y[0]['test']) ''; + pypy3 = writePyPy3 "test-writers-pypy3" { libraries = [ pypy3Packages.pyyaml ]; } '' + import yaml + + y = yaml.load(""" + - test: success + """) + print(y[0]['test']) + ''; + + pypy2NoLibs = writePyPy2 "test-writers-pypy2-no-libs" {} '' + print("success") + ''; + python3NoLibs = writePython3 "test-writers-python3-no-libs" {} '' print("success") ''; + + pypy3NoLibs = writePyPy3 "test-writers-pypy3-no-libs" {} '' + print("success") + ''; };