about summary refs log tree commit diff
path: root/nixpkgs/pkgs/development/interpreters/python
diff options
context:
space:
mode:
Diffstat (limited to 'nixpkgs/pkgs/development/interpreters/python')
-rw-r--r--nixpkgs/pkgs/development/interpreters/python/cpython/2.7/default.nix17
-rw-r--r--nixpkgs/pkgs/development/interpreters/python/cpython/2.7/find_library-gcc10.patch79
-rw-r--r--nixpkgs/pkgs/development/interpreters/python/cpython/3.6/fix-finding-headers-when-cross-compiling.patch54
-rw-r--r--nixpkgs/pkgs/development/interpreters/python/cpython/3.7/fix-finding-headers-when-cross-compiling.patch54
-rw-r--r--nixpkgs/pkgs/development/interpreters/python/cpython/3.8/no-ldconfig.patch44
-rw-r--r--nixpkgs/pkgs/development/interpreters/python/cpython/default.nix85
-rw-r--r--nixpkgs/pkgs/development/interpreters/python/default.nix10
-rw-r--r--nixpkgs/pkgs/development/interpreters/python/mk-python-derivation.nix2
-rw-r--r--nixpkgs/pkgs/development/interpreters/python/pypy/default.nix14
-rw-r--r--nixpkgs/pkgs/development/interpreters/python/pypy/prebuilt.nix6
-rw-r--r--nixpkgs/pkgs/development/interpreters/python/tests.nix2
-rw-r--r--nixpkgs/pkgs/development/interpreters/python/wrapper.nix6
12 files changed, 319 insertions, 54 deletions
diff --git a/nixpkgs/pkgs/development/interpreters/python/cpython/2.7/default.nix b/nixpkgs/pkgs/development/interpreters/python/cpython/2.7/default.nix
index e6ab1f218795..85af394e3f65 100644
--- a/nixpkgs/pkgs/development/interpreters/python/cpython/2.7/default.nix
+++ b/nixpkgs/pkgs/development/interpreters/python/cpython/2.7/default.nix
@@ -1,4 +1,4 @@
-{ stdenv, fetchurl, fetchpatch
+{ lib, stdenv, fetchurl, fetchpatch
 , bzip2
 , expat
 , libffi
@@ -36,7 +36,7 @@ assert x11Support -> tcl != null
                   && xlibsWrapper != null
                   && libX11 != null;
 
-with stdenv.lib;
+with lib;
 
 let
   buildPackages = pkgsBuildHost;
@@ -114,6 +114,9 @@ let
       # libuuid, slowing down program startup a lot).
       ./no-ldconfig.patch
 
+      # Fix ctypes.util.find_library with gcc10.
+      ./find_library-gcc10.patch
+
     ] ++ optionals stdenv.hostPlatform.isCygwin [
       ./2.5.2-ctypes-util-find_library.patch
       ./2.5.2-tkinter-x11.patch
@@ -212,7 +215,7 @@ let
   };
 
   # Python 2.7 needs this
-  crossCompileEnv = stdenv.lib.optionalAttrs (stdenv.hostPlatform != stdenv.buildPlatform)
+  crossCompileEnv = lib.optionalAttrs (stdenv.hostPlatform != stdenv.buildPlatform)
                       { _PYTHON_HOST_PLATFORM = stdenv.hostPlatform.config; };
 
   # Build the basic Python interpreter without modules that have
@@ -224,7 +227,7 @@ in with passthru; stdenv.mkDerivation ({
 
     inherit src patches buildInputs nativeBuildInputs preConfigure configureFlags;
 
-    LDFLAGS = stdenv.lib.optionalString (!stdenv.isDarwin) "-lgcc_s";
+    LDFLAGS = lib.optionalString (!stdenv.isDarwin) "-lgcc_s";
     inherit (mkPaths buildInputs) C_INCLUDE_PATH LIBRARY_PATH;
 
     NIX_CFLAGS_COMPILE = optionalString stdenv.isDarwin "-msse2"
@@ -295,9 +298,9 @@ in with passthru; stdenv.mkDerivation ({
         hierarchical packages; exception-based error handling; and very
         high level dynamic data types.
       '';
-      license = stdenv.lib.licenses.psfl;
-      platforms = stdenv.lib.platforms.all;
-      maintainers = with stdenv.lib.maintainers; [ fridh ];
+      license = lib.licenses.psfl;
+      platforms = lib.platforms.all;
+      maintainers = with lib.maintainers; [ fridh ];
       # Higher priority than Python 3.x so that `/bin/python` points to `/bin/python2`
       # in case both 2 and 3 are installed.
       priority = -100;
diff --git a/nixpkgs/pkgs/development/interpreters/python/cpython/2.7/find_library-gcc10.patch b/nixpkgs/pkgs/development/interpreters/python/cpython/2.7/find_library-gcc10.patch
new file mode 100644
index 000000000000..4627baf119c1
--- /dev/null
+++ b/nixpkgs/pkgs/development/interpreters/python/cpython/2.7/find_library-gcc10.patch
@@ -0,0 +1,79 @@
+Backport https://github.com/python/cpython/commit/82df3b3071bb003247c33eac4670775e9883c994
+and https://github.com/python/cpython/commit/27ac19cca2c639caaf6fedf3632fe6beb265f24f
+
+Fixes the check phase of python2Packages.cffi.
+
+--- a/Lib/ctypes/util.py
++++ b/Lib/ctypes/util.py
+@@ -87,6 +87,12 @@ elif os.name == "posix":
+     # Andreas Degert's find functions, using gcc, /sbin/ldconfig, objdump
+     import re, tempfile, errno
+ 
++    def _is_elf(filename):
++        "Return True if the given file is an ELF file"
++        elf_header = b'\x7fELF'
++        with open(filename, 'rb') as thefile:
++            return thefile.read(4) == elf_header
++
+     def _findLib_gcc(name):
+         # Run GCC's linker with the -t (aka --trace) option and examine the
+         # library name it prints out. The GCC command will fail because we
+@@ -110,10 +116,17 @@ elif os.name == "posix":
+                 # the normal behaviour of GCC if linking fails
+                 if e.errno != errno.ENOENT:
+                     raise
+-        res = re.search(expr, trace)
++        res = re.findall(expr, trace)
+         if not res:
+             return None
+-        return res.group(0)
++
++        for file in res:
++            # Check if the given file is an elf file: gcc can report
++            # some files that are linker scripts and not actual
++            # shared objects. See bpo-41976 for more details
++            if not _is_elf(file):
++                continue
++            return file
+ 
+ 
+     if sys.platform == "sunos5":
+@@ -237,8 +250,37 @@ elif os.name == "posix":
+         def _findSoname_ldconfig(name):
+             return None
+ 
++        def _findLib_ld(name):
++            # See issue #9998 for why this is needed
++            expr = r'[^\(\)\s]*lib%s\.[^\(\)\s]*' % re.escape(name)
++            cmd = ['ld', '-t']
++            libpath = os.environ.get('LD_LIBRARY_PATH')
++            if libpath:
++                for d in libpath.split(':'):
++                    cmd.extend(['-L', d])
++            cmd.extend(['-o', os.devnull, '-l%s' % name])
++            result = None
++            try:
++                p = subprocess.Popen(cmd, stdout=subprocess.PIPE,
++                                     stderr=subprocess.PIPE,
++                                     universal_newlines=True)
++                out, _ = p.communicate()
++                res = re.findall(expr, out)
++                for file in res:
++                    # Check if the given file is an elf file: gcc can report
++                    # some files that are linker scripts and not actual
++                    # shared objects. See bpo-41976 for more details
++                    if not _is_elf(file):
++                        continue
++                    return file
++            except Exception:
++                pass  # result will be None
++            return result
++
+         def find_library(name):
+-            return _findSoname_ldconfig(name) or _get_soname(_findLib_gcc(name))
++            # See issue #9998
++            return _findSoname_ldconfig(name) or \
++                   _get_soname(_findLib_gcc(name)) or _get_soname(_findLib_ld(name))
+ 
+ ################################################################
+ # test code
diff --git a/nixpkgs/pkgs/development/interpreters/python/cpython/3.6/fix-finding-headers-when-cross-compiling.patch b/nixpkgs/pkgs/development/interpreters/python/cpython/3.6/fix-finding-headers-when-cross-compiling.patch
new file mode 100644
index 000000000000..d324d10b39fc
--- /dev/null
+++ b/nixpkgs/pkgs/development/interpreters/python/cpython/3.6/fix-finding-headers-when-cross-compiling.patch
@@ -0,0 +1,54 @@
+From 45dfbbb4f5b67ab83e4365564ea569334e979f8e Mon Sep 17 00:00:00 2001
+From: Ben Wolsieffer <benwolsieffer@gmail.com>
+Date: Fri, 25 Sep 2020 16:49:16 -0400
+Subject: [PATCH] Fix finding headers when cross compiling
+
+When cross-compiling third-party extensions, get_python_inc() may be called to
+return the path to Python's headers. However, it uses the sys.prefix or
+sys.exec_prefix of the build Python, which returns incorrect paths when
+cross-compiling (paths pointing to build system headers).
+
+To fix this, we use the INCLUDEPY and CONFINCLUDEPY conf variables, which can
+be configured to point at host Python by setting _PYTHON_SYSCONFIGDATA_NAME.
+The existing behavior is maintained on non-POSIX platforms or if a prefix is
+manually specified.
+---
+ Lib/distutils/sysconfig.py | 14 ++++++++++----
+ 1 file changed, 10 insertions(+), 4 deletions(-)
+
+diff --git a/Lib/distutils/sysconfig.py b/Lib/distutils/sysconfig.py
+index 2bcd1dd288..567375e488 100644
+--- a/Lib/distutils/sysconfig.py
++++ b/Lib/distutils/sysconfig.py
+@@ -84,8 +84,6 @@ def get_python_inc(plat_specific=0, prefix=None):
+     If 'prefix' is supplied, use it instead of sys.base_prefix or
+     sys.base_exec_prefix -- i.e., ignore 'plat_specific'.
+     """
+-    if prefix is None:
+-        prefix = plat_specific and BASE_EXEC_PREFIX or BASE_PREFIX
+     if os.name == "posix":
+         if python_build:
+             # Assume the executable is in the build directory.  The
+@@ -98,9 +96,17 @@ def get_python_inc(plat_specific=0, prefix=None):
+             else:
+                 incdir = os.path.join(get_config_var('srcdir'), 'Include')
+                 return os.path.normpath(incdir)
+-        python_dir = 'python' + get_python_version() + build_flags
+-        return os.path.join(prefix, "include", python_dir)
++        if prefix is None:
++          if plat_specific:
++            return get_config_var('CONFINCLUDEPY')
++          else:
++            return get_config_var('INCLUDEPY')
++        else:
++          python_dir = 'python' + get_python_version() + build_flags
++          return os.path.join(prefix, "include", python_dir)
+     elif os.name == "nt":
++        if prefix is None:
++          prefix = plat_specific and BASE_EXEC_PREFIX or BASE_PREFIX
+         return os.path.join(prefix, "include")
+     else:
+         raise DistutilsPlatformError(
+-- 
+2.28.0
+
diff --git a/nixpkgs/pkgs/development/interpreters/python/cpython/3.7/fix-finding-headers-when-cross-compiling.patch b/nixpkgs/pkgs/development/interpreters/python/cpython/3.7/fix-finding-headers-when-cross-compiling.patch
new file mode 100644
index 000000000000..543e267e94bf
--- /dev/null
+++ b/nixpkgs/pkgs/development/interpreters/python/cpython/3.7/fix-finding-headers-when-cross-compiling.patch
@@ -0,0 +1,54 @@
+From debccd4be0a8d619770f63622d9de1b451dd02ac Mon Sep 17 00:00:00 2001
+From: Ben Wolsieffer <benwolsieffer@gmail.com>
+Date: Fri, 25 Sep 2020 16:49:16 -0400
+Subject: [PATCH] Fix finding headers when cross compiling
+
+When cross-compiling third-party extensions, get_python_inc() may be called to
+return the path to Python's headers. However, it uses the sys.prefix or
+sys.exec_prefix of the build Python, which returns incorrect paths when
+cross-compiling (paths pointing to build system headers).
+
+To fix this, we use the INCLUDEPY and CONFINCLUDEPY conf variables, which can
+be configured to point at host Python by setting _PYTHON_SYSCONFIGDATA_NAME.
+The existing behavior is maintained on non-POSIX platforms or if a prefix is
+manually specified.
+---
+ Lib/distutils/sysconfig.py | 14 ++++++++++----
+ 1 file changed, 10 insertions(+), 4 deletions(-)
+
+diff --git a/Lib/distutils/sysconfig.py b/Lib/distutils/sysconfig.py
+index 37feae5df7..6d4ad06696 100644
+--- a/Lib/distutils/sysconfig.py
++++ b/Lib/distutils/sysconfig.py
+@@ -95,8 +95,6 @@ def get_python_inc(plat_specific=0, prefix=None):
+     If 'prefix' is supplied, use it instead of sys.base_prefix or
+     sys.base_exec_prefix -- i.e., ignore 'plat_specific'.
+     """
+-    if prefix is None:
+-        prefix = plat_specific and BASE_EXEC_PREFIX or BASE_PREFIX
+     if os.name == "posix":
+         if python_build:
+             # Assume the executable is in the build directory.  The
+@@ -109,9 +107,17 @@ def get_python_inc(plat_specific=0, prefix=None):
+             else:
+                 incdir = os.path.join(get_config_var('srcdir'), 'Include')
+                 return os.path.normpath(incdir)
+-        python_dir = 'python' + get_python_version() + build_flags
+-        return os.path.join(prefix, "include", python_dir)
++        if prefix is None:
++          if plat_specific:
++            return get_config_var('CONFINCLUDEPY')
++          else:
++            return get_config_var('INCLUDEPY')
++        else:
++          python_dir = 'python' + get_python_version() + build_flags
++          return os.path.join(prefix, "include", python_dir)
+     elif os.name == "nt":
++        if prefix is None:
++          prefix = plat_specific and BASE_EXEC_PREFIX or BASE_PREFIX
+         if python_build:
+             # Include both the include and PC dir to ensure we can find
+             # pyconfig.h
+-- 
+2.28.0
+
diff --git a/nixpkgs/pkgs/development/interpreters/python/cpython/3.8/no-ldconfig.patch b/nixpkgs/pkgs/development/interpreters/python/cpython/3.8/no-ldconfig.patch
index a1f9d68eb166..41d3ab52345b 100644
--- a/nixpkgs/pkgs/development/interpreters/python/cpython/3.8/no-ldconfig.patch
+++ b/nixpkgs/pkgs/development/interpreters/python/cpython/3.8/no-ldconfig.patch
@@ -1,19 +1,19 @@
-From 597e73f2a4b2f0b508127931b36d5540d6941823 Mon Sep 17 00:00:00 2001
-From: Frederik Rietdijk <fridh@fridh.nl>
-Date: Mon, 28 Aug 2017 09:24:06 +0200
+From 66f492d2eda94bd64db833839a325caf6ba0fed5 Mon Sep 17 00:00:00 2001
+From: Greg Roodt <greg@canva.com>
+Date: Wed, 9 Dec 2020 17:59:24 +1100
 Subject: [PATCH] Don't use ldconfig
 
 ---
- Lib/ctypes/util.py | 70 ++----------------------------------------------------
- 1 file changed, 2 insertions(+), 68 deletions(-)
+ Lib/ctypes/util.py | 77 ++--------------------------------------------
+ 1 file changed, 2 insertions(+), 75 deletions(-)
 
 diff --git a/Lib/ctypes/util.py b/Lib/ctypes/util.py
-index 5e8b31a854..7b45ce6c15 100644
+index 0c2510e161..7fb98af308 100644
 --- a/Lib/ctypes/util.py
 +++ b/Lib/ctypes/util.py
-@@ -94,46 +94,7 @@ elif os.name == "posix":
-     import re, tempfile
- 
+@@ -100,53 +100,7 @@ elif os.name == "posix":
+             return thefile.read(4) == elf_header
+
      def _findLib_gcc(name):
 -        # Run GCC's linker with the -t (aka --trace) option and examine the
 -        # library name it prints out. The GCC command will fail because we
@@ -51,17 +51,24 @@ index 5e8b31a854..7b45ce6c15 100644
 -                # Raised if the file was already removed, which is the normal
 -                # behaviour of GCC if linking fails
 -                pass
--        res = re.search(expr, trace)
+-        res = re.findall(expr, trace)
 -        if not res:
 -            return None
--        return os.fsdecode(res.group(0))
+-
+-        for file in res:
+-            # Check if the given file is an elf file: gcc can report
+-            # some files that are linker scripts and not actual
+-            # shared objects. See bpo-41976 for more details
+-            if not _is_elf(file):
+-                continue
+-            return os.fsdecode(file)
 +        return None
- 
- 
+
+
      if sys.platform == "sunos5":
-@@ -255,34 +216,7 @@ elif os.name == "posix":
+@@ -268,34 +222,7 @@ elif os.name == "posix":
      else:
- 
+
          def _findSoname_ldconfig(name):
 -            import struct
 -            if struct.calcsize('l') == 4:
@@ -92,9 +99,8 @@ index 5e8b31a854..7b45ce6c15 100644
 -            except OSError:
 -                pass
 +            return None
- 
+
          def _findLib_ld(name):
              # See issue #9998 for why this is needed
--- 
-2.15.0
-
+--
+2.24.3 (Apple Git-128)
diff --git a/nixpkgs/pkgs/development/interpreters/python/cpython/default.nix b/nixpkgs/pkgs/development/interpreters/python/cpython/default.nix
index f62a0b0bfe13..7bc6084f61dd 100644
--- a/nixpkgs/pkgs/development/interpreters/python/cpython/default.nix
+++ b/nixpkgs/pkgs/development/interpreters/python/cpython/default.nix
@@ -1,4 +1,4 @@
-{ stdenv, fetchurl, fetchpatch
+{ lib, stdenv, fetchurl, fetchpatch
 , bzip2
 , expat
 , libffi
@@ -35,7 +35,7 @@
 , rebuildBytecode ? true
 , stripBytecode ? false
 , includeSiteCustomize ? true
-, static ? false
+, static ? stdenv.hostPlatform.isStatic
 # Not using optimizations on Darwin
 # configure: error: llvm-profdata is required for a --enable-optimizations build but could not be found.
 , enableOptimizations ? (!stdenv.isDarwin)
@@ -54,7 +54,7 @@ assert x11Support -> tcl != null
 
 assert bluezSupport -> bluez != null;
 
-with stdenv.lib;
+with lib;
 
 let
   buildPackages = pkgsBuildHost;
@@ -100,6 +100,56 @@ let
     "$out/bin/python"
   else pythonForBuild.interpreter;
 
+  # The CPython interpreter contains a _sysconfigdata_<platform specific suffix>
+  # module that is imported by the sysconfig and distutils.sysconfig modules.
+  # The sysconfigdata module is generated at build time and contains settings
+  # required for building Python extension modules, such as include paths and
+  # other compiler flags. By default, the sysconfigdata module is loaded from
+  # the currently running interpreter (ie. the build platform interpreter), but
+  # when cross-compiling we want to load it from the host platform interpreter.
+  # This can be done using the _PYTHON_SYSCONFIGDATA_NAME environment variable.
+  # The _PYTHON_HOST_PLATFORM variable also needs to be set to get the correct
+  # platform suffix on extension modules. The correct values for these variables
+  # are not documented, and must be derived from the configure script (see links
+  # below).
+  sysconfigdataHook = with stdenv.hostPlatform; with passthru; let
+    # https://github.com/python/cpython/blob/e488e300f5c01289c10906c2e53a8e43d6de32d8/configure.ac#L428
+    # The configure script uses "arm" as the CPU name for all 32-bit ARM
+    # variants when cross-compiling, but native builds include the version
+    # suffix, so we do the same.
+    pythonHostPlatform = "${parsed.kernel.name}-${parsed.cpu.name}";
+
+    # https://github.com/python/cpython/blob/e488e300f5c01289c10906c2e53a8e43d6de32d8/configure.ac#L724
+    multiarchCpu =
+      if isAarch32 then
+        if parsed.cpu.significantByte.name == "littleEndian" then "arm" else "armeb"
+      else if isx86_32 then "i386"
+      else parsed.cpu.name;
+    pythonAbiName =
+      # python's build doesn't differentiate between musl and glibc in its
+      # abi detection, our wrapper should match.
+      if stdenv.hostPlatform.isMusl then
+        replaceStrings [ "musl" ] [ "gnu" ] parsed.abi.name
+        else parsed.abi.name;
+    multiarch =
+      if isDarwin then "darwin"
+      else "${multiarchCpu}-${parsed.kernel.name}-${pythonAbiName}";
+
+    abiFlags = optionalString (isPy36 || isPy37) "m";
+
+    # https://github.com/python/cpython/blob/e488e300f5c01289c10906c2e53a8e43d6de32d8/configure.ac#L78
+    pythonSysconfigdataName = "_sysconfigdata_${abiFlags}_${parsed.kernel.name}_${multiarch}";
+  in ''
+    sysconfigdataHook() {
+      if [ "$1" = '${placeholder "out"}' ]; then
+        export _PYTHON_HOST_PLATFORM='${pythonHostPlatform}'
+        export _PYTHON_SYSCONFIGDATA_NAME='${pythonSysconfigdataName}'
+      fi
+    }
+
+    addEnvHooks "$hostOffset" sysconfigdataHook
+  '';
+
 in with passthru; stdenv.mkDerivation {
   pname = "python3";
   inherit version;
@@ -165,7 +215,14 @@ in with passthru; stdenv.mkDerivation {
   ] ++ [
     # LDSHARED now uses $CC instead of gcc. Fixes cross-compilation of extension modules.
     ./3.8/0001-On-all-posix-systems-not-just-Darwin-set-LDSHARED-if.patch
-  ] ++ optionals (isPy36 || isPy37 || isPy38) [
+    # Use sysconfigdata to find headers. Fixes cross-compilation of extension modules.
+    (
+      if isPy36 then
+        ./3.6/fix-finding-headers-when-cross-compiling.patch
+      else
+        ./3.7/fix-finding-headers-when-cross-compiling.patch
+    )
+  ] ++ optionals (isPy36 || isPy37) [
     # Backport a fix for ctypes.util.find_library.
     ./3.7/find_library.patch
   ];
@@ -281,6 +338,10 @@ in with passthru; stdenv.mkDerivation {
     find $out/lib/python*/config-* -type f -print -exec nuke-refs -e $out '{}' +
     find $out/lib -name '_sysconfigdata*.py*' -print -exec nuke-refs -e $out '{}' +
 
+    # Make the sysconfigdata module accessible on PYTHONPATH
+    # This allows build Python to import host Python's sysconfigdata
+    mkdir -p "$out/${sitePackages}"
+    ln -s "$out/lib/${libPrefix}/"_sysconfigdata*.py "$out/${sitePackages}/"
     '' + optionalString stripConfig ''
     rm -R $out/bin/python*-config $out/lib/python*/config-*
     '' + optionalString stripIdlelib ''
@@ -308,16 +369,24 @@ in with passthru; stdenv.mkDerivation {
     find $out -type d -name __pycache__ -print0 | xargs -0 -I {} rm -rf "{}"
   '';
 
-  preFixup = stdenv.lib.optionalString (stdenv.hostPlatform != stdenv.buildPlatform) ''
+  preFixup = lib.optionalString (stdenv.hostPlatform != stdenv.buildPlatform) ''
     # Ensure patch-shebangs uses shebangs of host interpreter.
-    export PATH=${stdenv.lib.makeBinPath [ "$out" bash ]}:$PATH
+    export PATH=${lib.makeBinPath [ "$out" bash ]}:$PATH
+  '';
+
+  # Add CPython specific setup-hook that configures distutils.sysconfig to
+  # always load sysconfigdata from host Python.
+  postFixup = lib.optionalString (!stdenv.hostPlatform.isDarwin) ''
+    cat << "EOF" >> "$out/nix-support/setup-hook"
+    ${sysconfigdataHook}
+    EOF
   '';
 
   # Enforce that we don't have references to the OpenSSL -dev package, which we
   # explicitly specify in our configure flags above.
   disallowedReferences =
-    stdenv.lib.optionals (openssl != null && !static) [ openssl.dev ]
-    ++ stdenv.lib.optionals (stdenv.hostPlatform != stdenv.buildPlatform) [
+    lib.optionals (openssl != null && !static) [ openssl.dev ]
+    ++ lib.optionals (stdenv.hostPlatform != stdenv.buildPlatform) [
     # Ensure we don't have references to build-time packages.
     # These typically end up in shebangs.
     pythonForBuild buildPackages.bash
diff --git a/nixpkgs/pkgs/development/interpreters/python/default.nix b/nixpkgs/pkgs/development/interpreters/python/default.nix
index 2982cdc8856d..38b0382c2191 100644
--- a/nixpkgs/pkgs/development/interpreters/python/default.nix
+++ b/nixpkgs/pkgs/development/interpreters/python/default.nix
@@ -24,7 +24,7 @@ with pkgs;
       pythonPackages = callPackage
         ({ pkgs, stdenv, python, overrides }: let
           pythonPackagesFun = import ../../../top-level/python-packages.nix {
-            inherit stdenv pkgs;
+            inherit stdenv pkgs lib;
             python = self;
           };
           otherSplices = {
@@ -154,10 +154,10 @@ in {
     sourceVersion = {
       major = "3";
       minor = "8";
-      patch = "6";
+      patch = "7";
       suffix = "";
     };
-    sha256 = "qeC3nSeqBW65zOjWOkJ7X5urFGXe4/lC3P2yWoL0q4o=";
+    sha256 = "sha256-3cwd8Wu1uHqkLsXSCluQLy0IjKommyjgFZD5enmOxQo=";
     inherit (darwin) configd;
     inherit passthruFun;
   };
@@ -181,9 +181,9 @@ in {
       major = "3";
       minor = "10";
       patch = "0";
-      suffix = "a3";
+      suffix = "a4";
     };
-    sha256 = "sha256-sJjJdAdxOUfX7W7VioSGdxlgp2lyMOPZjg42MCd/JYY=";
+    sha256 = "sha256-McHBl7IZuOH96je/izkxur0Edirn+igVkQU/pbek73M=";
     inherit (darwin) configd;
     inherit passthruFun;
   };
diff --git a/nixpkgs/pkgs/development/interpreters/python/mk-python-derivation.nix b/nixpkgs/pkgs/development/interpreters/python/mk-python-derivation.nix
index 670c870f1077..175454ea0559 100644
--- a/nixpkgs/pkgs/development/interpreters/python/mk-python-derivation.nix
+++ b/nixpkgs/pkgs/development/interpreters/python/mk-python-derivation.nix
@@ -162,7 +162,7 @@ let
 
     postFixup = lib.optionalString (!dontWrapPythonPrograms) ''
       wrapPythonPrograms
-    '' + attrs.postFixup or '''';
+    '' + attrs.postFixup or "";
 
     # Python packages built through cross-compilation are always for the host platform.
     disallowedReferences = lib.optionals (python.stdenv.hostPlatform != python.stdenv.buildPlatform) [ python.pythonForBuild ];
diff --git a/nixpkgs/pkgs/development/interpreters/python/pypy/default.nix b/nixpkgs/pkgs/development/interpreters/python/pypy/default.nix
index 8feeb3c51bf3..cfa1ac71891c 100644
--- a/nixpkgs/pkgs/development/interpreters/python/pypy/default.nix
+++ b/nixpkgs/pkgs/development/interpreters/python/pypy/default.nix
@@ -1,5 +1,5 @@
-{ stdenv, substituteAll, fetchurl
-, zlib ? null, zlibSupport ? true, bzip2, pkgconfig, libffi, libunwind, Security
+{ lib, stdenv, substituteAll, fetchurl
+, zlib ? null, zlibSupport ? true, bzip2, pkg-config, libffi, libunwind, Security
 , sqlite, openssl, ncurses, python, expat, tcl, tk, tix, xlibsWrapper, libX11
 , self, gdbm, db, lzma
 , python-setup-hook
@@ -14,12 +14,12 @@
 , pythonVersion
 , sha256
 , passthruFun
-, pythonAttr ? "pypy${stdenv.lib.substring 0 1 pythonVersion}${stdenv.lib.substring 2 3 pythonVersion}"
+, pythonAttr ? "pypy${lib.substring 0 1 pythonVersion}${lib.substring 2 3 pythonVersion}"
 }:
 
 assert zlibSupport -> zlib != null;
 
-with stdenv.lib;
+with lib;
 
 let
   isPy3k = substring 0 1 pythonVersion == "3";
@@ -49,7 +49,7 @@ in with passthru; stdenv.mkDerivation rec {
     inherit sha256;
   };
 
-  nativeBuildInputs = [ pkgconfig ];
+  nativeBuildInputs = [ pkg-config ];
   buildInputs = [
     bzip2 openssl pythonForPypy libffi ncurses expat sqlite tk tcl xlibsWrapper libX11 gdbm db
   ]  ++ optionals isPy3k [
@@ -144,7 +144,7 @@ in with passthru; stdenv.mkDerivation rec {
     ln -s $out/${executable}-c/include $out/include/${libPrefix}
     ln -s $out/${executable}-c/lib-python/${if isPy3k then "3" else pythonVersion} $out/lib/${libPrefix}
 
-    ${stdenv.lib.optionalString stdenv.isDarwin ''
+    ${lib.optionalString stdenv.isDarwin ''
       install_name_tool -change @rpath/libpypy${optionalString isPy3k "3"}-c.dylib $out/lib/libpypy${optionalString isPy3k "3"}-c.dylib $out/bin/${executable}
     ''}
 
@@ -158,7 +158,7 @@ in with passthru; stdenv.mkDerivation rec {
   inherit passthru;
   enableParallelBuilding = true;  # almost no parallelization without STM
 
-  meta = with stdenv.lib; {
+  meta = with lib; {
     homepage = "http://pypy.org/";
     description = "Fast, compliant alternative implementation of the Python language (${pythonVersion})";
     license = licenses.mit;
diff --git a/nixpkgs/pkgs/development/interpreters/python/pypy/prebuilt.nix b/nixpkgs/pkgs/development/interpreters/python/pypy/prebuilt.nix
index 1522047a3806..6fd0ee2e925f 100644
--- a/nixpkgs/pkgs/development/interpreters/python/pypy/prebuilt.nix
+++ b/nixpkgs/pkgs/development/interpreters/python/pypy/prebuilt.nix
@@ -22,7 +22,7 @@
 # This version of PyPy is primarily added to speed-up translation of
 # our PyPy source build when developing that expression.
 
-with stdenv.lib;
+with lib;
 
 let
   isPy3k = majorVersion == "3";
@@ -78,7 +78,7 @@ in with passthru; stdenv.mkDerivation {
 
     pushd $out
     find {lib,lib_pypy*} -name "*.so" -exec patchelf --remove-needed libncursesw.so.6 --replace-needed libtinfow.so.6 libncursesw.so.6 {} \;
-    find {lib,lib_pypy*} -name "*.so" -exec patchelf --set-rpath ${stdenv.lib.makeLibraryPath deps}:$out/lib {} \;
+    find {lib,lib_pypy*} -name "*.so" -exec patchelf --set-rpath ${lib.makeLibraryPath deps}:$out/lib {} \;
 
     echo "Removing bytecode"
     find . -name "__pycache__" -type d -depth -exec rm -rf {} \;
@@ -115,7 +115,7 @@ in with passthru; stdenv.mkDerivation {
 
   inherit passthru;
 
-  meta = with stdenv.lib; {
+  meta = with lib; {
     homepage = "http://pypy.org/";
     description = "Fast, compliant alternative implementation of the Python language (${pythonVersion})";
     license = licenses.mit;
diff --git a/nixpkgs/pkgs/development/interpreters/python/tests.nix b/nixpkgs/pkgs/development/interpreters/python/tests.nix
index a291919b3277..61fc497024be 100644
--- a/nixpkgs/pkgs/development/interpreters/python/tests.nix
+++ b/nixpkgs/pkgs/development/interpreters/python/tests.nix
@@ -93,4 +93,4 @@ let
 
 
 
-in stdenv.lib.optionalAttrs (stdenv.hostPlatform == stdenv.buildPlatform ) (environmentTests // integrationTests)
+in lib.optionalAttrs (stdenv.hostPlatform == stdenv.buildPlatform ) (environmentTests // integrationTests)
diff --git a/nixpkgs/pkgs/development/interpreters/python/wrapper.nix b/nixpkgs/pkgs/development/interpreters/python/wrapper.nix
index dffad6b98f5e..61ad4a8a6ad9 100644
--- a/nixpkgs/pkgs/development/interpreters/python/wrapper.nix
+++ b/nixpkgs/pkgs/development/interpreters/python/wrapper.nix
@@ -1,4 +1,4 @@
-{ stdenv, python, buildEnv, makeWrapper
+{ lib, stdenv, python, buildEnv, makeWrapper
 , extraLibs ? []
 , extraOutputsToInstall ? []
 , postBuild ? ""
@@ -30,14 +30,14 @@ let
       fi
       mkdir -p "$out/bin"
 
-      for path in ${stdenv.lib.concatStringsSep " " paths}; do
+      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} ${if permitUserSite then "" else ''--set PYTHONNOUSERSITE "true"''} ${stdenv.lib.concatStringsSep " " makeWrapperArgs}
+                makeWrapper "$path/bin/$prg" "$out/bin/$prg" --set NIX_PYTHONPREFIX "$out" --set NIX_PYTHONEXECUTABLE ${pythonExecutable} --set NIX_PYTHONPATH ${pythonPath} ${if permitUserSite then "" else ''--set PYTHONNOUSERSITE "true"''} ${lib.concatStringsSep " " makeWrapperArgs}
               fi
             fi
           done