Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
show config now shows all config, filter-able, contains host tox python
and package versions
- Loading branch information
1 parent
bfd22c6
commit d011311
Showing
6 changed files
with
184 additions
and
55 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
``--showconfig`` overhaul: | ||
|
||
- now fully generated via the config parser, so anyone can load it by using the built-in python config parser | ||
- the ``tox`` section contains all configuration data from config | ||
- the ``tox`` section contains a ``host_python`` key detailing the path of the host python | ||
- the ``tox:version`` section contains the versions of all packages tox depends on with their version | ||
- passing ``-l`` now allows only listing default target envs | ||
- allows showing config for a given set of tox environments only via the ``-e`` cli flag or the ``TOXENV`` environment | ||
variable, in this case the ``tox`` and ``tox:version`` section is only shown if at least one verbosity flag is passed |
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,31 +1,76 @@ | ||
import subprocess | ||
import sys | ||
from collections import OrderedDict | ||
|
||
from tox import reporter as report | ||
from tox.version import __version__ | ||
from six import StringIO | ||
|
||
from tox import reporter | ||
|
||
try: | ||
import ConfigParser | ||
except ImportError: | ||
# noinspection PyPep8Naming | ||
import configparser as ConfigParser | ||
|
||
DO_NOT_SHOW_CONFIG_ATTRIBUTES = ( | ||
"interpreters", | ||
"envconfigs", | ||
"envlist", | ||
"pluginmanager", | ||
"envlist_explicit", | ||
) | ||
|
||
|
||
def show_config(config): | ||
info_versions() | ||
report.keyvalue("config-file:", config.option.configfile) | ||
report.keyvalue("toxinipath: ", config.toxinipath) | ||
report.keyvalue("toxinidir: ", config.toxinidir) | ||
report.keyvalue("toxworkdir: ", config.toxworkdir) | ||
report.keyvalue("setupdir: ", config.setupdir) | ||
report.keyvalue("distshare: ", config.distshare) | ||
report.keyvalue("skipsdist: ", config.skipsdist) | ||
report.line("") | ||
for envconfig in config.envconfigs.values(): | ||
report.line("[testenv:{}]".format(envconfig.envname), bold=True) | ||
for attr in config._parser._testenv_attr: | ||
report.line(" {:<15} = {}".format(attr.name, getattr(envconfig, attr.name))) | ||
|
||
|
||
def info_versions(): | ||
versions = ["tox-{}".format(__version__)] | ||
proc = subprocess.Popen( | ||
(sys.executable, "-m", "virtualenv", "--version"), stdout=subprocess.PIPE | ||
parser = ConfigParser.ConfigParser() | ||
|
||
if not config.envlist_explicit or reporter.verbosity() >= reporter.Verbosity.INFO: | ||
tox_info(config, parser) | ||
version_info(parser) | ||
tox_envs_info(config, parser) | ||
|
||
content = StringIO() | ||
parser.write(content) | ||
value = content.getvalue().rstrip() | ||
reporter.verbosity0(value) | ||
|
||
|
||
def tox_envs_info(config, parser): | ||
if config.envlist_explicit: | ||
env_list = config.envlist | ||
elif config.option.listenvs: | ||
env_list = config.envlist_default | ||
else: | ||
env_list = list(config.envconfigs.keys()) | ||
for name in env_list: | ||
env_config = config.envconfigs[name] | ||
values = OrderedDict( | ||
(attr.name, str(getattr(env_config, attr.name))) | ||
for attr in config._parser._testenv_attr | ||
) | ||
parser["testenv:{}".format(name)] = values | ||
|
||
|
||
def tox_info(config, parser): | ||
info = OrderedDict( | ||
(i, str(getattr(config, i))) | ||
for i in sorted(dir(config)) | ||
if not i.startswith("_") and i not in DO_NOT_SHOW_CONFIG_ATTRIBUTES | ||
) | ||
out, _ = proc.communicate() | ||
versions.append("virtualenv-{}".format(out.decode("UTF-8").strip())) | ||
report.keyvalue("tool-versions:", " ".join(versions)) | ||
info["host_python"] = sys.executable | ||
parser["tox"] = info | ||
|
||
|
||
def version_info(parser): | ||
import pkg_resources | ||
|
||
versions = OrderedDict() | ||
visited = set() | ||
to_visit = {"tox"} | ||
while to_visit: | ||
current = to_visit.pop() | ||
visited.add(current) | ||
current_dist = pkg_resources.get_distribution(current) | ||
to_visit.update(i.name for i in current_dist.requires() if i.name not in visited) | ||
versions[current] = current_dist.version | ||
|
||
parser["tox:versions"] = versions |
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
import re | ||
|
||
import pytest | ||
|
||
try: | ||
import ConfigParser | ||
except ImportError: | ||
# noinspection PyPep8Naming | ||
import configparser as ConfigParser | ||
|
||
|
||
def test_showconfig_with_force_dep_version(cmd, initproj): | ||
initproj( | ||
"force_dep_version", | ||
filedefs={ | ||
"tox.ini": """ | ||
[tox] | ||
[testenv] | ||
deps= | ||
dep1==2.3 | ||
dep2 | ||
""" | ||
}, | ||
) | ||
result = cmd("--showconfig") | ||
result.assert_success(is_run_test_env=False) | ||
assert any(re.match(r".*deps.*dep1==2.3, dep2.*", l) for l in result.outlines) | ||
# override dep1 specific version, and force version for dep2 | ||
result = cmd("--showconfig", "--force-dep=dep1", "--force-dep=dep2==5.0") | ||
result.assert_success(is_run_test_env=False) | ||
assert any(re.match(r".*deps.*dep1, dep2==5.0.*", l) for l in result.outlines) | ||
|
||
|
||
@pytest.fixture() | ||
def setup_mixed_conf(initproj): | ||
initproj( | ||
"force_dep_version", | ||
filedefs={ | ||
"tox.ini": """ | ||
[tox] | ||
envlist = py37,py27,pypi,docs | ||
[testenv:notincluded] | ||
changedir = whatever | ||
[testenv:docs] | ||
changedir = docs | ||
""" | ||
}, | ||
) | ||
|
||
|
||
@pytest.mark.parametrize( | ||
"args, expected", | ||
[ | ||
( | ||
["--showconfig"], | ||
[ | ||
"tox", | ||
"tox:versions", | ||
"testenv:py37", | ||
"testenv:py27", | ||
"testenv:pypi", | ||
"testenv:docs", | ||
"testenv:notincluded", | ||
], | ||
), | ||
( | ||
["--showconfig", "-l"], | ||
[ | ||
"tox", | ||
"tox:versions", | ||
"testenv:py37", | ||
"testenv:py27", | ||
"testenv:pypi", | ||
"testenv:docs", | ||
], | ||
), | ||
(["--showconfig", "-e", "py37,py36"], ["testenv:py37", "testenv:py36"]), | ||
], | ||
ids=["all", "default_only", "-e"], | ||
) | ||
def test_showconfig(cmd, setup_mixed_conf, args, expected): | ||
result = cmd(*args) | ||
result.assert_success(is_run_test_env=False) | ||
parser = ConfigParser.ConfigParser() | ||
parser.read_string(result.out) | ||
found_sections = parser.sections() | ||
assert found_sections == expected |
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