Created
November 23, 2016 16:05
-
-
Save eli-collins/ef91add2bc635ccaf61738cd805cb18b to your computer and use it in GitHub Desktop.
Helper for running tox
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
""" | |
Quick script that returns list of TOX envs, after applying pattern expansion. | |
Usage example: | |
$ toxmatch {foo,bar}-py{2,3} | |
foo-py2,foo-py3,bar-py2,bar-py3 | |
""" | |
from __future__ import print_function | |
import sys | |
import subprocess | |
try: | |
from itertools import filter | |
except ImportError: | |
pass | |
from tox.config import _expand_envstr | |
def main(pattern): | |
reqs = set(frozenset(elem.split("-")) for elem in _expand_envstr(pattern)) | |
def match(env): | |
factors = set(env.split("-")) | |
return any(factors.issuperset(req) for req in reqs) | |
envs = subprocess.check_output(["tox", "-l"]).splitlines() | |
print(",".join(env for env in envs if match(env))) | |
if __name__ == "__main__": | |
sys.exit(main(*sys.argv[1:])) |
these both seem to have a problem with signature def main(pattern)
vs calling main(*sys.argv[1:])
leading to TypeError: main() takes exactly 1 argument (2 given)
but basically works good
"""
Usage example:
$ toxmatch {foo,bar}-py{2,3}
foo-py2,foo-py3,bar-py2,bar-py3
$ toxmatch py2
foo-py2,bar-py2,baz-py2
$ toxmatch foo
foo-py2,foo-py3
"""
from __future__ import print_function
import sys
from tox.config import parseconfig, _expand_envstr
def main(pattern):
reqs = set(frozenset(elem.split("-")) for elem in _expand_envstr(pattern))
def match(env):
factors = set(env.split("-"))
return any(factors.issuperset(req) for req in reqs)
print(
",".join(
env
for env in parseconfig([]).envlist
if match(env)
)
)
if __name__ == "__main__":
sys.exit(main(sys.argv[1]))
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This has problems on python3 due to a bytes/string issue when calling subprocess. You can circumvent this completely by calling tox directly.