<commit_before>#!/bin/bash
# -*-mode: Shell-script; indent-tabs-mode: nil; sh-basic-offset: 2 -*-

# Find the base directory while avoiding subtle variations in $0:
dollar0=`which $0`; PACKAGE_DIR=$(cd $(dirname $dollar0); pwd) # NEVER export PACKAGE_DIR

# Set defaults for BUILD_DIR and INSTALL_DIR environment variables and
# define utility functions such as BuildDependentPackage:
. $PACKAGE_DIR/../../../support-files/build_platform_util.bash

# --------------------------------------------------------------------------------
# Usage
# --------------------------------------------------------------------------------
MAJOR_VERSION=2
usage () {
  cat <<EOF
USAGE: $0 ... options ...

Options are:

[ -builddir BUILD_DIR ]

  Override the BUILD_DIR default, which is $BUILD_DIR.

[ -installdir INSTALL_DIR ]

  Override the INSTALL_DIR default, which is $INSTALL_DIR.

[ -clean ]

  Build from scratch.

[ -majorversion MAJOR_VERSION ]

  Build the version of Python whose major version is given by
  MAJOR_VERSION. MAJOR_VERSION defaults to "$MAJOR_VERSION"

EOF

}

CLEAN=0
while [ $# -gt 0 ]
do
  if [ "$1" = "-builddir" ]
  then
    BUILD_DIR="$2"
    shift
  elif [ "$1" = "-installdir" ]
  then
    INSTALL_DIR="$2"
    shift
  elif [ "$1" = "-majorversion" ]
  then
    MAJOR_VERSION="$2"
    shift
  elif [ "$1" = "-clean" ]
  then
    CLEAN=1
  elif [ "$1" = "-h" ]
  then
    usage
    exit 0
  else
    echo "Undefined parameter $1"
    exit 1
  fi
  shift
done

# --------------------------------------------------------------------------------
# Create build directory structure:
# --------------------------------------------------------------------------------
CreateAndChdirIntoBuildDir python

# --------------------------------------------------------------------------------
# Download the source into the build directory:
# --------------------------------------------------------------------------------
echo "Downloading ..."
version=$(wget -O - "http://www.python.org/download/releases/" \
  | sed -n 's%^.*href="\([0-9.]*\)".*$%\1%gp' \
  | sort -t. -k1,1n -k2,2n -k3.3n \
  | grep "^${MAJOR_VERSION}\." \
  | tail -1)
if [ -z "$version" ]
then
  echo "ERROR: Cannot download major version $MAJOR_VERSION of Python"
  exit 1
fi
echo "Note: Found latest major version $MAJOR_VERSION version of $version"
version_subdir="Python-${version}"
tarballBase="$version_subdir.tgz"
if [ "$CLEAN" = 1 ]
then
  PrintRun rm -rf "$version_subdir"
fi
if [ ! -d "$version_subdir" ]
then
  tarballURL="http://www.python.org/ftp/python/${version}/$tarballBase"
  if [ ! -f $tarballBase ]
  then
    PrintRun wget -O $tarballBase $tarballURL<commit_msg>Insure bz is installed into Python by default. This is needed for pip to work properly.  Besides, bzip functionality is pretty basic functionality and should have been in Python to begin with.<commit_after>#!/bin/bash
# -*-mode: Shell-script; indent-tabs-mode: nil; sh-basic-offset: 2 -*-

# Find the base directory while avoiding subtle variations in $0:
dollar0=`which $0`; PACKAGE_DIR=$(cd $(dirname $dollar0); pwd) # NEVER export PACKAGE_DIR

# Set defaults for BUILD_DIR and INSTALL_DIR environment variables and
# define utility functions such as BuildDependentPackage:
. $PACKAGE_DIR/../../../support-files/build_platform_util.bash

# --------------------------------------------------------------------------------
# Usage
# --------------------------------------------------------------------------------
MAJOR_VERSION=2
usage () {
  cat <<EOF
USAGE: $0 ... options ...

Options are:

[ -builddir BUILD_DIR ]

  Override the BUILD_DIR default, which is $BUILD_DIR.

[ -installdir INSTALL_DIR ]

  Override the INSTALL_DIR default, which is $INSTALL_DIR.

[ -clean ]

  Build from scratch.

[ -majorversion MAJOR_VERSION ]

  Build the version of Python whose major version is given by
  MAJOR_VERSION. MAJOR_VERSION defaults to "$MAJOR_VERSION"

EOF

}

CLEAN=0
while [ $# -gt 0 ]
do
  if [ "$1" = "-builddir" ]
  then
    BUILD_DIR="$2"
    shift
  elif [ "$1" = "-installdir" ]
  then
    INSTALL_DIR="$2"
    shift
  elif [ "$1" = "-majorversion" ]
  then
    MAJOR_VERSION="$2"
    shift
  elif [ "$1" = "-clean" ]
  then
    CLEAN=1
  elif [ "$1" = "-h" ]
  then
    usage
    exit 0
  else
    echo "Undefined parameter $1"
    exit 1
  fi
  shift
done

# --------------------------------------------------------------------------------
# Create build directory structure:
# --------------------------------------------------------------------------------
CreateAndChdirIntoBuildDir python

# --------------------------------------------------------------------------------
# Get dependent packages:
# --------------------------------------------------------------------------------
VerifyOperatingSystemPackageContainingFile Debian libbz2-dev /usr/include/bzlib.h

# --------------------------------------------------------------------------------
# Download the source into the build directory:
# --------------------------------------------------------------------------------
echo "Downloading ..."
version=$(wget -O - "http://www.python.org/download/releases/" \
  | sed -n 's%^.*href="\([0-9.]*\)".*$%\1%gp' \
  | sort -t. -k1,1n -k2,2n -k3.3n \
  | grep "^${MAJOR_VERSION}\." \
  | tail -1)
if [ -z "$version" ]
then
  echo "ERROR: Cannot download major version $MAJOR_VERSION of Python"
  exit 1
fi
echo "Note: Found latest major version $MAJOR_VERSION version of $version"
version_subdir="Python-${version}"
tarballBase="$version_subdir.tgz"
if [ "$CLEAN" = 1 ]
then
  PrintRun rm -rf "$version_subdir"
fi
if [ ! -d "$version_subdir" ]
then
  tarballURL="http://www.python.org/ftp/python/${version}/$tarballBase"
  if [ ! -f $tarballBase ]
  then
    PrintRun wget -O $tarballBase $tarballURL
{'fraction_non_alphanumeric': 0.30546902042229146, 'fraction_numerical': 0.0115957078573901, 'mean_word_length': 1.6388127853881278, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 4, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 8, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '224426', 'n_tokens_mistral': 1741, 'n_tokens_neox': 1668, 'n_words': 477}