"""
Enable this feature if the optimized code will be executed by the same Python
binary: so exactly the same Python version with the same build options.

Allow to optimize non-BMP unicode strings on Python < 3.3.

See also pythonenv feature if you control the full environment.
"""
from astoptimizer.config import Function
import platform
import sys

def setup_config(config):
    config.enable('platform')

    # When pythonbin feature is enabled, non-BMP strings (ex: "\U0010ffff") are
    # also optimized: chr(), ord(), str.encode(), etc.

    # Python version
    config.add_constant('sys.hexversion', sys.hexversion)
    config.add_constant('sys.version', sys.version)
    if sys.platform == 'win32':
        config.add_constant('sys.winver', sys.winver)
    if sys.version_info >= (2, 7):
        for attr in ('major', 'minor', 'micro', 'releaselevel', 'serial'):
            value = getattr(sys.version_info, attr)
            config.add_constant('sys.version_info.%s' % attr, value)
    else:
        config.add_constant('sys.version_info', sys.version_info)

    config.add_func('platform.python_version',
                    Function(platform.python_version, 0))
    config.add_func('platform.python_version_tuple',
                    Function(platform.python_version_tuple, 0))

    # Build options
    config.add_constant('sys.maxunicode', sys.maxunicode)
    if hasattr(sys, 'abiflags'):
        # sys.abiflags was added to Python 3.2
        config.add_constant('sys.abiflags', sys.abiflags)
    if hasattr(sys, 'maxsize'):
        # Python < 2.6 doesn't have sys.maxsize
        config.max_size = sys.maxsize



