<commit_before>{ stdenv, fetchurl, zlib ? null, zlibSupport ? true, bzip2
, sqlite, tcl, tk, x11, openssl, readline, db, ncurses, gdbm, libX11 }:

assert zlibSupport -> zlib != null;

with stdenv.lib;

let

  majorVersion = "2.7";
  version = "${majorVersion}.8";

  src = fetchurl {
    url = "http://www.python.org/ftp/python/${version}/Python-${version}.tar.xz";
    sha256 = "0nh7d3dp75f1aj0pamn4hla8s0l7nbaq4a38brry453xrfh11ppd";
  };

  patches =
    [ # Look in C_INCLUDE_PATH and LIBRARY_PATH for stuff.
      ./search-path.patch

      # Python recompiles a Python if the mtime stored *in* the
      # pyc/pyo file differs from the mtime of the source file.  This
      # doesn't work in Nix because Nix changes the mtime of files in
      # the Nix store to 1.  So treat that as a special case.
      ./nix-store-mtime.patch

      # patch python to put zero timestamp into pyc
      # if DETERMINISTIC_BUILD env var is set
      ./deterministic-build.patch
    ];

  postPatch = stdenv.lib.optionalString (stdenv.gcc.libc != null) ''
    substituteInPlace ./Lib/plat-generic/regen \
                      --replace /usr/include/netinet/in.h \
                                ${stdenv.gcc.libc}/include/netinet/in.h
  '';

  buildInputs =
    optional (stdenv ? gcc && stdenv.gcc.libc != null) stdenv.gcc.libc ++
    [ bzip2 openssl ]
    ++ optional zlibSupport zlib;

  ensurePurity =
    ''
      # Purity.
      for i in /usr /sw /opt /pkg; do
        substituteInPlace ./setup.py --replace $i /no-such-path
      done
    '';

  # Build the basic Python interpreter without modules that have
  # external dependencies.
  python = stdenv.mkDerivation {
    name = "python-${version}";

    inherit majorVersion version src patches postPatch buildInputs;

    C_INCLUDE_PATH = concatStringsSep ":" (map (p: "${p}/include") buildInputs);
    LIBRARY_PATH = concatStringsSep ":" (map (p: "${p}/lib") buildInputs);

    configureFlags = "--enable-shared --with-threads --enable-unicode";

    preConfigure = "${ensurePurity}" + optionalString stdenv.isCygwin
      ''
        # On Cygwin, `make install' tries to read this Makefile.
        mkdir -p $out/lib/python${majorVersion}/config<commit_msg>python: link gcc_s<commit_after>{ stdenv, fetchurl, zlib ? null, zlibSupport ? true, bzip2
, sqlite, tcl, tk, x11, openssl, readline, db, ncurses, gdbm, libX11 }:

assert zlibSupport -> zlib != null;

with stdenv.lib;

let

  majorVersion = "2.7";
  version = "${majorVersion}.8";

  src = fetchurl {
    url = "http://www.python.org/ftp/python/${version}/Python-${version}.tar.xz";
    sha256 = "0nh7d3dp75f1aj0pamn4hla8s0l7nbaq4a38brry453xrfh11ppd";
  };

  patches =
    [ # Look in C_INCLUDE_PATH and LIBRARY_PATH for stuff.
      ./search-path.patch

      # Python recompiles a Python if the mtime stored *in* the
      # pyc/pyo file differs from the mtime of the source file.  This
      # doesn't work in Nix because Nix changes the mtime of files in
      # the Nix store to 1.  So treat that as a special case.
      ./nix-store-mtime.patch

      # patch python to put zero timestamp into pyc
      # if DETERMINISTIC_BUILD env var is set
      ./deterministic-build.patch
    ];

  postPatch = stdenv.lib.optionalString (stdenv.gcc.libc != null) ''
    substituteInPlace ./Lib/plat-generic/regen \
                      --replace /usr/include/netinet/in.h \
                                ${stdenv.gcc.libc}/include/netinet/in.h
  '';

  buildInputs =
    optional (stdenv ? gcc && stdenv.gcc.libc != null) stdenv.gcc.libc ++
    [ bzip2 openssl ]
    ++ optional zlibSupport zlib;

  ensurePurity =
    ''
      # Purity.
      for i in /usr /sw /opt /pkg; do
        substituteInPlace ./setup.py --replace $i /no-such-path
      done
    '';

  # Build the basic Python interpreter without modules that have
  # external dependencies.
  python = stdenv.mkDerivation {
    name = "python-${version}";

    inherit majorVersion version src patches postPatch buildInputs;

    LDFLAGS = stdenv.lib.optionalString (!stdenv.isDarwin) "-lgcc_s";
    C_INCLUDE_PATH = concatStringsSep ":" (map (p: "${p}/include") buildInputs);
    LIBRARY_PATH = concatStringsSep ":" (map (p: "${p}/lib") buildInputs);

    configureFlags = "--enable-shared --with-threads --enable-unicode";

    preConfigure = "${ensurePurity}" + optionalString stdenv.isCygwin
      ''
        # On Cygwin, `make install' tries to read this Makefile.
        mkdir -p $out/lib/python${majorVersion}/config
{'fraction_non_alphanumeric': 0.12063209436901848, 'fraction_numerical': 0.01424438014689517, 'mean_word_length': 2.6596091205211727, 'pattern_counts': {'":': 4, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '671681', 'n_tokens_mistral': 1587, 'n_tokens_neox': 1493, 'n_words': 397}