Skip to content
This repository was archived by the owner on Nov 19, 2024. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ def default_environment():
entry_points={
'tox': ['travis = tox_travis.hooks'],
},
install_requires=['tox>=2.0,<4'],
install_requires=['tox>=2.0'],
python_requires='>=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*',
classifiers=[
'Development Status :: 4 - Beta',
Expand Down
2 changes: 1 addition & 1 deletion src/tox_travis/after.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import json
import time

from tox.config import _split_env as split_env
from .v4_workarounds import _split_env as split_env
try:
import urllib.request as urllib2
except ImportError:
Expand Down
8 changes: 5 additions & 3 deletions src/tox_travis/envlist.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,14 @@
import os
import re
import sys
from itertools import product
import itertools

import tox.config
from tox.config import _split_env as split_env

from .utils import TRAVIS_FACTORS, parse_dict
from .v4_workarounds import _split_env as split_env



def detect_envlist(ini):
"""Default envlist automatically based on the Travis environment."""
Expand All @@ -20,7 +22,7 @@ def detect_envlist(ini):
desired_factors = get_desired_factors(ini)

# Reduce desired factors
desired_envs = ['-'.join(env) for env in product(*desired_factors)]
desired_envs = ['-'.join(env) for env in itertools.product(*desired_factors)]

# Find matching envs
return match_envs(declared_envs, desired_envs,
Expand Down
10 changes: 6 additions & 4 deletions src/tox_travis/hooks.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import os
import sys
import tox
from tox.plugin import impl
from .envlist import (
detect_envlist,
autogen_envconfigs,
Expand All @@ -15,8 +16,8 @@
from .after import travis_after


@tox.hookimpl
def tox_addoption(parser):
@impl
def tox_add_option(parser):
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we know when this was added to tox? Do we need to restrict the lower bound?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Likely you should restrict to latest release, because that's also against what you're running the CI.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See my comment below - this is not compatible with tox<4.

"""Add arguments and needed monkeypatches."""
parser.add_argument(
'--travis-after', dest='travis_after', action='store_true',
Expand All @@ -27,12 +28,13 @@ def tox_addoption(parser):
subcommand_test_monkeypatch(tox_subcommand_test_post)


@tox.hookimpl
def tox_configure(config):
@impl
def tox_add_env_config(env_conf, state):
"""Check for the presence of the added options."""
if 'TRAVIS' not in os.environ:
return

config = env_conf
ini = config._cfg

# envlist
Expand Down
32 changes: 32 additions & 0 deletions src/tox_travis/v4_workarounds.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import itertools
import re

_ENVSTR_SPLIT_PATTERN = re.compile(r"((?:{[^}]+})+)|,")
_ENVSTR_EXPAND_PATTERN = re.compile(r"{([^}]+)}")
_WHITESPACE_PATTERN = re.compile(r"\s+")

def mapcat(f, seq):
return list(itertools.chain.from_iterable(map(f, seq)))


def _expand_envstr(envstr):
# split by commas not in groups
tokens = _ENVSTR_SPLIT_PATTERN.split(envstr)
envlist = ["".join(g).strip() for k, g in itertools.groupby(tokens, key=bool) if k]

def expand(env):
tokens = _ENVSTR_EXPAND_PATTERN.split(env)
parts = [_WHITESPACE_PATTERN.sub("", token).split(",") for token in tokens]
return ["".join(variant) for variant in itertools.product(*parts)]

return mapcat(expand, envlist)

def _split_env(env):
"""if handed a list, action="append" was used for -e"""
if env is None:
return []
if not isinstance(env, list):
env = [e.split("#", 1)[0].strip() for e in env.split("\n")]
env = ",".join(e for e in env if e)
env = [env]
return mapcat(_expand_envstr, env)