treewide: Format all Nix files

Format all Nix files using the officially approved formatter,
making the CI check introduced in the previous commit succeed:

  nix-build ci -A fmt.check

This is the next step of the of the [implementation](https://github.com/NixOS/nixfmt/issues/153)
of the accepted [RFC 166](https://github.com/NixOS/rfcs/pull/166).

This commit will lead to merge conflicts for a number of PRs,
up to an estimated ~1100 (~33%) among the PRs with activity in the past 2
months, but that should be lower than what it would be without the previous
[partial treewide format](https://github.com/NixOS/nixpkgs/pull/322537).

Merge conflicts caused by this commit can now automatically be resolved while rebasing using the
[auto-rebase script](https://github.com/NixOS/nixpkgs/tree/8616af08d915377bd930395f3b700a0e93d08728/maintainers/scripts/auto-rebase).

If you run into any problems regarding any of this, please reach out to the
[formatting team](https://nixos.org/community/teams/formatting/) by
pinging @NixOS/nix-formatting.
This commit is contained in:
Silvan Mosberger
2025-04-01 20:10:43 +02:00
parent 2140bf39e4
commit 374e6bcc40
1523 changed files with 986039 additions and 513613 deletions
@@ -1,83 +1,96 @@
{ lib, stdenv, fetchFromGitHub, fetchpatch
, bzip2
, expat
, libffi
, gdbm
, db
, ncurses
, openssl
, readline
, sqlite
, tcl ? null, tk ? null, tclPackages, libX11 ? null, x11Support ? false
, zlib
, self
, coreutils
, autoreconfHook
, python-setup-hook
# Some proprietary libs assume UCS2 unicode, especially on darwin :(
, ucsEncoding ? 4
# For the Python package set
, packageOverrides ? (self: super: {})
, pkgsBuildBuild
, pkgsBuildHost
, pkgsBuildTarget
, pkgsHostHost
, pkgsTargetTarget
, sourceVersion
, hash
, passthruFun
, static ? stdenv.hostPlatform.isStatic
, stripBytecode ? reproducibleBuild
, rebuildBytecode ? true
, reproducibleBuild ? false
, enableOptimizations ? false
, strip2to3 ? false
, stripConfig ? false
, stripIdlelib ? false
, stripTests ? false
, pythonAttr ? "python${sourceVersion.major}${sourceVersion.minor}"
{
lib,
stdenv,
fetchFromGitHub,
fetchpatch,
bzip2,
expat,
libffi,
gdbm,
db,
ncurses,
openssl,
readline,
sqlite,
tcl ? null,
tk ? null,
tclPackages,
libX11 ? null,
x11Support ? false,
zlib,
self,
coreutils,
autoreconfHook,
python-setup-hook,
# Some proprietary libs assume UCS2 unicode, especially on darwin :(
ucsEncoding ? 4,
# For the Python package set
packageOverrides ? (self: super: { }),
pkgsBuildBuild,
pkgsBuildHost,
pkgsBuildTarget,
pkgsHostHost,
pkgsTargetTarget,
sourceVersion,
hash,
passthruFun,
static ? stdenv.hostPlatform.isStatic,
stripBytecode ? reproducibleBuild,
rebuildBytecode ? true,
reproducibleBuild ? false,
enableOptimizations ? false,
strip2to3 ? false,
stripConfig ? false,
stripIdlelib ? false,
stripTests ? false,
pythonAttr ? "python${sourceVersion.major}${sourceVersion.minor}",
}:
assert x11Support -> tcl != null
&& tk != null
&& libX11 != null;
assert x11Support -> tcl != null && tk != null && libX11 != null;
assert lib.assertMsg (enableOptimizations -> (!stdenv.cc.isClang))
"Optimizations with clang are not supported. configure: error: llvm-profdata is required for a --enable-optimizations build but could not be found.";
assert lib.assertMsg (reproducibleBuild -> stripBytecode)
"Deterministic builds require stripping bytecode.";
assert lib.assertMsg (
reproducibleBuild -> stripBytecode
) "Deterministic builds require stripping bytecode.";
assert lib.assertMsg (reproducibleBuild -> (!enableOptimizations))
"Deterministic builds are not achieved when optimizations are enabled.";
assert lib.assertMsg (
reproducibleBuild -> (!enableOptimizations)
) "Deterministic builds are not achieved when optimizations are enabled.";
assert lib.assertMsg (reproducibleBuild -> (!rebuildBytecode))
"Deterministic builds are not achieved when (default unoptimized) bytecode is created.";
assert lib.assertMsg (
reproducibleBuild -> (!rebuildBytecode)
) "Deterministic builds are not achieved when (default unoptimized) bytecode is created.";
let
buildPackages = pkgsBuildHost;
inherit (passthru) pythonOnBuildForHost;
pythonOnBuildForHostInterpreter = if stdenv.hostPlatform == stdenv.buildPlatform then
"$out/bin/python"
else pythonOnBuildForHost.interpreter;
pythonOnBuildForHostInterpreter =
if stdenv.hostPlatform == stdenv.buildPlatform then
"$out/bin/python"
else
pythonOnBuildForHost.interpreter;
passthru = passthruFun rec {
inherit self sourceVersion packageOverrides;
implementation = "cpython";
libPrefix = "python${pythonVersion}";
executable = libPrefix;
pythonVersion = with sourceVersion; "${major}.${minor}";
sitePackages = "lib/${libPrefix}/site-packages";
inherit hasDistutilsCxxPatch pythonAttr;
pythonOnBuildForBuild = pkgsBuildBuild.${pythonAttr};
pythonOnBuildForHost = pkgsBuildHost.${pythonAttr};
pythonOnBuildForTarget = pkgsBuildTarget.${pythonAttr};
pythonOnHostForHost = pkgsHostHost.${pythonAttr};
pythonOnTargetForTarget = pkgsTargetTarget.${pythonAttr} or {};
} // {
inherit ucsEncoding;
};
passthru =
passthruFun rec {
inherit self sourceVersion packageOverrides;
implementation = "cpython";
libPrefix = "python${pythonVersion}";
executable = libPrefix;
pythonVersion = with sourceVersion; "${major}.${minor}";
sitePackages = "lib/${libPrefix}/site-packages";
inherit hasDistutilsCxxPatch pythonAttr;
pythonOnBuildForBuild = pkgsBuildBuild.${pythonAttr};
pythonOnBuildForHost = pkgsBuildHost.${pythonAttr};
pythonOnBuildForTarget = pkgsBuildTarget.${pythonAttr};
pythonOnHostForHost = pkgsHostHost.${pythonAttr};
pythonOnTargetForTarget = pkgsTargetTarget.${pythonAttr} or { };
}
// {
inherit ucsEncoding;
};
version = with sourceVersion; "${major}.${minor}.${patch}${suffix}";
@@ -92,7 +105,8 @@ let
hasDistutilsCxxPatch = !(stdenv.cc.isGNU or false);
patches =
[ # Look in C_INCLUDE_PATH and LIBRARY_PATH for stuff.
[
# Look in C_INCLUDE_PATH and LIBRARY_PATH for stuff.
./search-path.patch
# Python recompiles a Python if the mtime stored *in* the
@@ -137,10 +151,12 @@ let
revert = true;
hash = "sha256-Lp5fGlcfJJ6p6vKmcLckJiAA2AZz4prjFE0aMEJxotw=";
})
] ++ lib.optionals (x11Support && stdenv.hostPlatform.isDarwin) [
]
++ lib.optionals (x11Support && stdenv.hostPlatform.isDarwin) [
./use-correct-tcl-tk-on-darwin.patch
] ++ lib.optionals stdenv.hostPlatform.isLinux [
]
++ lib.optionals stdenv.hostPlatform.isLinux [
# Disable the use of ldconfig in ctypes.util.find_library (since
# ldconfig doesn't work on NixOS), and don't use
@@ -152,7 +168,8 @@ let
# Fix ctypes.util.find_library with gcc10.
./find_library-gcc10.patch
] ++ lib.optionals stdenv.hostPlatform.isCygwin [
]
++ lib.optionals stdenv.hostPlatform.isCygwin [
./2.5.2-ctypes-util-find_library.patch
./2.5.2-tkinter-x11.patch
./2.6.2-ssl-threads.patch
@@ -163,7 +180,8 @@ let
./2.7.3-dylib.patch
./2.7.3-getpath-exe-extension.patch
./2.7.3-no-libm.patch
] ++ lib.optionals hasDistutilsCxxPatch [
]
++ lib.optionals hasDistutilsCxxPatch [
# Patch from http://bugs.python.org/issue1222585 adapted to work with
# `patch -p1' and with a last hunk removed
@@ -171,75 +189,102 @@ let
# only works for GCC and Apple Clang. This makes distutils to call C++
# compiler when needed.
./python-2.7-distutils-C++.patch
] ++ lib.optionals (stdenv.hostPlatform != stdenv.buildPlatform) [
]
++ lib.optionals (stdenv.hostPlatform != stdenv.buildPlatform) [
./cross-compile.patch
];
preConfigure = ''
preConfigure =
''
# Purity.
for i in /usr /sw /opt /pkg; do
substituteInPlace ./setup.py --replace $i /no-such-path
done
'' + lib.optionalString (stdenv ? cc && stdenv.cc.libc != null) ''
''
+ lib.optionalString (stdenv ? cc && stdenv.cc.libc != null) ''
for i in Lib/plat-*/regen; do
substituteInPlace $i --replace /usr/include/ ${stdenv.cc.libc}/include/
done
'' + lib.optionalString stdenv.hostPlatform.isDarwin ''
''
+ lib.optionalString stdenv.hostPlatform.isDarwin ''
substituteInPlace configure --replace '`/usr/bin/arch`' '"i386"'
substituteInPlace Lib/multiprocessing/__init__.py \
--replace 'os.popen(comm)' 'os.popen("${coreutils}/bin/nproc")'
'';
configureFlags = lib.optionals enableOptimizations [
"--enable-optimizations"
] ++ lib.optionals (!static) [
"--enable-shared"
] ++ [
"--with-threads"
"--with-system-ffi"
"--with-system-expat"
"--enable-unicode=ucs${toString ucsEncoding}"
] ++ lib.optionals stdenv.hostPlatform.isCygwin [
"ac_cv_func_bind_textdomain_codeset=yes"
] ++ lib.optionals stdenv.hostPlatform.isDarwin [
"--disable-toolbox-glue"
] ++ lib.optionals (stdenv.hostPlatform != stdenv.buildPlatform) [
"PYTHON_FOR_BUILD=${lib.getBin buildPackages.python27}/bin/python"
"ac_cv_buggy_getaddrinfo=no"
# Assume little-endian IEEE 754 floating point when cross compiling
"ac_cv_little_endian_double=yes"
"ac_cv_big_endian_double=no"
"ac_cv_mixed_endian_double=no"
"ac_cv_x87_double_rounding=yes"
"ac_cv_tanh_preserves_zero_sign=yes"
# Generally assume that things are present and work
"ac_cv_posix_semaphores_enabled=yes"
"ac_cv_broken_sem_getvalue=no"
"ac_cv_wchar_t_signed=yes"
"ac_cv_rshift_extends_sign=yes"
"ac_cv_broken_nice=no"
"ac_cv_broken_poll=no"
"ac_cv_working_tzset=yes"
"ac_cv_have_long_long_format=yes"
"ac_cv_have_size_t_format=yes"
"ac_cv_computed_gotos=yes"
"ac_cv_file__dev_ptmx=yes"
"ac_cv_file__dev_ptc=yes"
]
configureFlags =
lib.optionals enableOptimizations [
"--enable-optimizations"
]
++ lib.optionals (!static) [
"--enable-shared"
]
++ [
"--with-threads"
"--with-system-ffi"
"--with-system-expat"
"--enable-unicode=ucs${toString ucsEncoding}"
]
++ lib.optionals stdenv.hostPlatform.isCygwin [
"ac_cv_func_bind_textdomain_codeset=yes"
]
++ lib.optionals stdenv.hostPlatform.isDarwin [
"--disable-toolbox-glue"
]
++ lib.optionals (stdenv.hostPlatform != stdenv.buildPlatform) [
"PYTHON_FOR_BUILD=${lib.getBin buildPackages.python27}/bin/python"
"ac_cv_buggy_getaddrinfo=no"
# Assume little-endian IEEE 754 floating point when cross compiling
"ac_cv_little_endian_double=yes"
"ac_cv_big_endian_double=no"
"ac_cv_mixed_endian_double=no"
"ac_cv_x87_double_rounding=yes"
"ac_cv_tanh_preserves_zero_sign=yes"
# Generally assume that things are present and work
"ac_cv_posix_semaphores_enabled=yes"
"ac_cv_broken_sem_getvalue=no"
"ac_cv_wchar_t_signed=yes"
"ac_cv_rshift_extends_sign=yes"
"ac_cv_broken_nice=no"
"ac_cv_broken_poll=no"
"ac_cv_working_tzset=yes"
"ac_cv_have_long_long_format=yes"
"ac_cv_have_size_t_format=yes"
"ac_cv_computed_gotos=yes"
"ac_cv_file__dev_ptmx=yes"
"ac_cv_file__dev_ptc=yes"
]
# Never even try to use lchmod on linux,
# don't rely on detecting glibc-isms.
++ lib.optional stdenv.hostPlatform.isLinux "ac_cv_func_lchmod=no"
++ lib.optional static "LDFLAGS=-static";
++ lib.optional stdenv.hostPlatform.isLinux "ac_cv_func_lchmod=no"
++ lib.optional static "LDFLAGS=-static";
strictDeps = true;
buildInputs =
lib.optional (stdenv ? cc && stdenv.cc.libc != null) stdenv.cc.libc ++
[ bzip2 openssl zlib libffi expat db gdbm ncurses sqlite readline ]
++ lib.optionals x11Support [ tcl tk libX11 ];
lib.optional (stdenv ? cc && stdenv.cc.libc != null) stdenv.cc.libc
++ [
bzip2
openssl
zlib
libffi
expat
db
gdbm
ncurses
sqlite
readline
]
++ lib.optionals x11Support [
tcl
tk
libX11
];
nativeBuildInputs =
[ autoreconfHook ]
++ lib.optionals (stdenv.hostPlatform != stdenv.buildPlatform)
[ buildPackages.stdenv.cc buildPackages.python27 ];
++ lib.optionals (stdenv.hostPlatform != stdenv.buildPlatform) [
buildPackages.stdenv.cc
buildPackages.python27
];
mkPaths = paths: {
C_INCLUDE_PATH = lib.makeSearchPathOutput "dev" "include" paths;
@@ -247,29 +292,41 @@ let
};
# Python 2.7 needs this
crossCompileEnv = lib.optionalAttrs (stdenv.hostPlatform != stdenv.buildPlatform)
{ _PYTHON_HOST_PLATFORM = stdenv.hostPlatform.config; };
crossCompileEnv = lib.optionalAttrs (stdenv.hostPlatform != stdenv.buildPlatform) {
_PYTHON_HOST_PLATFORM = stdenv.hostPlatform.config;
};
# Build the basic Python interpreter without modules that have
# external dependencies.
in with passthru; stdenv.mkDerivation ({
in
with passthru;
stdenv.mkDerivation (
{
pname = "python";
inherit version;
inherit src patches buildInputs nativeBuildInputs preConfigure configureFlags;
inherit
src
patches
buildInputs
nativeBuildInputs
preConfigure
configureFlags
;
LDFLAGS = lib.optionalString (!stdenv.hostPlatform.isDarwin) "-lgcc_s";
inherit (mkPaths buildInputs) C_INCLUDE_PATH LIBRARY_PATH;
env.NIX_CFLAGS_COMPILE = lib.optionalString (stdenv.targetPlatform.system == "x86_64-darwin") "-msse2"
env.NIX_CFLAGS_COMPILE =
lib.optionalString (stdenv.targetPlatform.system == "x86_64-darwin") "-msse2"
+ lib.optionalString stdenv.hostPlatform.isMusl " -DTHREAD_STACK_SIZE=0x100000";
DETERMINISTIC_BUILD = 1;
setupHook = python-setup-hook sitePackages;
postPatch = lib.optionalString (x11Support && ((tclPackages.tix or null) != null)) ''
substituteInPlace "Lib/lib-tk/Tix.py" --replace "os.environ.get('TIX_LIBRARY')" "os.environ.get('TIX_LIBRARY') or '${tclPackages.tix}/lib'"
substituteInPlace "Lib/lib-tk/Tix.py" --replace "os.environ.get('TIX_LIBRARY')" "os.environ.get('TIX_LIBRARY') or '${tclPackages.tix}/lib'"
'';
postInstall =
@@ -295,37 +352,45 @@ in with passthru; stdenv.mkDerivation ({
# Determinism: Windows installers were not deterministic.
# We're also not interested in building Windows installers.
find "$out" -name 'wininst*.exe' | xargs -r rm -f
'' + lib.optionalString stripBytecode ''
''
+ lib.optionalString stripBytecode ''
# Determinism: deterministic bytecode
# First we delete all old bytecode.
find $out -name "*.pyc" -delete
'' + lib.optionalString rebuildBytecode ''
''
+ lib.optionalString rebuildBytecode ''
# We build 3 levels of optimized bytecode. Note the default level, without optimizations,
# is not reproducible yet. https://bugs.python.org/issue29708
# Not creating bytecode will result in a large performance loss however, so we do build it.
find $out -name "*.py" | ${pythonOnBuildForHostInterpreter} -m compileall -q -f -x "lib2to3" -i -
find $out -name "*.py" | ${pythonOnBuildForHostInterpreter} -O -m compileall -q -f -x "lib2to3" -i -
find $out -name "*.py" | ${pythonOnBuildForHostInterpreter} -OO -m compileall -q -f -x "lib2to3" -i -
'' + lib.optionalString stdenv.hostPlatform.isCygwin ''
''
+ lib.optionalString stdenv.hostPlatform.isCygwin ''
cp libpython2.7.dll.a $out/lib
'';
inherit passthru;
postFixup = ''
# Include a sitecustomize.py file. Note it causes an error when it's in postInstall with 2.7.
cp ${../../sitecustomize.py} $out/${sitePackages}/sitecustomize.py
'' + lib.optionalString strip2to3 ''
rm -R $out/bin/2to3 $out/lib/python*/lib2to3
'' + lib.optionalString stripConfig ''
rm -R $out/bin/python*-config $out/lib/python*/config*
'' + lib.optionalString stripIdlelib ''
# Strip IDLE
rm -R $out/bin/idle* $out/lib/python*/idlelib
'' + lib.optionalString stripTests ''
# Strip tests
rm -R $out/lib/python*/test $out/lib/python*/**/test{,s}
'';
postFixup =
''
# Include a sitecustomize.py file. Note it causes an error when it's in postInstall with 2.7.
cp ${../../sitecustomize.py} $out/${sitePackages}/sitecustomize.py
''
+ lib.optionalString strip2to3 ''
rm -R $out/bin/2to3 $out/lib/python*/lib2to3
''
+ lib.optionalString stripConfig ''
rm -R $out/bin/python*-config $out/lib/python*/config*
''
+ lib.optionalString stripIdlelib ''
# Strip IDLE
rm -R $out/bin/idle* $out/lib/python*/idlelib
''
+ lib.optionalString stripTests ''
# Strip tests
rm -R $out/lib/python*/test $out/lib/python*/**/test{,s}
'';
enableParallelBuilding = true;
@@ -355,4 +420,6 @@ in with passthru; stdenv.mkDerivation ({
# sunset till 2020.
];
};
} // crossCompileEnv)
}
// crossCompileEnv
)
File diff suppressed because it is too large Load Diff
@@ -1,6 +1,10 @@
# This file was generated and will be overwritten by ./generate.sh
{ stdenv, lib, fetchurl }:
{
stdenv,
lib,
fetchurl,
}:
stdenv.mkDerivation {
pname = "python27-docs-html";
@@ -1,6 +1,10 @@
# This file was generated and will be overwritten by ./generate.sh
{ stdenv, lib, fetchurl }:
{
stdenv,
lib,
fetchurl,
}:
stdenv.mkDerivation {
pname = "python27-docs-pdf-a4";
@@ -1,6 +1,10 @@
# This file was generated and will be overwritten by ./generate.sh
{ stdenv, lib, fetchurl }:
{
stdenv,
lib,
fetchurl,
}:
stdenv.mkDerivation {
pname = "python27-docs-pdf-letter";
@@ -1,6 +1,10 @@
# This file was generated and will be overwritten by ./generate.sh
{ stdenv, lib, fetchurl }:
{
stdenv,
lib,
fetchurl,
}:
stdenv.mkDerivation {
pname = "python27-docs-text";
@@ -1,6 +1,10 @@
# This file was generated and will be overwritten by ./generate.sh
{ stdenv, lib, fetchurl }:
{
stdenv,
lib,
fetchurl,
}:
stdenv.mkDerivation {
pname = "python310-docs-html";
@@ -1,6 +1,10 @@
# This file was generated and will be overwritten by ./generate.sh
{ stdenv, lib, fetchurl }:
{
stdenv,
lib,
fetchurl,
}:
stdenv.mkDerivation {
pname = "python310-docs-pdf-a4";
@@ -1,6 +1,10 @@
# This file was generated and will be overwritten by ./generate.sh
{ stdenv, lib, fetchurl }:
{
stdenv,
lib,
fetchurl,
}:
stdenv.mkDerivation {
pname = "python310-docs-pdf-letter";
@@ -1,6 +1,10 @@
# This file was generated and will be overwritten by ./generate.sh
{ stdenv, lib, fetchurl }:
{
stdenv,
lib,
fetchurl,
}:
stdenv.mkDerivation {
pname = "python310-docs-text";
@@ -1,47 +1,53 @@
{ stdenv, fetchurl, lib }:
{
stdenv,
fetchurl,
lib,
}:
let
pythonDocs = {
html = {
recurseForDerivations = true;
python27 = import ./2.7-html.nix {
inherit stdenv fetchurl lib;
pythonDocs = {
html = {
recurseForDerivations = true;
python27 = import ./2.7-html.nix {
inherit stdenv fetchurl lib;
};
python310 = import ./3.10-html.nix {
inherit stdenv fetchurl lib;
};
};
python310 = import ./3.10-html.nix {
inherit stdenv fetchurl lib;
pdf_a4 = {
recurseForDerivations = true;
python27 = import ./2.7-pdf-a4.nix {
inherit stdenv fetchurl lib;
};
python310 = import ./3.10-pdf-a4.nix {
inherit stdenv fetchurl lib;
};
};
pdf_letter = {
recurseForDerivations = true;
python27 = import ./2.7-pdf-letter.nix {
inherit stdenv fetchurl lib;
};
python310 = import ./3.10-pdf-letter.nix {
inherit stdenv fetchurl lib;
};
};
text = {
recurseForDerivations = true;
python27 = import ./2.7-text.nix {
inherit stdenv fetchurl lib;
};
python310 = import ./3.10-text.nix {
inherit stdenv fetchurl lib;
};
};
texinfo = {
recurseForDerivations = true;
python310 = import ./3.10-texinfo.nix {
inherit stdenv fetchurl lib;
};
};
};
pdf_a4 = {
recurseForDerivations = true;
python27 = import ./2.7-pdf-a4.nix {
inherit stdenv fetchurl lib;
};
python310 = import ./3.10-pdf-a4.nix {
inherit stdenv fetchurl lib;
};
};
pdf_letter = {
recurseForDerivations = true;
python27 = import ./2.7-pdf-letter.nix {
inherit stdenv fetchurl lib;
};
python310 = import ./3.10-pdf-letter.nix {
inherit stdenv fetchurl lib;
};
};
text = {
recurseForDerivations = true;
python27 = import ./2.7-text.nix {
inherit stdenv fetchurl lib;
};
python310 = import ./3.10-text.nix {
inherit stdenv fetchurl lib;
};
};
texinfo = {
recurseForDerivations = true;
python310 = import ./3.10-texinfo.nix {
inherit stdenv fetchurl lib;
};
};
}; in pythonDocs
in
pythonDocs
+206 -190
View File
@@ -1,206 +1,222 @@
{ __splicedPackages
, callPackage
, config
, darwin
, db
, lib
, libffiBoot
, makeScopeWithSplicing'
, pythonPackagesExtensions
, stdenv
{
__splicedPackages,
callPackage,
config,
darwin,
db,
lib,
libffiBoot,
makeScopeWithSplicing',
pythonPackagesExtensions,
stdenv,
}@args:
(let
(
let
# Common passthru for all Python interpreters.
passthruFun = import ./passthrufun.nix args;
# Common passthru for all Python interpreters.
passthruFun = import ./passthrufun.nix args;
sources = {
python312 = {
sources = {
python312 = {
sourceVersion = {
major = "3";
minor = "12";
patch = "9";
suffix = "";
};
hash = "sha256-ciCDXZ+Qs3wAbphCqN/0WAqspDGGdPlHMCuNKPP4ERI=";
};
};
in
{
python27 = callPackage ./cpython/2.7 {
self = __splicedPackages.python27;
sourceVersion = {
major = "2";
minor = "7";
patch = "18";
suffix = ".8"; # ActiveState's Python 2 extended support
};
hash = "sha256-HUOzu3uJbtd+3GbmGD35KOk/CDlwL4S7hi9jJGRFiqI=";
inherit passthruFun;
};
python39 = callPackage ./cpython {
self = __splicedPackages.python39;
sourceVersion = {
major = "3";
minor = "12";
patch = "9";
minor = "9";
patch = "21";
suffix = "";
};
hash = "sha256-ciCDXZ+Qs3wAbphCqN/0WAqspDGGdPlHMCuNKPP4ERI=";
};
};
in {
python27 = callPackage ./cpython/2.7 {
self = __splicedPackages.python27;
sourceVersion = {
major = "2";
minor = "7";
patch = "18";
suffix = ".8"; # ActiveState's Python 2 extended support
};
hash = "sha256-HUOzu3uJbtd+3GbmGD35KOk/CDlwL4S7hi9jJGRFiqI=";
inherit passthruFun;
};
python39 = callPackage ./cpython {
self = __splicedPackages.python39;
sourceVersion = {
major = "3";
minor = "9";
patch = "21";
suffix = "";
};
hash = "sha256-MSb1lZLJsNeYWEdV8r97CB+hyjXOem/qmAEI11KgW7E=";
inherit passthruFun;
};
python310 = callPackage ./cpython {
self = __splicedPackages.python310;
sourceVersion = {
major = "3";
minor = "10";
patch = "16";
suffix = "";
};
hash = "sha256-v7JJYJmQIgSRobkoUKBxNe0IMeQXOM9oHWPPAbKo+9E=";
inherit passthruFun;
};
python311 = callPackage ./cpython {
self = __splicedPackages.python311;
sourceVersion = {
major = "3";
minor = "11";
patch = "11";
suffix = "";
};
hash = "sha256-Kpkgx6DNI23jNkTtmAoTy7whBYv9xSj+u2CBV17XO+M=";
inherit passthruFun;
};
python312 = callPackage ./cpython ({
self = __splicedPackages.python312;
inherit passthruFun;
} // sources.python312);
python313 = callPackage ./cpython {
self = __splicedPackages.python313;
sourceVersion = {
major = "3";
minor = "13";
patch = "2";
suffix = "";
};
hash = "sha256-2YS8xXzWfKqyb33vQuUjscAVu8XcB4Ns9PC2P6FZ61Y=";
inherit passthruFun;
};
python314 = callPackage ./cpython {
self = __splicedPackages.python314;
sourceVersion = {
major = "3";
minor = "14";
patch = "0";
suffix = "a6";
};
hash = "sha256-jWGB5TMdmizWykBa4SMOiFiaBD9HaOu0Q9OInUXBw1w=";
inherit passthruFun;
};
# Minimal versions of Python (built without optional dependencies)
python3Minimal = (callPackage ./cpython ({
self = __splicedPackages.python3Minimal;
inherit passthruFun;
pythonAttr = "python3Minimal";
# strip down that python version as much as possible
openssl = null;
readline = null;
ncurses = null;
gdbm = null;
sqlite = null;
tzdata = null;
libuuid = null;
libffi = libffiBoot; # without test suite
stripConfig = true;
stripIdlelib = true;
stripTests = true;
stripTkinter = true;
rebuildBytecode = false;
stripBytecode = true;
includeSiteCustomize = false;
enableOptimizations = false;
enableLTO = false;
mimetypesSupport = false;
} // sources.python312)).overrideAttrs(old: {
# TODO(@Artturin): Add this to the main cpython expr
strictDeps = true;
pname = "python3-minimal";
});
pypy27 = callPackage ./pypy {
self = __splicedPackages.pypy27;
sourceVersion = {
major = "7";
minor = "3";
patch = "17";
hash = "sha256-MSb1lZLJsNeYWEdV8r97CB+hyjXOem/qmAEI11KgW7E=";
inherit passthruFun;
};
hash = "sha256-UOBoQPS73pFEgICkEYBoqJuPvK4l/42h4rsUAtyaA0Y=";
pythonVersion = "2.7";
db = db.override { dbmSupport = !stdenv.hostPlatform.isDarwin; };
python = __splicedPackages.pythonInterpreters.pypy27_prebuilt;
inherit passthruFun;
};
pypy310 = callPackage ./pypy {
self = __splicedPackages.pypy310;
sourceVersion = {
major = "7";
minor = "3";
patch = "17";
python310 = callPackage ./cpython {
self = __splicedPackages.python310;
sourceVersion = {
major = "3";
minor = "10";
patch = "16";
suffix = "";
};
hash = "sha256-v7JJYJmQIgSRobkoUKBxNe0IMeQXOM9oHWPPAbKo+9E=";
inherit passthruFun;
};
hash = "sha256-atdLxXjpxtOoocUVAzEwWOPFjDXfhvdIVFPEvmqyS/c=";
pythonVersion = "3.10";
db = db.override { dbmSupport = !stdenv.hostPlatform.isDarwin; };
python = __splicedPackages.pypy27;
inherit passthruFun;
};
pypy27_prebuilt = callPackage ./pypy/prebuilt_2_7.nix {
# Not included at top-level
self = __splicedPackages.pythonInterpreters.pypy27_prebuilt;
sourceVersion = {
major = "7";
minor = "3";
patch = "17";
python311 = callPackage ./cpython {
self = __splicedPackages.python311;
sourceVersion = {
major = "3";
minor = "11";
patch = "11";
suffix = "";
};
hash = "sha256-Kpkgx6DNI23jNkTtmAoTy7whBYv9xSj+u2CBV17XO+M=";
inherit passthruFun;
};
hash = {
aarch64-linux = "sha256-DUzvpmBoUk4qyyxPn1EQSqcnIc0YvPRi7HyLo5Ekqa4=";
x86_64-linux = "sha256-nzSX+HszctF+RHNp4AFqS+yZprTSpZq6d0olv+Q1NHQ=";
aarch64-darwin = "sha256-gCJIc5sqzIwb5tlH8Zsy/A44wI4xKzXAXMf7IvEHCeQ=";
x86_64-darwin = "sha256-gtRgQhRmyBraSh2Z3y3xuLNTQbOXyF///lGkwwItCDM=";
}.${stdenv.system};
pythonVersion = "2.7";
inherit passthruFun;
};
python312 = callPackage ./cpython (
{
self = __splicedPackages.python312;
inherit passthruFun;
}
// sources.python312
);
pypy39_prebuilt = throw "pypy 3.9 has been removed, use pypy 3.10 instead"; # Added 2025-01-03
pypy310_prebuilt = callPackage ./pypy/prebuilt.nix {
# Not included at top-level
self = __splicedPackages.pythonInterpreters.pypy310_prebuilt;
sourceVersion = {
major = "7";
minor = "3";
patch = "17";
python313 = callPackage ./cpython {
self = __splicedPackages.python313;
sourceVersion = {
major = "3";
minor = "13";
patch = "2";
suffix = "";
};
hash = "sha256-2YS8xXzWfKqyb33vQuUjscAVu8XcB4Ns9PC2P6FZ61Y=";
inherit passthruFun;
};
hash = {
aarch64-linux = "sha256-v79JVJirwv53G2C/ZOXDwHLgr7z8pprHKCxP9Dd/9BY=";
x86_64-linux = "sha256-NA2kGWYGsiRQmhuLMa/SAYE/CCYB3xicE46QXB1g4K8=";
aarch64-darwin = "sha256-KPKf/JxcyQbo6QgT/BRPA34js4TwUuGE4kIzL3tgqwY=";
x86_64-darwin = "sha256-I/8mS3PlvFt8OhufrHdosj35bH1mDLZBLxxSNSGjNL8=";
}.${stdenv.system};
pythonVersion = "3.10";
inherit passthruFun;
};
})
python314 = callPackage ./cpython {
self = __splicedPackages.python314;
sourceVersion = {
major = "3";
minor = "14";
patch = "0";
suffix = "a6";
};
hash = "sha256-jWGB5TMdmizWykBa4SMOiFiaBD9HaOu0Q9OInUXBw1w=";
inherit passthruFun;
};
# Minimal versions of Python (built without optional dependencies)
python3Minimal =
(callPackage ./cpython (
{
self = __splicedPackages.python3Minimal;
inherit passthruFun;
pythonAttr = "python3Minimal";
# strip down that python version as much as possible
openssl = null;
readline = null;
ncurses = null;
gdbm = null;
sqlite = null;
tzdata = null;
libuuid = null;
libffi = libffiBoot; # without test suite
stripConfig = true;
stripIdlelib = true;
stripTests = true;
stripTkinter = true;
rebuildBytecode = false;
stripBytecode = true;
includeSiteCustomize = false;
enableOptimizations = false;
enableLTO = false;
mimetypesSupport = false;
}
// sources.python312
)).overrideAttrs
(old: {
# TODO(@Artturin): Add this to the main cpython expr
strictDeps = true;
pname = "python3-minimal";
});
pypy27 = callPackage ./pypy {
self = __splicedPackages.pypy27;
sourceVersion = {
major = "7";
minor = "3";
patch = "17";
};
hash = "sha256-UOBoQPS73pFEgICkEYBoqJuPvK4l/42h4rsUAtyaA0Y=";
pythonVersion = "2.7";
db = db.override { dbmSupport = !stdenv.hostPlatform.isDarwin; };
python = __splicedPackages.pythonInterpreters.pypy27_prebuilt;
inherit passthruFun;
};
pypy310 = callPackage ./pypy {
self = __splicedPackages.pypy310;
sourceVersion = {
major = "7";
minor = "3";
patch = "17";
};
hash = "sha256-atdLxXjpxtOoocUVAzEwWOPFjDXfhvdIVFPEvmqyS/c=";
pythonVersion = "3.10";
db = db.override { dbmSupport = !stdenv.hostPlatform.isDarwin; };
python = __splicedPackages.pypy27;
inherit passthruFun;
};
pypy27_prebuilt = callPackage ./pypy/prebuilt_2_7.nix {
# Not included at top-level
self = __splicedPackages.pythonInterpreters.pypy27_prebuilt;
sourceVersion = {
major = "7";
minor = "3";
patch = "17";
};
hash =
{
aarch64-linux = "sha256-DUzvpmBoUk4qyyxPn1EQSqcnIc0YvPRi7HyLo5Ekqa4=";
x86_64-linux = "sha256-nzSX+HszctF+RHNp4AFqS+yZprTSpZq6d0olv+Q1NHQ=";
aarch64-darwin = "sha256-gCJIc5sqzIwb5tlH8Zsy/A44wI4xKzXAXMf7IvEHCeQ=";
x86_64-darwin = "sha256-gtRgQhRmyBraSh2Z3y3xuLNTQbOXyF///lGkwwItCDM=";
}
.${stdenv.system};
pythonVersion = "2.7";
inherit passthruFun;
};
pypy39_prebuilt = throw "pypy 3.9 has been removed, use pypy 3.10 instead"; # Added 2025-01-03
pypy310_prebuilt = callPackage ./pypy/prebuilt.nix {
# Not included at top-level
self = __splicedPackages.pythonInterpreters.pypy310_prebuilt;
sourceVersion = {
major = "7";
minor = "3";
patch = "17";
};
hash =
{
aarch64-linux = "sha256-v79JVJirwv53G2C/ZOXDwHLgr7z8pprHKCxP9Dd/9BY=";
x86_64-linux = "sha256-NA2kGWYGsiRQmhuLMa/SAYE/CCYB3xicE46QXB1g4K8=";
aarch64-darwin = "sha256-KPKf/JxcyQbo6QgT/BRPA34js4TwUuGE4kIzL3tgqwY=";
x86_64-darwin = "sha256-I/8mS3PlvFt8OhufrHdosj35bH1mDLZBLxxSNSGjNL8=";
}
.${stdenv.system};
pythonVersion = "3.10";
inherit passthruFun;
};
}
)
@@ -1,22 +1,41 @@
{ lib, stdenv, replaceVars, fetchurl
, zlibSupport ? true, zlib
, bzip2, pkg-config, libffi
, sqlite, openssl, ncurses, python, expat, tcl, tk, tclPackages, libX11
, gdbm, db, xz, python-setup-hook
, optimizationLevel ? "jit", boehmgc
# For the Python package set
, hash
, self
, packageOverrides ? (self: super: {})
, pkgsBuildBuild
, pkgsBuildHost
, pkgsBuildTarget
, pkgsHostHost
, pkgsTargetTarget
, sourceVersion
, pythonVersion
, passthruFun
, pythonAttr ? "pypy${lib.substring 0 1 pythonVersion}${lib.substring 2 3 pythonVersion}"
{
lib,
stdenv,
replaceVars,
fetchurl,
zlibSupport ? true,
zlib,
bzip2,
pkg-config,
libffi,
sqlite,
openssl,
ncurses,
python,
expat,
tcl,
tk,
tclPackages,
libX11,
gdbm,
db,
xz,
python-setup-hook,
optimizationLevel ? "jit",
boehmgc,
# For the Python package set
hash,
self,
packageOverrides ? (self: super: { }),
pkgsBuildBuild,
pkgsBuildHost,
pkgsBuildTarget,
pkgsHostHost,
pkgsTargetTarget,
sourceVersion,
pythonVersion,
passthruFun,
pythonAttr ? "pypy${lib.substring 0 1 pythonVersion}${lib.substring 2 3 pythonVersion}",
}:
assert zlibSupport -> zlib != null;
@@ -26,10 +45,17 @@ let
isPy38OrNewer = lib.versionAtLeast pythonVersion "3.8";
isPy39OrNewer = lib.versionAtLeast pythonVersion "3.9";
passthru = passthruFun rec {
inherit self sourceVersion pythonVersion packageOverrides;
inherit
self
sourceVersion
pythonVersion
packageOverrides
;
implementation = "pypy";
libPrefix = "pypy${pythonVersion}";
executable = "pypy${if isPy39OrNewer then lib.versions.majorMinor pythonVersion else lib.optionalString isPy3k "3"}";
executable = "pypy${
if isPy39OrNewer then lib.versions.majorMinor pythonVersion else lib.optionalString isPy3k "3"
}";
sitePackages = "${lib.optionalString isPy38OrNewer "lib/${libPrefix}/"}site-packages";
hasDistutilsCxxPatch = false;
inherit pythonAttr;
@@ -38,13 +64,15 @@ let
pythonOnBuildForHost = pkgsBuildHost.${pythonAttr};
pythonOnBuildForTarget = pkgsBuildTarget.${pythonAttr};
pythonOnHostForHost = pkgsHostHost.${pythonAttr};
pythonOnTargetForTarget = pkgsTargetTarget.${pythonAttr} or {};
pythonOnTargetForTarget = pkgsTargetTarget.${pythonAttr} or { };
};
pname = passthru.executable;
version = with sourceVersion; "${major}.${minor}.${patch}";
pythonForPypy = python.withPackages (ppkgs: [ ]);
in with passthru; stdenv.mkDerivation rec {
in
with passthru;
stdenv.mkDerivation rec {
inherit pname version;
src = fetchurl {
@@ -53,17 +81,41 @@ in with passthru; stdenv.mkDerivation rec {
};
nativeBuildInputs = [ pkg-config ];
buildInputs = [
bzip2 openssl pythonForPypy libffi ncurses expat sqlite tk tcl libX11 gdbm db
] ++ lib.optionals isPy3k [
xz
] ++ lib.optionals (stdenv ? cc && stdenv.cc.libc != null) [
stdenv.cc.libc
] ++ lib.optionals zlibSupport [
zlib
] ++ lib.optionals (lib.any (l: l == optimizationLevel) [ "0" "1" "2" "3"]) [
boehmgc
];
buildInputs =
[
bzip2
openssl
pythonForPypy
libffi
ncurses
expat
sqlite
tk
tcl
libX11
gdbm
db
]
++ lib.optionals isPy3k [
xz
]
++ lib.optionals (stdenv ? cc && stdenv.cc.libc != null) [
stdenv.cc.libc
]
++ lib.optionals zlibSupport [
zlib
]
++
lib.optionals
(lib.any (l: l == optimizationLevel) [
"0"
"1"
"2"
"3"
])
[
boehmgc
];
# Remove bootstrap python from closure
dontPatchShebangs = true;
@@ -71,7 +123,9 @@ in with passthru; stdenv.mkDerivation rec {
C_INCLUDE_PATH = lib.makeSearchPathOutput "dev" "include" buildInputs;
LIBRARY_PATH = lib.makeLibraryPath buildInputs;
LD_LIBRARY_PATH = lib.makeLibraryPath (builtins.filter (x : x.outPath != stdenv.cc.libc.outPath or "") buildInputs);
LD_LIBRARY_PATH = lib.makeLibraryPath (
builtins.filter (x: x.outPath != stdenv.cc.libc.outPath or "") buildInputs
);
patches = [
./dont_fetch_vendored_deps.patch
@@ -123,83 +177,102 @@ in with passthru; stdenv.mkDerivation rec {
ln -s $out/${executable}-c/lib-python/${if isPy3k then "3" else pythonVersion} $out/lib/${libPrefix}
# Include a sitecustomize.py file
cp ${../sitecustomize.py} $out/${if isPy38OrNewer then sitePackages else "lib/${libPrefix}/${sitePackages}"}/sitecustomize.py
cp ${../sitecustomize.py} $out/${
if isPy38OrNewer then sitePackages else "lib/${libPrefix}/${sitePackages}"
}/sitecustomize.py
runHook postInstall
'';
preFixup = lib.optionalString (stdenv.hostPlatform.isDarwin) ''
install_name_tool -change @rpath/lib${executable}-c.dylib $out/lib/lib${executable}-c.dylib $out/bin/${executable}
'' + lib.optionalString (stdenv.hostPlatform.isDarwin && stdenv.hostPlatform.isAarch64) ''
mkdir -p $out/${executable}-c/pypy/bin
mv $out/bin/${executable} $out/${executable}-c/pypy/bin/${executable}
ln -s $out/${executable}-c/pypy/bin/${executable} $out/bin/${executable}
'';
preFixup =
lib.optionalString (stdenv.hostPlatform.isDarwin) ''
install_name_tool -change @rpath/lib${executable}-c.dylib $out/lib/lib${executable}-c.dylib $out/bin/${executable}
''
+ lib.optionalString (stdenv.hostPlatform.isDarwin && stdenv.hostPlatform.isAarch64) ''
mkdir -p $out/${executable}-c/pypy/bin
mv $out/bin/${executable} $out/${executable}-c/pypy/bin/${executable}
ln -s $out/${executable}-c/pypy/bin/${executable} $out/bin/${executable}
'';
setupHook = python-setup-hook sitePackages;
# TODO: A bunch of tests are failing as of 7.1.1, please feel free to
# fix and re-enable if you have the patience and tenacity.
doCheck = false;
checkPhase = let
disabledTests = [
# disable shutils because it assumes gid 0 exists
"test_shutil"
# disable socket because it has two actual network tests that fail
"test_socket"
] ++ lib.optionals (!isPy3k) [
# disable test_urllib2net, test_urllib2_localnet, and test_urllibnet because they require networking (example.com)
"test_urllib2net"
"test_urllibnet"
"test_urllib2_localnet"
] ++ lib.optionals isPy3k [
# disable asyncio due to https://github.com/NixOS/nix/issues/1238
"test_asyncio"
# disable os due to https://github.com/NixOS/nixpkgs/issues/10496
"test_os"
# disable pathlib due to https://bitbucket.org/pypy/pypy/pull-requests/594
"test_pathlib"
# disable tarfile because it assumes gid 0 exists
"test_tarfile"
# disable __all__ because of spurious imp/importlib warning and
# warning-to-error test policy
"test___all__"
];
in ''
export TERMINFO="${ncurses.out}/share/terminfo/";
export TERM="xterm";
export HOME="$TMPDIR";
checkPhase =
let
disabledTests =
[
# disable shutils because it assumes gid 0 exists
"test_shutil"
# disable socket because it has two actual network tests that fail
"test_socket"
]
++ lib.optionals (!isPy3k) [
# disable test_urllib2net, test_urllib2_localnet, and test_urllibnet because they require networking (example.com)
"test_urllib2net"
"test_urllibnet"
"test_urllib2_localnet"
]
++ lib.optionals isPy3k [
# disable asyncio due to https://github.com/NixOS/nix/issues/1238
"test_asyncio"
# disable os due to https://github.com/NixOS/nixpkgs/issues/10496
"test_os"
# disable pathlib due to https://bitbucket.org/pypy/pypy/pull-requests/594
"test_pathlib"
# disable tarfile because it assumes gid 0 exists
"test_tarfile"
# disable __all__ because of spurious imp/importlib warning and
# warning-to-error test policy
"test___all__"
];
in
''
export TERMINFO="${ncurses.out}/share/terminfo/";
export TERM="xterm";
export HOME="$TMPDIR";
${pythonForPypy.interpreter} ./pypy/test_all.py --pypy=./${executable}-c -k 'not (${lib.concatStringsSep " or " disabledTests})' lib-python
'';
${pythonForPypy.interpreter} ./pypy/test_all.py --pypy=./${executable}-c -k 'not (${lib.concatStringsSep " or " disabledTests})' lib-python
'';
# verify cffi modules
doInstallCheck = true;
installCheckPhase = let
modules = [
"curses"
"sqlite3"
] ++ lib.optionals (!isPy3k) [
"Tkinter"
] ++ lib.optionals isPy3k [
"tkinter"
"lzma"
];
imports = lib.concatMapStringsSep "; " (x: "import ${x}") modules;
in ''
echo "Testing whether we can import modules"
$out/bin/${executable} -c '${imports}'
'';
installCheckPhase =
let
modules =
[
"curses"
"sqlite3"
]
++ lib.optionals (!isPy3k) [
"Tkinter"
]
++ lib.optionals isPy3k [
"tkinter"
"lzma"
];
imports = lib.concatMapStringsSep "; " (x: "import ${x}") modules;
in
''
echo "Testing whether we can import modules"
$out/bin/${executable} -c '${imports}'
'';
inherit passthru;
enableParallelBuilding = true; # almost no parallelization without STM
enableParallelBuilding = true; # almost no parallelization without STM
meta = with lib; {
homepage = "https://www.pypy.org/";
description = "Fast, compliant alternative implementation of the Python language (${pythonVersion})";
mainProgram = "pypy";
license = licenses.mit;
platforms = [ "aarch64-linux" "x86_64-linux" "aarch64-darwin" "x86_64-darwin" ];
platforms = [
"aarch64-linux"
"x86_64-linux"
"aarch64-darwin"
"x86_64-darwin"
];
broken = optimizationLevel == "0"; # generates invalid code
maintainers = with maintainers; [ andersk ];
};
@@ -1,26 +1,27 @@
{ lib
, stdenv
, fetchurl
, autoPatchelfHook
, python-setup-hook
, self
# Dependencies
, bzip2
, expat
, gdbm
, ncurses6
, sqlite
, tcl-8_5
, tk-8_5
, tcl-8_6
, tk-8_6
, zlib
# For the Python package set
, packageOverrides ? (self: super: {})
, sourceVersion
, pythonVersion
, hash
, passthruFun
{
lib,
stdenv,
fetchurl,
autoPatchelfHook,
python-setup-hook,
self,
# Dependencies
bzip2,
expat,
gdbm,
ncurses6,
sqlite,
tcl-8_5,
tk-8_5,
tcl-8_6,
tk-8_6,
zlib,
# For the Python package set
packageOverrides ? (self: super: { }),
sourceVersion,
pythonVersion,
hash,
passthruFun,
}:
# This version of PyPy is primarily added to speed-up translation of
@@ -29,7 +30,12 @@
let
isPy3k = majorVersion == "3";
passthru = passthruFun rec {
inherit self sourceVersion pythonVersion packageOverrides;
inherit
self
sourceVersion
pythonVersion
packageOverrides
;
implementation = "pypy";
libPrefix = "pypy${pythonVersion}";
executable = "pypy${lib.optionalString isPy3k "3"}";
@@ -55,7 +61,9 @@ let
x86_64-darwin = "https://downloads.python.org/pypy/pypy${pythonVersion}-v${version}-macos_x86_64.tar.bz2";
};
in with passthru; stdenv.mkDerivation {
in
with passthru;
stdenv.mkDerivation {
inherit pname version;
src = fetchurl {
@@ -63,21 +71,24 @@ in with passthru; stdenv.mkDerivation {
inherit hash;
};
buildInputs = [
bzip2
expat
gdbm
ncurses6
sqlite
zlib
stdenv.cc.cc.libgcc or null
] ++ lib.optionals stdenv.hostPlatform.isLinux [
tcl-8_5
tk-8_5
] ++ lib.optionals stdenv.hostPlatform.isDarwin [
tcl-8_6
tk-8_6
];
buildInputs =
[
bzip2
expat
gdbm
ncurses6
sqlite
zlib
stdenv.cc.cc.libgcc or null
]
++ lib.optionals stdenv.hostPlatform.isLinux [
tcl-8_5
tk-8_5
]
++ lib.optionals stdenv.hostPlatform.isDarwin [
tcl-8_6
tk-8_6
];
nativeBuildInputs = lib.optionals stdenv.hostPlatform.isLinux [ autoPatchelfHook ];
@@ -101,52 +112,59 @@ in with passthru; stdenv.mkDerivation {
runHook postInstall
'';
preFixup = lib.optionalString stdenv.hostPlatform.isLinux ''
find $out/{lib,lib_pypy*} -name "*.so" \
-exec patchelf \
--replace-needed libtinfow.so.6 libncursesw.so.6 \
--replace-needed libgdbm.so.4 libgdbm_compat.so.4 {} \;
'' + lib.optionalString stdenv.hostPlatform.isDarwin ''
install_name_tool \
-change \
@rpath/lib${libPrefix}-c.dylib \
$out/lib/lib${libPrefix}-c.dylib \
$out/bin/${executable}
install_name_tool \
-change \
@rpath/lib${libPrefix}-c.dylib \
$out/lib/lib${libPrefix}-c.dylib \
$out/bin/${libPrefix}
install_name_tool \
-change \
/opt/homebrew${lib.optionalString stdenv.hostPlatform.isx86_64 "_x86_64"}/opt/tcl-tk/lib/libtcl8.6.dylib \
${tcl-8_6}/lib/libtcl8.6.dylib \
$out/lib/${libPrefix}/_tkinter/*.so
install_name_tool \
-change \
/opt/homebrew${lib.optionalString stdenv.hostPlatform.isx86_64 "_x86_64"}/opt/tcl-tk/lib/libtk8.6.dylib \
${tk-8_6}/lib/libtk8.6.dylib \
$out/lib/${libPrefix}/_tkinter/*.so
'';
preFixup =
lib.optionalString stdenv.hostPlatform.isLinux ''
find $out/{lib,lib_pypy*} -name "*.so" \
-exec patchelf \
--replace-needed libtinfow.so.6 libncursesw.so.6 \
--replace-needed libgdbm.so.4 libgdbm_compat.so.4 {} \;
''
+ lib.optionalString stdenv.hostPlatform.isDarwin ''
install_name_tool \
-change \
@rpath/lib${libPrefix}-c.dylib \
$out/lib/lib${libPrefix}-c.dylib \
$out/bin/${executable}
install_name_tool \
-change \
@rpath/lib${libPrefix}-c.dylib \
$out/lib/lib${libPrefix}-c.dylib \
$out/bin/${libPrefix}
install_name_tool \
-change \
/opt/homebrew${lib.optionalString stdenv.hostPlatform.isx86_64 "_x86_64"}/opt/tcl-tk/lib/libtcl8.6.dylib \
${tcl-8_6}/lib/libtcl8.6.dylib \
$out/lib/${libPrefix}/_tkinter/*.so
install_name_tool \
-change \
/opt/homebrew${lib.optionalString stdenv.hostPlatform.isx86_64 "_x86_64"}/opt/tcl-tk/lib/libtk8.6.dylib \
${tk-8_6}/lib/libtk8.6.dylib \
$out/lib/${libPrefix}/_tkinter/*.so
'';
doInstallCheck = true;
# Check whether importing of (extension) modules functions
installCheckPhase = let
modules = [
"ssl"
"sys"
"curses"
] ++ lib.optionals (!isPy3k) [
"Tkinter"
] ++ lib.optionals isPy3k [
"tkinter"
];
imports = lib.concatMapStringsSep "; " (x: "import ${x}") modules;
in ''
echo "Testing whether we can import modules"
$out/bin/${executable} -c '${imports}'
'';
installCheckPhase =
let
modules =
[
"ssl"
"sys"
"curses"
]
++ lib.optionals (!isPy3k) [
"Tkinter"
]
++ lib.optionals isPy3k [
"tkinter"
];
imports = lib.concatMapStringsSep "; " (x: "import ${x}") modules;
in
''
echo "Testing whether we can import modules"
$out/bin/${executable} -c '${imports}'
'';
setupHook = python-setup-hook sitePackages;
@@ -1,26 +1,27 @@
{ lib
, stdenv
, fetchurl
, autoPatchelfHook
, python-setup-hook
, self
# Dependencies
, bzip2
, expat
, gdbm
, ncurses6
, sqlite
, tcl-8_5
, tk-8_5
, tcl-8_6
, tk-8_6
, zlib
# For the Python package set
, packageOverrides ? (self: super: {})
, sourceVersion
, pythonVersion
, hash
, passthruFun
{
lib,
stdenv,
fetchurl,
autoPatchelfHook,
python-setup-hook,
self,
# Dependencies
bzip2,
expat,
gdbm,
ncurses6,
sqlite,
tcl-8_5,
tk-8_5,
tcl-8_6,
tk-8_6,
zlib,
# For the Python package set
packageOverrides ? (self: super: { }),
sourceVersion,
pythonVersion,
hash,
passthruFun,
}:
# This version of PyPy is primarily added to speed-up translation of
@@ -29,7 +30,12 @@
let
isPy3k = majorVersion == "3";
passthru = passthruFun {
inherit self sourceVersion pythonVersion packageOverrides;
inherit
self
sourceVersion
pythonVersion
packageOverrides
;
implementation = "pypy";
libPrefix = "pypy${pythonVersion}";
executable = "pypy${lib.optionalString isPy3k "3"}";
@@ -55,7 +61,9 @@ let
x86_64-darwin = "https://downloads.python.org/pypy/pypy${pythonVersion}-v${version}-macos_x86_64.tar.bz2";
};
in with passthru; stdenv.mkDerivation {
in
with passthru;
stdenv.mkDerivation {
inherit pname version;
src = fetchurl {
@@ -63,21 +71,24 @@ in with passthru; stdenv.mkDerivation {
inherit hash;
};
buildInputs = [
bzip2
expat
gdbm
ncurses6
sqlite
zlib
stdenv.cc.cc.libgcc or null
] ++ lib.optionals stdenv.hostPlatform.isLinux [
tcl-8_5
tk-8_5
] ++ lib.optionals stdenv.hostPlatform.isDarwin [
tcl-8_6
tk-8_6
];
buildInputs =
[
bzip2
expat
gdbm
ncurses6
sqlite
zlib
stdenv.cc.cc.libgcc or null
]
++ lib.optionals stdenv.hostPlatform.isLinux [
tcl-8_5
tk-8_5
]
++ lib.optionals stdenv.hostPlatform.isDarwin [
tcl-8_6
tk-8_6
];
nativeBuildInputs = lib.optionals stdenv.hostPlatform.isLinux [ autoPatchelfHook ];
@@ -102,47 +113,54 @@ in with passthru; stdenv.mkDerivation {
runHook postInstall
'';
preFixup = lib.optionalString (stdenv.hostPlatform.isLinux) ''
find $out/{lib,lib_pypy*} -name "*.so" \
-exec patchelf \
--replace-needed libtinfow.so.6 libncursesw.so.6 \
--replace-needed libgdbm.so.4 libgdbm_compat.so.4 {} \;
'' + lib.optionalString (stdenv.hostPlatform.isDarwin) ''
install_name_tool \
-change \
@rpath/lib${executable}-c.dylib \
$out/lib/lib${executable}-c.dylib \
$out/bin/${executable}
install_name_tool \
-change \
/opt/homebrew${lib.optionalString stdenv.hostPlatform.isx86_64 "_x86_64"}/opt/tcl-tk/lib/libtcl8.6.dylib \
${tcl-8_6}/lib/libtcl8.6.dylib \
$out/lib_pypy/_tkinter/*.so
install_name_tool \
-change \
/opt/homebrew${lib.optionalString stdenv.hostPlatform.isx86_64 "_x86_64"}/opt/tcl-tk/lib/libtk8.6.dylib \
${tk-8_6}/lib/libtk8.6.dylib \
$out/lib_pypy/_tkinter/*.so
'';
preFixup =
lib.optionalString (stdenv.hostPlatform.isLinux) ''
find $out/{lib,lib_pypy*} -name "*.so" \
-exec patchelf \
--replace-needed libtinfow.so.6 libncursesw.so.6 \
--replace-needed libgdbm.so.4 libgdbm_compat.so.4 {} \;
''
+ lib.optionalString (stdenv.hostPlatform.isDarwin) ''
install_name_tool \
-change \
@rpath/lib${executable}-c.dylib \
$out/lib/lib${executable}-c.dylib \
$out/bin/${executable}
install_name_tool \
-change \
/opt/homebrew${lib.optionalString stdenv.hostPlatform.isx86_64 "_x86_64"}/opt/tcl-tk/lib/libtcl8.6.dylib \
${tcl-8_6}/lib/libtcl8.6.dylib \
$out/lib_pypy/_tkinter/*.so
install_name_tool \
-change \
/opt/homebrew${lib.optionalString stdenv.hostPlatform.isx86_64 "_x86_64"}/opt/tcl-tk/lib/libtk8.6.dylib \
${tk-8_6}/lib/libtk8.6.dylib \
$out/lib_pypy/_tkinter/*.so
'';
doInstallCheck = true;
# Check whether importing of (extension) modules functions
installCheckPhase = let
modules = [
"ssl"
"sys"
"curses"
] ++ lib.optionals (!isPy3k) [
"Tkinter"
] ++ lib.optionals isPy3k [
"tkinter"
];
imports = lib.concatMapStringsSep "; " (x: "import ${x}") modules;
in ''
echo "Testing whether we can import modules"
$out/bin/${executable} -c '${imports}'
'';
installCheckPhase =
let
modules =
[
"ssl"
"sys"
"curses"
]
++ lib.optionals (!isPy3k) [
"Tkinter"
]
++ lib.optionals isPy3k [
"tkinter"
];
imports = lib.concatMapStringsSep "; " (x: "import ${x}") modules;
in
''
echo "Testing whether we can import modules"
$out/bin/${executable} -c '${imports}'
'';
setupHook = python-setup-hook sitePackages;
+252 -202
View File
@@ -5,230 +5,280 @@
#
# $ nix-build -A python3.tests
#
{ stdenv
, python
, runCommand
, lib
, callPackage
, pkgs
{
stdenv,
python,
runCommand,
lib,
callPackage,
pkgs,
}:
let
# Test whether the interpreter behaves in the different types of environments
# we aim to support.
environmentTests = let
envs = let
inherit python;
pythonEnv = python.withPackages(ps: with ps; [ ]);
pythonVirtualEnv = if python.isPy3k
then
python.withPackages(ps: with ps; [ virtualenv ])
else
python.buildEnv.override {
extraLibs = with python.pkgs; [ virtualenv ];
# Collisions because of namespaces __init__.py
ignoreCollisions = true;
environmentTests =
let
envs =
let
inherit python;
pythonEnv = python.withPackages (ps: with ps; [ ]);
pythonVirtualEnv =
if python.isPy3k then
python.withPackages (ps: with ps; [ virtualenv ])
else
python.buildEnv.override {
extraLibs = with python.pkgs; [ virtualenv ];
# Collisions because of namespaces __init__.py
ignoreCollisions = true;
};
in
{
# Plain Python interpreter
plain = rec {
env = python;
interpreter = env.interpreter;
is_venv = "False";
is_nixenv = "False";
is_virtualenv = "False";
};
}
// lib.optionalAttrs (!python.isPyPy && !stdenv.hostPlatform.isDarwin) {
# Use virtualenv from a Nix env.
# Fails on darwin with
# virtualenv: error: argument dest: the destination . is not write-able at /nix/store
nixenv-virtualenv = rec {
env = runCommand "${python.name}-virtualenv" { } ''
${pythonVirtualEnv.interpreter} -m virtualenv venv
mv venv $out
'';
interpreter = "${env}/bin/${python.executable}";
is_venv = "False";
is_nixenv = "True";
is_virtualenv = "True";
};
}
// lib.optionalAttrs (python.implementation != "graal") {
# Python Nix environment (python.buildEnv)
nixenv = rec {
env = pythonEnv;
interpreter = env.interpreter;
is_venv = "False";
is_nixenv = "True";
is_virtualenv = "False";
};
}
// lib.optionalAttrs (python.isPy3k && (!python.isPyPy)) {
# Venv built using plain Python
# Python 2 does not support venv
# TODO: PyPy executable name is incorrect, it should be pypy-c or pypy-3c instead of pypy and pypy3.
plain-venv = rec {
env = runCommand "${python.name}-venv" { } ''
${python.interpreter} -m venv $out
'';
interpreter = "${env}/bin/${python.executable}";
is_venv = "True";
is_nixenv = "False";
is_virtualenv = "False";
};
in {
# Plain Python interpreter
plain = rec {
env = python;
interpreter = env.interpreter;
is_venv = "False";
is_nixenv = "False";
is_virtualenv = "False";
};
} // lib.optionalAttrs (!python.isPyPy && !stdenv.hostPlatform.isDarwin) {
# Use virtualenv from a Nix env.
# Fails on darwin with
# virtualenv: error: argument dest: the destination . is not write-able at /nix/store
nixenv-virtualenv = rec {
env = runCommand "${python.name}-virtualenv" {} ''
${pythonVirtualEnv.interpreter} -m virtualenv venv
mv venv $out
'';
interpreter = "${env}/bin/${python.executable}";
is_venv = "False";
is_nixenv = "True";
is_virtualenv = "True";
};
} // lib.optionalAttrs (python.implementation != "graal") {
# Python Nix environment (python.buildEnv)
nixenv = rec {
env = pythonEnv;
interpreter = env.interpreter;
is_venv = "False";
is_nixenv = "True";
is_virtualenv = "False";
};
} // lib.optionalAttrs (python.isPy3k && (!python.isPyPy)) {
# Venv built using plain Python
# Python 2 does not support venv
# TODO: PyPy executable name is incorrect, it should be pypy-c or pypy-3c instead of pypy and pypy3.
plain-venv = rec {
env = runCommand "${python.name}-venv" {} ''
${python.interpreter} -m venv $out
'';
interpreter = "${env}/bin/${python.executable}";
is_venv = "True";
is_nixenv = "False";
is_virtualenv = "False";
};
} // {
# Venv built using Python Nix environment (python.buildEnv)
# TODO: Cannot create venv from a nix env
# Error: Command '['/nix/store/ddc8nqx73pda86ibvhzdmvdsqmwnbjf7-python3-3.7.6-venv/bin/python3.7', '-Im', 'ensurepip', '--upgrade', '--default-pip']' returned non-zero exit status 1.
nixenv-venv = rec {
env = runCommand "${python.name}-venv" {} ''
${pythonEnv.interpreter} -m venv $out
'';
interpreter = "${env}/bin/${pythonEnv.executable}";
is_venv = "True";
is_nixenv = "True";
is_virtualenv = "False";
};
};
}
// {
# Venv built using Python Nix environment (python.buildEnv)
# TODO: Cannot create venv from a nix env
# Error: Command '['/nix/store/ddc8nqx73pda86ibvhzdmvdsqmwnbjf7-python3-3.7.6-venv/bin/python3.7', '-Im', 'ensurepip', '--upgrade', '--default-pip']' returned non-zero exit status 1.
nixenv-venv = rec {
env = runCommand "${python.name}-venv" { } ''
${pythonEnv.interpreter} -m venv $out
'';
interpreter = "${env}/bin/${pythonEnv.executable}";
is_venv = "True";
is_nixenv = "True";
is_virtualenv = "False";
};
};
testfun = name: attrs: runCommand "${python.name}-tests-${name}" ({
inherit (python) pythonVersion;
} // attrs) ''
cp -r ${./tests/test_environments} tests
chmod -R +w tests
substituteAllInPlace tests/test_python.py
${attrs.interpreter} -m unittest discover --verbose tests #/test_python.py
mkdir $out
touch $out/success
'';
testfun =
name: attrs:
runCommand "${python.name}-tests-${name}"
(
{
inherit (python) pythonVersion;
}
// attrs
)
''
cp -r ${./tests/test_environments} tests
chmod -R +w tests
substituteAllInPlace tests/test_python.py
${attrs.interpreter} -m unittest discover --verbose tests #/test_python.py
mkdir $out
touch $out/success
'';
in lib.mapAttrs testfun envs;
in
lib.mapAttrs testfun envs;
# Integration tests involving the package set.
# All PyPy package builds are broken at the moment
integrationTests = lib.optionalAttrs (!python.isPyPy) ({
# Make sure tkinter is importable. See https://github.com/NixOS/nixpkgs/issues/238990
tkinter = callPackage ./tests/test_tkinter {
interpreter = python;
};
} // lib.optionalAttrs (python.isPy3k && python.pythonOlder "3.13" && !stdenv.hostPlatform.isDarwin) { # darwin has no split-debug
# fails on python3.13
cpython-gdb = callPackage ./tests/test_cpython_gdb {
interpreter = python;
};
} // lib.optionalAttrs (python.isPy3k && python.pythonOlder "3.13") {
# Before the addition of NIX_PYTHONPREFIX mypy was broken with typed packages
# mypy does not yet support python3.13
# https://github.com/python/mypy/issues/17264
nix-pythonprefix-mypy = callPackage ./tests/test_nix_pythonprefix {
interpreter = python;
};
});
integrationTests = lib.optionalAttrs (!python.isPyPy) (
{
# Make sure tkinter is importable. See https://github.com/NixOS/nixpkgs/issues/238990
tkinter = callPackage ./tests/test_tkinter {
interpreter = python;
};
}
// lib.optionalAttrs (python.isPy3k && python.pythonOlder "3.13" && !stdenv.hostPlatform.isDarwin) {
# darwin has no split-debug
# fails on python3.13
cpython-gdb = callPackage ./tests/test_cpython_gdb {
interpreter = python;
};
}
// lib.optionalAttrs (python.isPy3k && python.pythonOlder "3.13") {
# Before the addition of NIX_PYTHONPREFIX mypy was broken with typed packages
# mypy does not yet support python3.13
# https://github.com/python/mypy/issues/17264
nix-pythonprefix-mypy = callPackage ./tests/test_nix_pythonprefix {
interpreter = python;
};
}
);
# Test editable package support
editableTests = let
testPython = python.override {
self = testPython;
packageOverrides = pyfinal: pyprev: {
# An editable package with a script that loads our mutable location
my-editable = pyfinal.mkPythonEditablePackage {
pname = "my-editable";
version = "0.1.0";
root = "$NIX_BUILD_TOP/src"; # Use environment variable expansion at runtime
# Inject a script
scripts = {
my-script = "my_editable.main:main";
editableTests =
let
testPython = python.override {
self = testPython;
packageOverrides = pyfinal: pyprev: {
# An editable package with a script that loads our mutable location
my-editable = pyfinal.mkPythonEditablePackage {
pname = "my-editable";
version = "0.1.0";
root = "$NIX_BUILD_TOP/src"; # Use environment variable expansion at runtime
# Inject a script
scripts = {
my-script = "my_editable.main:main";
};
};
};
};
in
{
editable-script =
runCommand "editable-test"
{
nativeBuildInputs = [ (testPython.withPackages (ps: [ ps.my-editable ])) ];
}
''
mkdir -p src/my_editable
cat > src/my_editable/main.py << EOF
def main():
print("hello mutable")
EOF
test "$(my-script)" == "hello mutable"
test "$(python -c 'import sys; print(sys.path[1])')" == "$NIX_BUILD_TOP/src"
touch $out
'';
};
in {
editable-script = runCommand "editable-test" {
nativeBuildInputs = [ (testPython.withPackages (ps: [ ps.my-editable ])) ];
} ''
mkdir -p src/my_editable
cat > src/my_editable/main.py << EOF
def main():
print("hello mutable")
EOF
test "$(my-script)" == "hello mutable"
test "$(python -c 'import sys; print(sys.path[1])')" == "$NIX_BUILD_TOP/src"
touch $out
'';
};
# Tests to ensure overriding works as expected.
overrideTests = let
extension = self: super: {
foobar = super.numpy;
};
# `pythonInterpreters.pypy39_prebuilt` does not expose an attribute
# name (is not present in top-level `pkgs`).
is_prebuilt = python: python.pythonAttr == null;
in lib.optionalAttrs (python.isPy3k) ({
test-packageOverrides = let
myPython = let
self = python.override {
packageOverrides = extension;
inherit self;
};
in self;
in assert myPython.pkgs.foobar == myPython.pkgs.numpy; myPython.withPackages(ps: with ps; [ foobar ]);
# overrideScope is broken currently
# test-overrideScope = let
# myPackages = python.pkgs.overrideScope extension;
# in assert myPackages.foobar == myPackages.numpy; myPackages.python.withPackages(ps: with ps; [ foobar ]);
#
# Have to skip prebuilt python as it's not present in top-level
# `pkgs` as an attribute.
} // lib.optionalAttrs (python ? pythonAttr && !is_prebuilt python) {
# Test applying overrides using pythonPackagesOverlays.
test-pythonPackagesExtensions = let
pkgs_ = pkgs.extend(final: prev: {
pythonPackagesExtensions = prev.pythonPackagesExtensions ++ [
(python-final: python-prev: {
foo = python-prev.setuptools;
})
];
});
in pkgs_.${python.pythonAttr}.pkgs.foo;
});
condaTests = let
requests = callPackage ({
autoPatchelfHook,
fetchurl,
pythonCondaPackages,
}:
python.pkgs.buildPythonPackage {
pname = "requests";
version = "2.24.0";
format = "other";
src = fetchurl {
url = "https://repo.anaconda.com/pkgs/main/noarch/requests-2.24.0-py_0.tar.bz2";
sha256 = "02qzaf6gwsqbcs69pix1fnjxzgnngwzvrsy65h1d521g750mjvvp";
};
nativeBuildInputs = [ autoPatchelfHook ] ++ (with python.pkgs; [
condaUnpackHook condaInstallHook
]);
buildInputs = [
pythonCondaPackages.condaPatchelfLibs
];
propagatedBuildInputs = with python.pkgs; [
chardet idna urllib3 certifi
];
overrideTests =
let
extension = self: super: {
foobar = super.numpy;
};
# `pythonInterpreters.pypy39_prebuilt` does not expose an attribute
# name (is not present in top-level `pkgs`).
is_prebuilt = python: python.pythonAttr == null;
in
lib.optionalAttrs (python.isPy3k) (
{
test-packageOverrides =
let
myPython =
let
self = python.override {
packageOverrides = extension;
inherit self;
};
in
self;
in
assert myPython.pkgs.foobar == myPython.pkgs.numpy;
myPython.withPackages (ps: with ps; [ foobar ]);
# overrideScope is broken currently
# test-overrideScope = let
# myPackages = python.pkgs.overrideScope extension;
# in assert myPackages.foobar == myPackages.numpy; myPackages.python.withPackages(ps: with ps; [ foobar ]);
#
# Have to skip prebuilt python as it's not present in top-level
# `pkgs` as an attribute.
}
) {};
pythonWithRequests = requests.pythonModule.withPackages (ps: [ requests ]);
in lib.optionalAttrs (python.isPy3k && stdenv.hostPlatform.isLinux)
{
condaExamplePackage = runCommand "import-requests" {} ''
// lib.optionalAttrs (python ? pythonAttr && !is_prebuilt python) {
# Test applying overrides using pythonPackagesOverlays.
test-pythonPackagesExtensions =
let
pkgs_ = pkgs.extend (
final: prev: {
pythonPackagesExtensions = prev.pythonPackagesExtensions ++ [
(python-final: python-prev: {
foo = python-prev.setuptools;
})
];
}
);
in
pkgs_.${python.pythonAttr}.pkgs.foo;
}
);
condaTests =
let
requests = callPackage (
{
autoPatchelfHook,
fetchurl,
pythonCondaPackages,
}:
python.pkgs.buildPythonPackage {
pname = "requests";
version = "2.24.0";
format = "other";
src = fetchurl {
url = "https://repo.anaconda.com/pkgs/main/noarch/requests-2.24.0-py_0.tar.bz2";
sha256 = "02qzaf6gwsqbcs69pix1fnjxzgnngwzvrsy65h1d521g750mjvvp";
};
nativeBuildInputs =
[ autoPatchelfHook ]
++ (with python.pkgs; [
condaUnpackHook
condaInstallHook
]);
buildInputs = [
pythonCondaPackages.condaPatchelfLibs
];
propagatedBuildInputs = with python.pkgs; [
chardet
idna
urllib3
certifi
];
}
) { };
pythonWithRequests = requests.pythonModule.withPackages (ps: [ requests ]);
in
lib.optionalAttrs (python.isPy3k && stdenv.hostPlatform.isLinux) {
condaExamplePackage = runCommand "import-requests" { } ''
${pythonWithRequests.interpreter} -c "import requests" > $out
'';
};
in lib.optionalAttrs (stdenv.hostPlatform == stdenv.buildPlatform ) (environmentTests // integrationTests // overrideTests // condaTests // editableTests)
in
lib.optionalAttrs (stdenv.hostPlatform == stdenv.buildPlatform) (
environmentTests // integrationTests // overrideTests // condaTests // editableTests
)
@@ -1,51 +1,66 @@
{ lib
, python
, makePythonHook
, makeWrapper }:
{
lib,
python,
makePythonHook,
makeWrapper,
}:
makePythonHook {
name = "wrap-python-hook";
propagatedBuildInputs = [ makeWrapper ];
substitutions.sitePackages = python.sitePackages;
substitutions.executable = python.interpreter;
substitutions.python = python.pythonOnBuildForHost;
substitutions.pythonHost = python;
substitutions.magicalSedExpression = let
# Looks weird? Of course, it's between single quoted shell strings.
# NOTE: Order DOES matter here, so single character quotes need to be
# at the last position.
quoteVariants = [ "'\"'''\"'" "\"\"\"" "\"" "'\"'\"'" ]; # hey Vim: ''
name = "wrap-python-hook";
propagatedBuildInputs = [ makeWrapper ];
substitutions.sitePackages = python.sitePackages;
substitutions.executable = python.interpreter;
substitutions.python = python.pythonOnBuildForHost;
substitutions.pythonHost = python;
substitutions.magicalSedExpression =
let
# Looks weird? Of course, it's between single quoted shell strings.
# NOTE: Order DOES matter here, so single character quotes need to be
# at the last position.
quoteVariants = [
"'\"'''\"'"
"\"\"\""
"\""
"'\"'\"'"
]; # hey Vim: ''
mkStringSkipper = labelNum: quote: let
mkStringSkipper =
labelNum: quote:
let
label = "q${toString labelNum}";
isSingle = lib.elem quote [ "\"" "'\"'\"'" ];
isSingle = lib.elem quote [
"\""
"'\"'\"'"
];
endQuote = if isSingle then "[^\\\\]${quote}" else quote;
in ''
in
''
/^[a-z]?${quote}/ {
/${quote}${quote}|${quote}.*${endQuote}/{n;br}
:${label}; n; /^${quote}/{n;br}; /${endQuote}/{n;br}; b${label}
}
'';
# This preamble does two things:
# * Sets argv[0] to the original application's name; otherwise it would be .foo-wrapped.
# Python doesn't support `exec -a`.
# * Adds all required libraries to sys.path via `site.addsitedir`. It also handles *.pth files.
preamble = ''
import sys
import site
import functools
sys.argv[0] = '"'$(readlink -f "$f")'"'
functools.reduce(lambda k, p: site.addsitedir(p, k), ['"$([ -n "$program_PYTHONPATH" ] && (echo "'$program_PYTHONPATH'" | sed "s|:|','|g") || true)"'], site._init_pathinfo())
'';
in ''
1 {
:r
/\\$|,$/{N;br}
/__future__|^ |^ *(#.*)?$/{n;br}
${lib.concatImapStrings mkStringSkipper quoteVariants}
/^[^# ]/i ${lib.replaceStrings ["\n"] [";"] preamble}
}
# This preamble does two things:
# * Sets argv[0] to the original application's name; otherwise it would be .foo-wrapped.
# Python doesn't support `exec -a`.
# * Adds all required libraries to sys.path via `site.addsitedir`. It also handles *.pth files.
preamble = ''
import sys
import site
import functools
sys.argv[0] = '"'$(readlink -f "$f")'"'
functools.reduce(lambda k, p: site.addsitedir(p, k), ['"$([ -n "$program_PYTHONPATH" ] && (echo "'$program_PYTHONPATH'" | sed "s|:|','|g") || true)"'], site._init_pathinfo())
'';
in
''
1 {
:r
/\\$|,$/{N;br}
/__future__|^ |^ *(#.*)?$/{n;br}
${lib.concatImapStrings mkStringSkipper quoteVariants}
/^[^# ]/i ${lib.replaceStrings [ "\n" ] [ ";" ] preamble}
}
'';
} ./wrap.sh
@@ -1,71 +1,82 @@
{ lib, stdenv, buildEnv, makeBinaryWrapper
{
lib,
stdenv,
buildEnv,
makeBinaryWrapper,
# manually pased
, python
, requiredPythonModules
# manually pased
python,
requiredPythonModules,
# extra opts
, extraLibs ? []
, extraOutputsToInstall ? []
, postBuild ? ""
, ignoreCollisions ? false
, permitUserSite ? false
# Wrap executables with the given argument.
, makeWrapperArgs ? []
, }:
# extra opts
extraLibs ? [ ],
extraOutputsToInstall ? [ ],
postBuild ? "",
ignoreCollisions ? false,
permitUserSite ? false,
# Wrap executables with the given argument.
makeWrapperArgs ? [ ],
}:
# Create a python executable that knows about additional packages.
let
env = let
paths = requiredPythonModules (extraLibs ++ [ python ] ) ;
pythonPath = "${placeholder "out"}/${python.sitePackages}";
pythonExecutable = "${placeholder "out"}/bin/${python.executable}";
in buildEnv {
name = "${python.name}-env";
env =
let
paths = requiredPythonModules (extraLibs ++ [ python ]);
pythonPath = "${placeholder "out"}/${python.sitePackages}";
pythonExecutable = "${placeholder "out"}/bin/${python.executable}";
in
buildEnv {
name = "${python.name}-env";
inherit paths;
inherit ignoreCollisions;
extraOutputsToInstall = [ "out" ] ++ extraOutputsToInstall;
inherit paths;
inherit ignoreCollisions;
extraOutputsToInstall = [ "out" ] ++ extraOutputsToInstall;
nativeBuildInputs = [ makeBinaryWrapper ];
nativeBuildInputs = [ makeBinaryWrapper ];
postBuild = ''
if [ -L "$out/bin" ]; then
unlink "$out/bin"
fi
mkdir -p "$out/bin"
postBuild =
''
if [ -L "$out/bin" ]; then
unlink "$out/bin"
fi
mkdir -p "$out/bin"
for path in ${lib.concatStringsSep " " paths}; do
if [ -d "$path/bin" ]; then
cd "$path/bin"
for prg in *; do
if [ -f "$prg" ]; then
rm -f "$out/bin/$prg"
if [ -x "$prg" ]; then
makeWrapper "$path/bin/$prg" "$out/bin/$prg" --set NIX_PYTHONPREFIX "$out" --set NIX_PYTHONEXECUTABLE ${pythonExecutable} --set NIX_PYTHONPATH ${pythonPath} ${lib.optionalString (!permitUserSite) ''--set PYTHONNOUSERSITE "true"''} ${lib.concatStringsSep " " makeWrapperArgs}
fi
for path in ${lib.concatStringsSep " " paths}; do
if [ -d "$path/bin" ]; then
cd "$path/bin"
for prg in *; do
if [ -f "$prg" ]; then
rm -f "$out/bin/$prg"
if [ -x "$prg" ]; then
makeWrapper "$path/bin/$prg" "$out/bin/$prg" --set NIX_PYTHONPREFIX "$out" --set NIX_PYTHONEXECUTABLE ${pythonExecutable} --set NIX_PYTHONPATH ${pythonPath} ${
lib.optionalString (!permitUserSite) ''--set PYTHONNOUSERSITE "true"''
} ${lib.concatStringsSep " " makeWrapperArgs}
fi
fi
done
fi
done
fi
done
'' + postBuild;
''
+ postBuild;
inherit (python) meta;
inherit (python) meta;
passthru = python.passthru // {
interpreter = "${env}/bin/${python.executable}";
inherit python;
env = stdenv.mkDerivation {
name = "interactive-${python.name}-environment";
nativeBuildInputs = [ env ];
passthru = python.passthru // {
interpreter = "${env}/bin/${python.executable}";
inherit python;
env = stdenv.mkDerivation {
name = "interactive-${python.name}-environment";
nativeBuildInputs = [ env ];
buildCommand = ''
echo >&2 ""
echo >&2 "*** Python 'env' attributes are intended for interactive nix-shell sessions, not for building! ***"
echo >&2 ""
exit 1
'';
buildCommand = ''
echo >&2 ""
echo >&2 "*** Python 'env' attributes are intended for interactive nix-shell sessions, not for building! ***"
echo >&2 ""
exit 1
'';
};
};
};
};
};
in env
in
env