about summary refs log tree commit diff
path: root/pkgs/development/interpreters/python
diff options
context:
space:
mode:
Diffstat (limited to 'pkgs/development/interpreters/python')
-rw-r--r--pkgs/development/interpreters/python/cpython/default.nix12
-rw-r--r--pkgs/development/interpreters/python/default.nix45
-rw-r--r--pkgs/development/interpreters/python/pypy/prebuilt.nix20
-rw-r--r--pkgs/development/interpreters/python/pypy/prebuilt_2_7.nix132
-rwxr-xr-xpkgs/development/interpreters/python/update-python-libraries/update-python-libraries.py36
5 files changed, 198 insertions, 47 deletions
diff --git a/pkgs/development/interpreters/python/cpython/default.nix b/pkgs/development/interpreters/python/cpython/default.nix
index e4a974a255b89..1bcbd2bb4b5e9 100644
--- a/pkgs/development/interpreters/python/cpython/default.nix
+++ b/pkgs/development/interpreters/python/cpython/default.nix
@@ -4,7 +4,7 @@
 , libffi
 , gdbm
 , xz
-, mime-types ? null, mimetypesSupport ? true
+, mailcap, mimetypesSupport ? true
 , ncurses
 , openssl
 , readline
@@ -17,6 +17,7 @@
 , configd
 , autoreconfHook
 , autoconf-archive
+, pkg-config
 , python-setup-hook
 , nukeReferences
 # For the Python package set
@@ -62,8 +63,6 @@ assert x11Support -> tcl != null
 
 assert bluezSupport -> bluez != null;
 
-assert mimetypesSupport -> mime-types != 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.";
 
