<commit_before># /ciscripts/setup/project/configure_python.py
#
# A script which configures and activates a python installation
#
# See /LICENCE.md for Copyright information
"""A script which configures and activates a python installation."""

import errno

import fnmatch

import os
import os.path

import platform

from collections import defaultdict

from contextlib import closing


def _usable_preinstalled_python(container, version):
    """Return any pre-installed python matching version that we can use."""
    py_util = container.fetch_and_import("python_util.py")
    preinstalled_pythons = py_util.discover_pythons()
    requested_components = version.count(".") + 1

    for candidate_version, candidate_path in preinstalled_pythons.items():
        cand = ".".join(candidate_version.split(".")[:requested_components])
        if cand == version:
            return candidate_path


def get(container, util, shell, ver_info):
    """Return a PythonContainer for an installed python in container."""
    del util

    version = ver_info[platform.system()]
    container_path = os.path.join(container.language_dir("python"),
                                  version)

    # This class is intended to be used through LanguageBase, so
    # most of its methods are private
    #
    # suppress(too-few-public-methods)
    class PythonContainer(container.new_container_for("python", version)):

        """A container representing an active python installation."""

        # pylint can't detect that this is a new-style class
        #
        # suppress(super-on-old-class)
        def __init__(self, version, installation, shell):
            """Initialize a python container for this version."""
            super(PythonContainer, self).__init__(installation,
                                                  "python",
                                                  version,
                                                  shell)

            self._version = version
            assert os.path.exists(self._installation)

        @staticmethod
        def _get_py_path_from(installation):
            """Given an installation, get the python library dir."""
            if platform.system() in ("Linux", "Darwin"):
                lib_subdirectory = "lib"
                py_lib = os.path.join(installation, lib_subdirectory)
                py_path = fnmatch.filter(os.listdir(py_lib), "python*")

                assert len(py_path) == 1
                return os.path.join(py_lib, py_path[0])
            elif platform.system() in ("Windows", ):
                lib_subdirectory = "Lib"
                return os.path.join(installation, lib_subdirectory)

            return None

        @staticmethod
        def _get_exec_path_from(installation):
            """Given an installation, get python binary path.

            This may have more than one component, depending on
            the platform specified.
            """
            if platform.system() in ("Linux", "Darwin"):<commit_msg>configure_python: Complain when installation doesn't exist<commit_after># /ciscripts/setup/project/configure_python.py
#
# A script which configures and activates a python installation
#
# See /LICENCE.md for Copyright information
"""A script which configures and activates a python installation."""

import errno

import fnmatch

import os
import os.path

import platform

from collections import defaultdict

from contextlib import closing


def _usable_preinstalled_python(container, version):
    """Return any pre-installed python matching version that we can use."""
    py_util = container.fetch_and_import("python_util.py")
    preinstalled_pythons = py_util.discover_pythons()
    requested_components = version.count(".") + 1

    for candidate_version, candidate_path in preinstalled_pythons.items():
        cand = ".".join(candidate_version.split(".")[:requested_components])
        if cand == version:
            return candidate_path


def get(container, util, shell, ver_info):
    """Return a PythonContainer for an installed python in container."""
    del util

    version = ver_info[platform.system()]
    container_path = os.path.join(container.language_dir("python"),
                                  version)

    # This class is intended to be used through LanguageBase, so
    # most of its methods are private
    #
    # suppress(too-few-public-methods)
    class PythonContainer(container.new_container_for("python", version)):

        """A container representing an active python installation."""

        # pylint can't detect that this is a new-style class
        #
        # suppress(super-on-old-class)
        def __init__(self, version, installation, shell):
            """Initialize a python container for this version."""
            super(PythonContainer, self).__init__(installation,
                                                  "python",
                                                  version,
                                                  shell)

            self._version = version
            assert os.path.exists(self._installation)

        @staticmethod
        def _get_py_path_from(installation):
            """Given an installation, get the python library dir."""
            if not os.path.exists(installation):
                raise RuntimeError("""Python installation {} """
                                   """does not exist""".format(installation))

            if platform.system() in ("Linux", "Darwin"):
                lib_subdirectory = "lib"
                py_lib = os.path.join(installation, lib_subdirectory)
                py_path = fnmatch.filter(os.listdir(py_lib), "python*")

                assert len(py_path) == 1
                return os.path.join(py_lib, py_path[0])
            elif platform.system() in ("Windows", ):
                lib_subdirectory = "Lib"
                return os.path.join(installation, lib_subdirectory)

            return None

        @staticmethod
        def _get_exec_path_from(installation):
            """Given an installation, get python binary path.

            This may have more than one component, depending on
            the platform specified.
            """
            if platform.system() in ("Linux", "Darwin"):
{'fraction_non_alphanumeric': 0.09050350541746335, 'fraction_numerical': 0.0009560229445506692, 'mean_word_length': 2.2222792607802875, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 15, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1777983', 'n_tokens_mistral': 1586, 'n_tokens_neox': 1510, 'n_words': 457}