|
1 |
| -import subprocess |
2 | 1 | import sys
|
| 2 | +from collections import OrderedDict |
3 | 3 |
|
4 |
| -from tox import reporter as report |
5 |
| -from tox.version import __version__ |
| 4 | +from six import StringIO |
| 5 | +from six.moves import configparser |
| 6 | + |
| 7 | +from tox import reporter |
| 8 | + |
| 9 | +DO_NOT_SHOW_CONFIG_ATTRIBUTES = ( |
| 10 | + "interpreters", |
| 11 | + "envconfigs", |
| 12 | + "envlist", |
| 13 | + "pluginmanager", |
| 14 | + "envlist_explicit", |
| 15 | +) |
6 | 16 |
|
7 | 17 |
|
8 | 18 | def show_config(config):
|
9 |
| - info_versions() |
10 |
| - report.keyvalue("config-file:", config.option.configfile) |
11 |
| - report.keyvalue("toxinipath: ", config.toxinipath) |
12 |
| - report.keyvalue("toxinidir: ", config.toxinidir) |
13 |
| - report.keyvalue("toxworkdir: ", config.toxworkdir) |
14 |
| - report.keyvalue("setupdir: ", config.setupdir) |
15 |
| - report.keyvalue("distshare: ", config.distshare) |
16 |
| - report.keyvalue("skipsdist: ", config.skipsdist) |
17 |
| - report.line("") |
18 |
| - for envconfig in config.envconfigs.values(): |
19 |
| - report.line("[testenv:{}]".format(envconfig.envname), bold=True) |
20 |
| - for attr in config._parser._testenv_attr: |
21 |
| - report.line(" {:<15} = {}".format(attr.name, getattr(envconfig, attr.name))) |
22 |
| - |
23 |
| - |
24 |
| -def info_versions(): |
25 |
| - versions = ["tox-{}".format(__version__)] |
26 |
| - proc = subprocess.Popen( |
27 |
| - (sys.executable, "-m", "virtualenv", "--version"), stdout=subprocess.PIPE |
| 19 | + parser = configparser.ConfigParser() |
| 20 | + |
| 21 | + if not config.envlist_explicit or reporter.verbosity() >= reporter.Verbosity.INFO: |
| 22 | + tox_info(config, parser) |
| 23 | + version_info(parser) |
| 24 | + tox_envs_info(config, parser) |
| 25 | + |
| 26 | + content = StringIO() |
| 27 | + parser.write(content) |
| 28 | + value = content.getvalue().rstrip() |
| 29 | + reporter.verbosity0(value) |
| 30 | + |
| 31 | + |
| 32 | +def tox_envs_info(config, parser): |
| 33 | + if config.envlist_explicit: |
| 34 | + env_list = config.envlist |
| 35 | + elif config.option.listenvs: |
| 36 | + env_list = config.envlist_default |
| 37 | + else: |
| 38 | + env_list = list(config.envconfigs.keys()) |
| 39 | + for name in env_list: |
| 40 | + env_config = config.envconfigs[name] |
| 41 | + values = OrderedDict( |
| 42 | + (attr.name, str(getattr(env_config, attr.name))) |
| 43 | + for attr in config._parser._testenv_attr |
| 44 | + ) |
| 45 | + section = "testenv:{}".format(name) |
| 46 | + set_section(parser, section, values) |
| 47 | + |
| 48 | + |
| 49 | +def tox_info(config, parser): |
| 50 | + info = OrderedDict( |
| 51 | + (i, str(getattr(config, i))) |
| 52 | + for i in sorted(dir(config)) |
| 53 | + if not i.startswith("_") and i not in DO_NOT_SHOW_CONFIG_ATTRIBUTES |
28 | 54 | )
|
29 |
| - out, _ = proc.communicate() |
30 |
| - versions.append("virtualenv-{}".format(out.decode("UTF-8").strip())) |
31 |
| - report.keyvalue("tool-versions:", " ".join(versions)) |
| 55 | + info["host_python"] = sys.executable |
| 56 | + set_section(parser, "tox", info) |
| 57 | + |
| 58 | + |
| 59 | +def version_info(parser): |
| 60 | + import pkg_resources |
| 61 | + |
| 62 | + versions = OrderedDict() |
| 63 | + visited = set() |
| 64 | + to_visit = {"tox"} |
| 65 | + while to_visit: |
| 66 | + current = to_visit.pop() |
| 67 | + visited.add(current) |
| 68 | + current_dist = pkg_resources.get_distribution(current) |
| 69 | + to_visit.update(i.name for i in current_dist.requires() if i.name not in visited) |
| 70 | + versions[current] = current_dist.version |
| 71 | + set_section(parser, "tox:versions", versions) |
| 72 | + |
| 73 | + |
| 74 | +def set_section(parser, section, values): |
| 75 | + parser.add_section(section) |
| 76 | + for key, value in values.items(): |
| 77 | + parser.set(section, key, value) |
0 commit comments