@@ -105,7 +104,7 @@ let
 
   nativeBuildInputs = optionals (!stdenv.isDarwin) [
     autoreconfHook
-  ] ++ optionals (!stdenv.isDarwin && passthru.pythonAtLeast "3.10") [
+    pkg-config
     autoconf-archive # needed for AX_CHECK_COMPILE_FLAG
   ] ++ [
     nukeReferences
@@ -193,7 +192,8 @@ in with passthru; stdenv.mkDerivation {
   prePatch = optionalString stdenv.isDarwin ''
     substituteInPlace configure --replace '`/usr/bin/arch`' '"i386"'
     substituteInPlace configure --replace '-Wl,-stack_size,1000000' ' '
-  '' + optionalString (stdenv.isDarwin && x11Support) ''
+  '' + optionalString (pythonOlder "3.9" && stdenv.isDarwin && x11Support) ''
+    # Broken on >= 3.9; replaced with ./3.9/darwin-tcl-tk.patch
     substituteInPlace setup.py --replace /Library/Frameworks /no-such-path
   '';
 
@@ -276,7 +276,7 @@ in with passthru; stdenv.mkDerivation {
       --replace "'/bin/sh'" "'${bash}/bin/sh'"
   '' + optionalString mimetypesSupport ''
     substituteInPlace Lib/mimetypes.py \
-      --replace "@mime-types@" "${mime-types}"
+      --replace "@mime-types@" "${mailcap}"
   '' + optionalString (x11Support && (tix != null)) ''
     substituteInPlace "Lib/tkinter/tix.py" --replace "os.environ.get('TIX_LIBRARY')" "os.environ.get('TIX_LIBRARY') or '${tix}/lib'"
   '';
diff --git a/pkgs/development/interpreters/python/default.nix b/pkgs/development/interpreters/python/default.nix
index 3e53ea251a27b..6bee51f64232a 100644
--- a/pkgs/development/interpreters/python/default.nix
+++ b/pkgs/development/interpreters/python/default.nix
@@ -133,10 +133,19 @@ with pkgs;
       sourceVersion = {
         major = "3";
         minor = "9";
-        patch = "9";
+        patch = "10";
         suffix = "";
       };
-      sha256 = "sha256-BoKMBKVzwHOk5RxCkqJ8G+SuJmIcPtx8+TGEGM47bSc=";
+      sha256 = "sha256-Co+/tSh+vDoT6brz1U4I+gZ3j/7M9jEa74Ibs6ZYbMg=";
+    };
+    python310 = {
+      sourceVersion = {
+        major = "3";
+        minor = "10";
+        patch = "2";
+        suffix = "";
+      };
+      sha256 = "sha256-F946x9qfJRmqnWQ3jGA6c6DprVjf+ogS5FFgwIbeZMc=";
     };
   };
 
@@ -180,18 +189,11 @@ in {
     inherit passthruFun;
   } // sources.python39);
 
-  python310 = callPackage ./cpython {
+  python310 = callPackage ./cpython ({
     self = python310;
-    sourceVersion = {
-      major = "3";
-      minor = "10";
-      patch = "0";
-      suffix = "";
-    };
-    sha256 = "00mhn6kj4qkvkkv6hh2klnnjr0yk0c9hspp7njc7n6m1lvkzi6as";
     inherit (darwin) configd;
     inherit passthruFun;
-  };
+  } // sources.python310);
 
   python311 = callPackage ./cpython {
     self = python311;
@@ -199,9 +201,9 @@ in {
       major = "3";
       minor = "11";
       patch = "0";
-      suffix = "a2";
+      suffix = "a4";
     };
-    sha256 = "sha256-aKjE1s4lSKe2F9aZ+9s0iTe9rODPltsaoIOEnfXa0T8=";
+    sha256 = "sha256-Q3/nN2w2Pa+vNM6A8ERrQfyaQsDiqMflGdPwoLfPs+0=";
     inherit (darwin) configd;
     inherit passthruFun;
   };
@@ -219,6 +221,7 @@ in {
     sqlite = null;
     configd = null;
     tzdata = null;
+    libffi = pkgs.libffiBoot; # without test suite
     stripConfig = true;
     stripIdlelib = true;
     stripTests = true;
@@ -273,29 +276,29 @@ in {
     sha256 = "sha256-LtAqyecQhZxBvILer7CGGXkruaJ+6qFnbHQe3t0hTdc=";
   };
 
-  pypy27_prebuilt = callPackage ./pypy/prebuilt.nix {
+  pypy27_prebuilt = callPackage ./pypy/prebuilt_2_7.nix {
     # Not included at top-level
     self = pythonInterpreters.pypy27_prebuilt;
     sourceVersion = {
       major = "7";
       minor = "3";
-      patch = "3";
+      patch = "6";
     };
-    sha256 = "1cfpdyvbvzwc0ynjr7248jhwgcpl7073wlp7w3g2v4fnrh1bc4pl"; # linux64
+    sha256 = "sha256-ghJ/Q/rmznXUfWxFOfjB6jcunC2/pA+ui1g1HVInk6Q="; # linux64
     pythonVersion = "2.7";
     inherit passthruFun;
   };
 
-  pypy36_prebuilt = callPackage ./pypy/prebuilt.nix {
+  pypy38_prebuilt = callPackage ./pypy/prebuilt.nix {
     # Not included at top-level
-    self = pythonInterpreters.pypy36_prebuilt;
+    self = pythonInterpreters.pypy38_prebuilt;
     sourceVersion = {
       major = "7";
       minor = "3";
-      patch = "3";
+      patch = "7";
     };
-    sha256 = "02lys9bjky9bqg6ggv8djirbd3zzcsq7755v4yvwm0k4a7fmzf2g"; # linux64
-    pythonVersion = "3.6";
+    sha256 = "sha256-Xe43x8PLixYAKPveOlkBxoBD36VFoWeUUCuJfUvEDX4="; # linux64
+    pythonVersion = "3.8";
     inherit passthruFun;
   };
 
diff --git a/pkgs/development/interpreters/python/pypy/prebuilt.nix b/pkgs/development/interpreters/python/pypy/prebuilt.nix
index 460af1cc67b4f..69de6e94e3781 100644
--- a/pkgs/development/interpreters/python/pypy/prebuilt.nix
+++ b/pkgs/development/interpreters/python/pypy/prebuilt.nix
@@ -6,8 +6,9 @@
 , which
 # Dependencies
 , bzip2
+, sqlite
 , zlib
-, openssl_1_0_2
+, openssl
 , expat
 , ncurses6
 , tcl-8_5
@@ -27,12 +28,12 @@ with lib;
 
 let
   isPy3k = majorVersion == "3";
-  passthru = passthruFun {
+  passthru = passthruFun rec {
     inherit self sourceVersion pythonVersion packageOverrides;
     implementation = "pypy";
     libPrefix = "pypy${pythonVersion}";
     executable = "pypy${if isPy3k then "3" else ""}";
-    sitePackages = "site-packages";
+    sitePackages = "lib/${libPrefix}/site-packages";
     hasDistutilsCxxPatch = false;
 
     # Not possible to cross-compile with.
@@ -49,8 +50,9 @@ let
 
   deps = [
     bzip2
+    sqlite
     zlib
-    openssl_1_0_2
+    openssl
     expat
     ncurses6
     tcl-8_5
@@ -68,10 +70,9 @@ in with passthru; stdenv.mkDerivation {
   buildInputs = [ which ];
 
   installPhase = ''
-    mkdir -p $out/lib
+    mkdir -p $out
     echo "Moving files to $out"
-    mv -t $out bin include lib-python lib_pypy site-packages
-    mv lib/libffi.so.6* $out/lib/
+    mv -t $out bin include lib
 
     mv $out/bin/libpypy*-c.so $out/lib/
 
@@ -84,8 +85,9 @@ in with passthru; stdenv.mkDerivation {
              $out/bin/pypy*
 
     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 ${lib.makeLibraryPath deps}:$out/lib {} \;
+
+    find ./lib -name "*.so" -exec patchelf --remove-needed libncursesw.so.6 --replace-needed libtinfow.so.6 libncursesw.so.6 {} \;
+    find ./lib -name "*.so" -exec patchelf --set-rpath ${lib.makeLibraryPath deps}:$out/lib {} \;
 
     echo "Removing bytecode"
     find . -name "__pycache__" -type d -depth -exec rm -rf {} \;
diff --git a/pkgs/development/interpreters/python/pypy/prebuilt_2_7.nix b/pkgs/development/interpreters/python/pypy/prebuilt_2_7.nix
new file mode 100644
index 0000000000000..460af1cc67b4f
--- /dev/null
+++ b/pkgs/development/interpreters/python/pypy/prebuilt_2_7.nix
@@ -0,0 +1,132 @@
+{ lib
+, stdenv
+, fetchurl
+, python-setup-hook
+, self
+, which
+# Dependencies
+, bzip2
+, zlib
+, openssl_1_0_2
+, expat
+, ncurses6
+, tcl-8_5
+, tk-8_5
+# For the Python package set
+, packageOverrides ? (self: super: {})
+, sourceVersion
+, pythonVersion
+, sha256
+, passthruFun
+}:
+
+# This version of PyPy is primarily added to speed-up translation of
+# our PyPy source build when developing that expression.
+
+with lib;
+
+let
+  isPy3k = majorVersion == "3";
+  passthru = passthruFun {
+    inherit self sourceVersion pythonVersion packageOverrides;
+    implementation = "pypy";
+    libPrefix = "pypy${pythonVersion}";
+    executable = "pypy${if isPy3k then "3" else ""}";
+    sitePackages = "site-packages";
+    hasDistutilsCxxPatch = false;
+
+    # Not possible to cross-compile with.
+    pythonOnBuildForBuild = throw "${pname} does not support cross compilation";
+    pythonOnBuildForHost = self;
+    pythonOnBuildForTarget = throw "${pname} does not support cross compilation";
+    pythonOnHostForHost = throw "${pname} does not support cross compilation";
+    pythonOnTargetForTarget = throw "${pname} does not support cross compilation";
+  };
+  pname = "${passthru.executable}_prebuilt";
+  version = with sourceVersion; "${major}.${minor}.${patch}";
+
+  majorVersion = substring 0 1 pythonVersion;
+
+  deps = [
+    bzip2
+    zlib
+    openssl_1_0_2
+    expat
+    ncurses6
+    tcl-8_5
+    tk-8_5
+  ];
+
+in with passthru; stdenv.mkDerivation {
+  inherit pname version;
+
+  src = fetchurl {
+    url = "https://downloads.python.org/pypy/pypy${pythonVersion}-v${version}-linux64.tar.bz2";
+    inherit sha256;
+  };
+
+  buildInputs = [ which ];
+
+  installPhase = ''
+    mkdir -p $out/lib
+    echo "Moving files to $out"
+    mv -t $out bin include lib-python lib_pypy site-packages
+    mv lib/libffi.so.6* $out/lib/
+
+    mv $out/bin/libpypy*-c.so $out/lib/
+
+    rm $out/bin/*.debug
+
+    echo "Patching binaries"
+    interpreter=$(patchelf --print-interpreter $(readlink -f $(which patchelf)))
+    patchelf --set-interpreter $interpreter \
+             --set-rpath $out/lib \
+             $out/bin/pypy*
+
+    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 ${lib.makeLibraryPath deps}:$out/lib {} \;
+
+    echo "Removing bytecode"
+    find . -name "__pycache__" -type d -depth -exec rm -rf {} \;
+    popd
+
+    # Include a sitecustomize.py file
+    cp ${../sitecustomize.py} $out/${sitePackages}/sitecustomize.py
+
+  '';
+
+  doInstallCheck = true;
+
+  # Check whether importing of (extension) modules functions
+  installCheckPhase = let
+    modules = [
+      "ssl"
+      "sys"
+      "curses"
+    ] ++ optionals (!isPy3k) [
+      "Tkinter"
+    ] ++ optionals isPy3k [
+      "tkinter"
+    ];
+    imports = concatMapStringsSep "; " (x: "import ${x}") modules;
+  in ''
+    echo "Testing whether we can import modules"
+    $out/bin/${executable} -c '${imports}'
+  '';
+
+  setupHook = python-setup-hook sitePackages;
+
+  donPatchElf = true;
+  dontStrip = true;
+
+  inherit passthru;
+
+  meta = with lib; {
+    homepage = "http://pypy.org/";
+    description = "Fast, compliant alternative implementation of the Python language (${pythonVersion})";
+    license = licenses.mit;
+    platforms = [ "x86_64-linux" ];
+  };
+
+}
diff --git a/pkgs/development/interpreters/python/update-python-libraries/update-python-libraries.py b/pkgs/development/interpreters/python/update-python-libraries/update-python-libraries.py
index 3a6a14133ea37..5f55ed5ecaf1a 100755
--- a/pkgs/development/interpreters/python/update-python-libraries/update-python-libraries.py
+++ b/pkgs/development/interpreters/python/update-python-libraries/update-python-libraries.py
@@ -242,7 +242,9 @@ DEFAULT_SETUPTOOLS_EXTENSION = 'tar.gz'
 
 FORMATS = {
     'setuptools'        :   DEFAULT_SETUPTOOLS_EXTENSION,
-    'wheel'             :   'whl'
+    'wheel'             :   'whl',
+    'pyproject'         :   'tar.gz',
+    'flit'              :   'tar.gz'
 }
 
 def _determine_fetcher(text):
@@ -281,12 +283,8 @@ def _determine_extension(text, fetcher):
         if extension is None:
             if src_format is None:
                 src_format = 'setuptools'
-            elif src_format == 'flit':
-                raise ValueError("Don't know how to update a Flit package.")
             elif src_format == 'other':
                 raise ValueError("Don't know how to update a format='other' package.")
-            elif src_format == 'pyproject':
-                raise ValueError("Don't know how to update a pyproject package.")
             extension = FORMATS[src_format]
 
     elif fetcher == 'fetchurl':
@@ -342,19 +340,35 @@ def _update_package(path, target):
         raise ValueError("no file available for {}.".format(pname))
 
     text = _replace_value('version', new_version, text)
+    # hashes from pypi are 16-bit encoded sha256's, normalize it to sri to avoid merge conflicts
+    # sri hashes have been the default format since nix 2.4+
+    try:
+        sri_hash = subprocess.check_output(["nix", "hash", "to-sri", "--type", "sha256", new_sha256]).decode('utf-8').strip()
+    except subprocess.CalledProcessError:
+        # nix<2.4 compat
+        sri_hash = subprocess.check_output(["nix", "to-sri", "--type", "sha256", new_sha256]).decode('utf-8').strip()
+
 
     # fetchers can specify a sha256, or a sri hash
     try:
-        text = _replace_value('sha256', new_sha256, text)
+        text = _replace_value('sha256', sri_hash, text)
     except ValueError:
-        # hashes from pypi are 16-bit encoded sha256's, need translate to an sri hash if used with "hash"
-        sri_hash = subprocess.check_output(["nix", "hash", "to-sri", "--type", "sha256", new_sha256]).decode('utf-8').strip()
         text = _replace_value('hash', sri_hash, text)
 
     if fetcher == 'fetchFromGitHub':
-        text = _replace_value('rev', f"{prefix}${{version}}", text)
-        # incase there's no prefix, just rewrite without interpolation
-        text = text.replace('"${version}";', 'version;')
+        # in the case of fetchFromGitHub, it's common to see `rev = version;`
+        # in which no string value is meant to be substituted.
+        # Verify that the attribute is set to a variable
+        regex = '(rev\s+=\s+([_a-zA-Z][_a-zA-Z0-9\.]*);)'
+        regex = re.compile(regex)
+        value = regex.findall(text)
+        n = len(value)
+
+        if n == 0:
+            # value is set to a string, e.g. `rev = "v${version}";`
+            text = _replace_value('rev', f"{prefix}${{version}}", text)
+            # incase there's no prefix, just rewrite without interpolation
+            text = text.replace('"${version}";', 'version;')
 
     with open(path, 'w') as f:
         f.write(text)