<commit_before>""" Learn basic capabilities here (e.g. can we display graphics?).
This is meant to be fast and light, having no complicated dependencies, so
that any module can fearlessly import this without adverse affects or
performance concerns.

$Id$
"""

from __future__ import division # confidence high

import os, sys
PY3K = sys.version_info[0] > 2


def is_darwin_and_x():
    """ Convenience function.  Returns True if is an X11-linked Python/Tkinter
    build on OSX.  This is intended to be quick and easy without further
    imports.  As a result, this relies on the assumption that on OSX, PyObjC
    is installed (only) in the Framework builds of Python. """
    if not sys.platform == 'darwin':
        return False

    return which_darwin_linkage() == "x11"


def which_darwin_linkage(force_otool_check=False):
    """ Convenience function.  Returns one of ('x11', 'aqua') in answer to the
    question of whether this is an X11-linked Python/Tkinter, or a natively
    built (framework, Aqua) one.  This is only for OSX.
    On Python 2.*, this relies on the assumption that on OSX, PyObjC
    is installed only in the Framework builds of Python.  On Python 3.*,
    this inspects the actual tkinter library binary via otool. """

    # sanity check
    assert sys.platform=='darwin', 'Incorrect usaage, not on OSX'

    # There will *usually* be PyObjC modules on sys.path on the natively-
    # linked Python. This is assumed to be always correct on Python 2.x, as
    # of 2012.  This is kludgy but quick and effective.
    if not force_otool_check:
        junk = ",".join(sys.path)
        if junk.lower().find('/pyobjc') >= 0:
            return "aqua"

    # OK, no PyObjC found.  What we do next is different per Python ver.
    if not PY3K and not force_otool_check:
        return "x11"

    # Is PY3K, use otool shell command (requires 2.7+)
    import Tkinter, subprocess
    libs = subprocess.check_output(('/usr/bin/otool', '-L', Tkinter._tkinter.__file__)).decode()
    if libs.find('/libX11.') >= 0:
        return "x11"
    else:
        return "aqua"


OF_GRAPHICS = True

if 'PYRAF_NO_DISPLAY' in os.environ or 'PYTOOLS_NO_DISPLAY' in os.environ:
    OF_GRAPHICS = False

if OF_GRAPHICS and sys.platform == 'darwin':
    #<commit_msg>typo fix<commit_after>""" Learn basic capabilities here (e.g. can we display graphics?).
This is meant to be fast and light, having no complicated dependencies, so
that any module can fearlessly import this without adverse affects or
performance concerns.

$Id$
"""

from __future__ import division # confidence high

import os, sys
PY3K = sys.version_info[0] > 2


def is_darwin_and_x():
    """ Convenience function.  Returns True if is an X11-linked Python/Tkinter
    build on OSX.  This is intended to be quick and easy without further
    imports.  As a result, this relies on the assumption that on OSX, PyObjC
    is installed (only) in the Framework builds of Python. """
    if not sys.platform == 'darwin':
        return False

    return which_darwin_linkage() == "x11"


def which_darwin_linkage(force_otool_check=False):
    """ Convenience function.  Returns one of ('x11', 'aqua') in answer to the
    question of whether this is an X11-linked Python/Tkinter, or a natively
    built (framework, Aqua) one.  This is only for OSX.
    On Python 2.*, this relies on the assumption that on OSX, PyObjC
    is installed only in the Framework builds of Python.  On Python 3.*,
    this inspects the actual tkinter library binary via otool. """

    # sanity check
    assert sys.platform=='darwin', 'Incorrect usage, not on OSX'

    # There will *usually* be PyObjC modules on sys.path on the natively-
    # linked Python. This is assumed to be always correct on Python 2.x, as
    # of 2012.  This is kludgy but quick and effective.
    if not force_otool_check:
        junk = ",".join(sys.path)
        if junk.lower().find('/pyobjc') >= 0:
            return "aqua"

    # OK, no PyObjC found.  What we do next is different per Python ver.
    if not PY3K and not force_otool_check:
        return "x11"

    # Is PY3K, use otool shell command (requires 2.7+)
    import Tkinter, subprocess
    libs = subprocess.check_output(('/usr/bin/otool', '-L', Tkinter._tkinter.__file__)).decode()
    if libs.find('/libX11.') >= 0:
        return "x11"
    else:
        return "aqua"


OF_GRAPHICS = True

if 'PYRAF_NO_DISPLAY' in os.environ or 'PYTOOLS_NO_DISPLAY' in os.environ:
    OF_GRAPHICS = False

if OF_GRAPHICS and sys.platform == 'darwin':
    #
{'fraction_non_alphanumeric': 0.08990744821507272, 'fraction_numerical': 0.013221683561040106, 'mean_word_length': 3.133879781420765, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, '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': '1750725', 'n_tokens_mistral': 1493, 'n_tokens_neox': 1408, 'n_words': 567}