Skip to content

Commit 7afb0a0

Browse files
authored
Merge pull request #495 from gaborbernat/all_env
[#271] show all defined enviroments for listenv, not just what's in envlist
2 parents a19d3d3 + 02cac29 commit 7afb0a0

File tree

4 files changed

+108
-20
lines changed

4 files changed

+108
-20
lines changed

doc/config.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -341,7 +341,7 @@ Complete list of settings that you can put into ``testenv*`` sections:
341341

342342
a short description of the environment, this will be used to explain
343343
the environment to the user upon listing environments for the command
344-
line. **default**: empty string
344+
line with any level of verbosity higher than zero. **default**: empty string
345345

346346
Substitutions
347347
-------------

tests/test_config.py

+75-12
Original file line numberDiff line numberDiff line change
@@ -1980,6 +1980,11 @@ def test_listenvs(self, cmd, initproj):
19801980
'tox.ini': '''
19811981
[tox]
19821982
envlist=py26,py27,py33,pypy,docs
1983+
description= py27: run py.test on Python 2.7
1984+
py33: run py.test on Python 3.6
1985+
pypy: publish to pypy
1986+
docs: document stuff
1987+
notincluded: random extra
19831988
19841989
[testenv:notincluded]
19851990
changedir = whatever
@@ -1990,15 +1995,69 @@ def test_listenvs(self, cmd, initproj):
19901995
})
19911996
result = cmd.run("tox", "-l")
19921997
result.stdout.fnmatch_lines("""
1993-
*py26*
1994-
*py27*
1995-
*py33*
1996-
*pypy*
1997-
*docs*
1998+
py26
1999+
py27
2000+
py33
2001+
pypy
2002+
docs
19982003
""")
19992004

2000-
def test_listenvs_description(self, cmd, initproj):
2001-
initproj('listenvs', filedefs={
2005+
def test_listenvs_verbose_description(self, cmd, initproj):
2006+
initproj('listenvs_verbose_description', filedefs={
2007+
'tox.ini': '''
2008+
[tox]
2009+
envlist=py26,py27,py33,pypy,docs
2010+
[testenv]
2011+
description= py26: run py.test on Python 2.6
2012+
py27: run py.test on Python 2.7
2013+
py33: run py.test on Python 3.3
2014+
pypy: publish to pypy
2015+
docs: document stuff
2016+
notincluded: random extra
2017+
2018+
[testenv:notincluded]
2019+
changedir = whatever
2020+
2021+
[testenv:docs]
2022+
changedir = docs
2023+
description = let me overwrite that
2024+
''',
2025+
})
2026+
result = cmd.run("tox", "-lv")
2027+
result.stdout.fnmatch_lines("""
2028+
default environments:
2029+
py26 -> run py.test on Python 2.6
2030+
py27 -> run py.test on Python 2.7
2031+
py33 -> run py.test on Python 3.3
2032+
pypy -> publish to pypy
2033+
docs -> let me overwrite that
2034+
""")
2035+
2036+
def test_listenvs_all(self, cmd, initproj):
2037+
initproj('listenvs_all', filedefs={
2038+
'tox.ini': '''
2039+
[tox]
2040+
envlist=py26,py27,py33,pypy,docs
2041+
2042+
[testenv:notincluded]
2043+
changedir = whatever
2044+
2045+
[testenv:docs]
2046+
changedir = docs
2047+
''',
2048+
})
2049+
result = cmd.run("tox", "-a")
2050+
result.stdout.fnmatch_lines("""
2051+
py26
2052+
py27
2053+
py33
2054+
pypy
2055+
docs
2056+
notincluded
2057+
""")
2058+
2059+
def test_listenvs_all_verbose_description(self, cmd, initproj):
2060+
initproj('listenvs_all_verbose_description', filedefs={
20022061
'tox.ini': '''
20032062
[tox]
20042063
envlist={py27,py36}-{windows,linux}
@@ -2014,12 +2073,16 @@ def test_listenvs_description(self, cmd, initproj):
20142073
changedir = docs
20152074
''',
20162075
})
2017-
result = cmd.run("tox", "-l")
2076+
result = cmd.run("tox", "-av")
20182077
result.stdout.fnmatch_lines("""
2019-
py27-windows run py.test on Python 2.7 on Windows platform
2020-
py27-linux run py.test on Python 2.7 on Linux platform
2021-
py36-windows run py.test on Python 3.6 on Windows platform
2022-
py36-linux run py.test on Python 3.6 on Linux platform
2078+
default environments:
2079+
py27-windows -> run py.test on Python 2.7 on Windows platform
2080+
py27-linux -> run py.test on Python 2.7 on Linux platform
2081+
py36-windows -> run py.test on Python 3.6 on Windows platform
2082+
py36-linux -> run py.test on Python 3.6 on Linux platform
2083+
2084+
additional environments:
2085+
docs -> generate documentation
20232086
""")
20242087

20252088
def test_config_specific_ini(self, tmpdir, cmd):

tox/config.py

+6-1
Original file line numberDiff line numberDiff line change
@@ -321,7 +321,12 @@ def tox_addoption(parser):
321321
parser.add_argument("--showconfig", action="store_true",
322322
help="show configuration information for all environments. ")
323323
parser.add_argument("-l", "--listenvs", action="store_true",
324-
dest="listenvs", help="show list of test environments")
324+
dest="listenvs", help="show list of test environments "
325+
"(with description if verbose)")
326+
parser.add_argument("-a", "--listenvs-all", action="store_true",
327+
dest="listenvs_all",
328+
help="show list of all defined environments"
329+
"(with description if verbose)")
325330
parser.add_argument("-c", action="store", default="tox.ini",
326331
dest="configfile",
327332
help="config file name or directory with 'tox.ini' file.")

tox/session.py

+26-6
Original file line numberDiff line numberDiff line change
@@ -385,7 +385,9 @@ def runcommand(self):
385385
if self.config.option.showconfig:
386386
self.showconfig()
387387
elif self.config.option.listenvs:
388-
self.showenvs()
388+
self.showenvs(all_envs=False, description=self.config.option.verbosity > 0)
389+
elif self.config.option.listenvs_all:
390+
self.showenvs(all_envs=True, description=self.config.option.verbosity > 0)
389391
else:
390392
return self.subcommand_test()
391393

@@ -626,11 +628,29 @@ def showconfig(self):
626628
self.report.line(" %-15s = %s"
627629
% (attr.name, getattr(envconfig, attr.name)))
628630

629-
def showenvs(self):
630-
max_length = max(len(env) for env in self.config.envlist)
631-
for env in self.config.envlist:
632-
self.report.line("{0} {1}".format(env.ljust(max_length),
633-
self.config.envconfigs[env].description).strip())
631+
def showenvs(self, all_envs=False, description=False):
632+
env_conf = self.config.envconfigs # this contains all environments
633+
default = self.config.envlist # this only the defaults
634+
extra = sorted([e for e in env_conf if e not in default]) if all_envs else []
635+
if description:
636+
self.report.line('default environments:')
637+
max_length = max(len(env) for env in (default + extra))
638+
639+
def report_env(e):
640+
if description:
641+
msg = '{0} -> {1}'.format(e.ljust(max_length),
642+
env_conf[e].description).strip()
643+
else:
644+
msg = e
645+
self.report.line(msg)
646+
for e in default:
647+
report_env(e)
648+
if all_envs:
649+
if description:
650+
self.report.line('')
651+
self.report.line('additional environments:')
652+
for e in extra:
653+
report_env(e)
634654

635655
def info_versions(self):
636656
versions = ['tox-%s' % tox.__version__]

0 commit comments

Comments
 (0)