Exemple #1
0
def tox_addoption(parser):
    if 'TRAVIS' not in os.environ:
        return

    version = os.environ.get('TRAVIS_PYTHON_VERSION')

    config = py.iniconfig.IniConfig('tox.ini')
    travis_section = config.sections.get('tox:travis', {})
    tox_section = config.sections.get('tox', {})

    # Find the envs that tox knows about
    envlist = split_env(tox_section.get('envlist', []))

    # Find and expand the requested envs
    envstr = travis_section.get(version, TOX_DEFAULTS.get(version))
    desired_envlist = split_env(envstr)

    matched = [
        env for env in envlist if any(
            env_matches(env, desired_env)
            for desired_env in desired_envlist
        )
    ]

    # If no envs match, just use the desired envstr directly
    if not matched:
        matched = [envstr]

    os.environ.setdefault('TOXENV', ','.join(matched))
Exemple #2
0
def after_config_matches(ini, envlist):
    """Determine if this job should wait for the others."""
    section = ini.sections.get('travis:after', {})

    if not section:
        return False  # Never wait if it's not configured

    if 'envlist' in section or 'toxenv' in section:
        if 'toxenv' in section:
            print('The "toxenv" key of the [travis:after] section is '
                  'deprecated in favor of the "envlist" key.', file=sys.stderr)

        toxenv = section.get('toxenv')
        required = set(split_env(section.get('envlist', toxenv) or ''))
        actual = set(envlist)
        if required - actual:
            return False

    # Translate travis requirements to env requirements
    env_requirements = [
        (TRAVIS_FACTORS[factor], value) for factor, value
        in parse_dict(section.get('travis', '')).items()
        if factor in TRAVIS_FACTORS
    ] + [
        (name, value) for name, value
        in parse_dict(section.get('env', '')).items()
    ]

    return all([
        os.environ.get(name) == value
        for name, value in env_requirements
    ])
Exemple #3
0
def tox_addoption(parser):
    if 'TRAVIS' not in os.environ:
        return

    version = os.environ.get('TRAVIS_PYTHON_VERSION')

    config = py.iniconfig.IniConfig('tox.ini')
    travis_section = config.sections.get('tox:travis', {})
    tox_section = config.sections.get('tox', {})

    # Find the envs that tox knows about
    envlist = split_env(tox_section.get('envlist', []))
    envlist_set = set(envlist)
    envlist.extend(
        s[8:] for s in sorted(config.sections, key=config.lineof)
        if s.startswith('testenv:')
        and s[8:] not in envlist_set)

    # Find and expand the requested envs
    envstr = travis_section.get(version, TOX_DEFAULTS.get(version))
    desired_envlist = split_env(envstr)

    matched = []
    matchmakers = set()
    for env in envlist:
        match = False
        for desired_env in desired_envlist:
            if env_matches(env, desired_env):
                match = True
                matchmakers.add(desired_env)
        if match:
            matched.append(env)

    # Add desired envs which yielded no match with the envlist
    matched.extend(env for env in desired_envlist
                   if env not in matchmakers)

    os.environ.setdefault('TOXENV', ','.join(matched))
Exemple #4
0
def get_declared_envs(config):
    """Get the full list of envs from the tox config.

    This notably also includes envs that aren't in the envlist,
    but are declared by having their own testenv:envname section.

    The envs are expected in a particular order. First the ones
    declared in the envlist, then the other testenvs in order.
    """
    tox_section = config.sections.get('tox', {})
    envlist = split_env(tox_section.get('envlist', []))

    # Add additional envs that are declared as sections in the config
    section_envs = [
        section[8:] for section in sorted(config.sections, key=config.lineof)
        if section.startswith('testenv:')
    ]

    return envlist + [env for env in section_envs if env not in envlist]
Exemple #5
0
def get_desired_envs(config, version):
    """Get the expanded list of desired envs."""
    travis_section = config.sections.get('tox:travis', {})
    default_envlist = get_default_envlist(version)
    return split_env(travis_section.get(version, default_envlist))
def get_desired_envs(config, version):
    """Get the expanded list of desired envs."""
    travis_section = config.sections.get('tox:travis', {})
    return split_env(travis_section.get(version, guess_python_env()))
Exemple #7
0
def get_desired_factors(ini):
    """Get the list of desired envs per declared factor.

    Look at all the accepted configuration locations, and give a list
    of envlists, one for each Travis factor found.

    Look in the ``[travis]`` section for the known Travis factors,
    which are backed by environment variable checking behind the
    scenes, but provide a cleaner interface.

    Also look for the ``[tox:travis]`` section, which is deprecated,
    and treat it as an additional ``python`` key from the ``[travis]``
    section.

    Finally, look for factors based directly on environment variables,
    listed in the ``[travis:env]`` section. Configuration found in the
    ``[travis]`` and ``[tox:travis]`` sections are converted to this
    form under the hood, and are considered in the same way.

    Special consideration is given to the ``python`` factor. If this
    factor is set in the environment, then an appropriate configuration
    will be provided automatically if no manual configuration is
    provided.

    To allow for the most flexible processing, the envlists provided
    by each factor are not combined after they are selected, but
    instead returned as a list of envlists, and expected to be
    combined as and when appropriate by the caller. This allows for
    special handling based on the number of factors that were found
    to apply to this environment.
    """
    # Find configuration based on known travis factors
    travis_section = ini.sections.get('travis', {})
    found_factors = [(factor, parse_dict(travis_section[factor]))
                     for factor in TRAVIS_FACTORS if factor in travis_section]

    # Backward compatibility with the old tox:travis section
    if 'tox:travis' in ini.sections:
        print(
            'The [tox:travis] section is deprecated in favor of'
            ' the "python" key of the [travis] section.',
            file=sys.stderr)
        found_factors.append(('python', ini.sections['tox:travis']))

    # Inject any needed autoenv
    version = os.environ.get('TRAVIS_PYTHON_VERSION')
    if version:
        default_envlist = get_default_envlist(version)
        if not any(factor == 'python' for factor, _ in found_factors):
            found_factors.insert(0, ('python', {version: default_envlist}))
        python_factors = [(factor, mapping)
                          for factor, mapping in found_factors
                          if version and factor == 'python']
        for _, mapping in python_factors:
            mapping.setdefault(version, default_envlist)

    # Convert known travis factors to env factors,
    # and combine with declared env factors.
    env_factors = [
        (TRAVIS_FACTORS[factor], mapping) for factor, mapping in found_factors
    ] + [(name, parse_dict(value))
         for name, value in ini.sections.get('travis:env', {}).items()]

    # Choose the correct envlists based on the factor values
    return [
        split_env(mapping[os.environ[name]]) for name, mapping in env_factors
        if name in os.environ and os.environ[name] in mapping
    ]
Exemple #8
0
def _add_to_each(s, factors, position=AFTER):
    items = split_env(s)
    items = [position(item, factors) for item in items]
    return ",".join(items)
Exemple #9
0
def get_desired_envs(config, version):
    """Get the expanded list of desired envs."""
    travis_section = config.sections.get('tox:travis', {})
    default_envlist = get_default_envlist(version)
    return split_env(travis_section.get(version, default_envlist))