Skip to content

Commit a9ec661

Browse files
authored
Add alias "allowlist_externals" to "whitelist_externals" (#1601)
1 parent c4ef11d commit a9ec661

File tree

12 files changed

+81
-26
lines changed

12 files changed

+81
-26
lines changed

CONTRIBUTORS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ Clark Boylan
2626
Cyril Roelandt
2727
Dane Hillard
2828
David Staheli
29+
David Diaz
2930
Ederag
3031
Eli Collins
3132
Eugene Yunak

docs/changelog/1491.deprecation.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Add allowlist_externals alias to whitelist_externals (whitelist_externals is now deprecated). - by :user:`dajose`

docs/config.rst

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -325,15 +325,20 @@ Complete list of settings that you can put into ``testenv*`` sections:
325325

326326
Don't set this option if your :conf:`install_command` does not use pip.
327327

328-
.. conf:: whitelist_externals ^ MULTI-LINE-LIST
328+
.. conf:: allowlist_externals ^ MULTI-LINE-LIST
329329

330330
Each line specifies a command name (in glob-style pattern format)
331331
which can be used in the ``commands`` section without triggering
332332
a "not installed in virtualenv" warning. Example: if you use the
333-
unix ``make`` for running tests you can list ``whitelist_externals=make``
334-
or ``whitelist_externals=/usr/bin/make`` if you want more precision.
333+
unix ``make`` for running tests you can list ``allowlist_externals=make``
334+
or ``allowlist_externals=/usr/bin/make`` if you want more precision.
335335
If you don't want tox to issue a warning in any case, just use
336-
``whitelist_externals=*`` which will match all commands (not recommended).
336+
``allowlist_externals=*`` which will match all commands (not recommended).
337+
338+
.. note::
339+
340+
``whitelist_externals`` has the same meaning and usage as ``allowlist_externals``
341+
but it is now deprecated.
337342

338343
.. conf:: changedir ^ PATH ^ {toxinidir}
339344

@@ -461,7 +466,7 @@ Complete list of settings that you can put into ``testenv*`` sections:
461466
WARNING: test command found but not installed in testenv
462467
cmd: /path/to/parent/interpreter/bin/<some command>
463468
env: /foo/bar/.tox/python
464-
Maybe you forgot to specify a dependency? See also the whitelist_externals envconfig setting.
469+
Maybe you forgot to specify a dependency? See also the allowlist_externals envconfig setting.
465470

466471

467472
.. conf:: alwayscopy ^ true|false ^ false

docs/example/basic.rst

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -104,21 +104,21 @@ runs on you can set a platform regular expression like this:
104104
If the expression does not match against ``sys.platform``
105105
the test environment will be skipped.
106106

107-
whitelisting non-virtualenv commands
107+
allowing non-virtualenv commands
108108
-----------------------------------------------
109109

110110
.. versionadded:: 1.5
111111

112112
Sometimes you may want to use tools not contained in your
113113
virtualenv such as ``make``, ``bash`` or others. To avoid
114-
warnings you can use the ``whitelist_externals`` testenv
114+
warnings you can use the ``allowlist_externals`` testenv
115115
configuration:
116116

117117
.. code-block:: ini
118118
119119
# content of tox.ini
120120
[testenv]
121-
whitelist_externals = make
121+
allowlist_externals = make
122122
/bin/bash
123123
124124

docs/index.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ tox will take care of environment isolation for you: it will strip away all oper
119119
environment variables not specified via :conf:`passenv`. Furthermore, it will also alter the
120120
``PATH`` variable so that your commands resolve first and foremost within the current active
121121
tox environment. In general all executables in the path are available in ``commands``, but tox will
122-
emit a warning if it was not explicitly allowed via :conf:`whitelist_externals`.
122+
emit a warning if it was not explicitly allowed via :conf:`allowlist_externals`.
123123

124124
Current features
125125
-------------------

src/tox/config/__init__.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -760,7 +760,11 @@ def passenv(testenv_config, value):
760760
)
761761

762762
parser.add_testenv_attribute(
763-
name="whitelist_externals",
763+
name="whitelist_externals", type="line-list", help="DEPRECATED: use allowlist_externals",
764+
)
765+
766+
parser.add_testenv_attribute(
767+
name="allowlist_externals",
764768
type="line-list",
765769
help="each lines specifies a path or basename for which tox will not warn "
766770
"about it coming from outside the test environment.",

src/tox/venv.py

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@ def getcommandpath(self, name, venv=True, cwd=None):
169169
170170
- If it's a local path we will rewrite it as as a relative path.
171171
- If venv is True we will check if the command is coming from the venv
172-
or is whitelisted to come from external.
172+
or is allowed to come from external.
173173
"""
174174
name = str(name)
175175
if os.path.isabs(name):
@@ -180,7 +180,7 @@ def getcommandpath(self, name, venv=True, cwd=None):
180180
return str(path)
181181

182182
if venv:
183-
path = self._venv_lookup_and_check_external_whitelist(name)
183+
path = self._venv_lookup_and_check_external_allowlist(name)
184184
else:
185185
path = self._normal_lookup(name)
186186

@@ -191,7 +191,7 @@ def getcommandpath(self, name, venv=True, cwd=None):
191191

192192
return str(path) # will not be rewritten for reporting
193193

194-
def _venv_lookup_and_check_external_whitelist(self, name):
194+
def _venv_lookup_and_check_external_allowlist(self, name):
195195
path = self._venv_lookup(name)
196196
if path is None:
197197
path = self._normal_lookup(name)
@@ -212,7 +212,7 @@ def _check_external_allowed_and_warn(self, path):
212212
" cmd: {}\n"
213213
" env: {}\n"
214214
"Maybe you forgot to specify a dependency? "
215-
"See also the whitelist_externals envconfig setting.\n\n"
215+
"See also the allowlist_externals envconfig setting.\n\n"
216216
"DEPRECATION WARNING: this will be an error in tox 4 and above!".format(
217217
path, self.envconfig.envdir,
218218
),
@@ -223,7 +223,16 @@ def is_allowed_external(self, p):
223223
if tox.INFO.IS_WIN:
224224
tryadd += [os.path.normcase(x) for x in os.environ["PATHEXT"].split(os.pathsep)]
225225
p = py.path.local(os.path.normcase(str(p)))
226-
for x in self.envconfig.whitelist_externals:
226+
227+
if self.envconfig.allowlist_externals and self.envconfig.whitelist_externals:
228+
raise tox.exception.ConfigError(
229+
"Either whitelist_externals or allowlist_externals might be specified, not both",
230+
)
231+
232+
allowed_externals = (
233+
self.envconfig.whitelist_externals or self.envconfig.allowlist_externals
234+
)
235+
for x in allowed_externals:
227236
for add in tryadd:
228237
if p.fnmatch(x + add):
229238
return True

tests/integration/test_parallel_interrupt.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ def test_parallel_interrupt(initproj, monkeypatch, capfd):
3333
skip_install = True
3434
commands = python -c "open('{{envname}}', 'w').write('done'); \
3535
import time; time.sleep(100)"
36-
whitelist_externals = {}
36+
allowlist_externals = {}
3737
3838
""".format(
3939
sys.executable,

tests/unit/config/test_config.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -999,25 +999,25 @@ def test_specific_command_overrides(self, newconfig):
999999
envconfig = config.envconfigs["py"]
10001000
assert envconfig.commands == [["abc"]]
10011001

1002-
def test_whitelist_externals(self, newconfig):
1002+
def test_allowlist_externals(self, newconfig):
10031003
config = newconfig(
10041004
"""
10051005
[testenv]
1006-
whitelist_externals = xyz
1006+
allowlist_externals = xyz
10071007
commands=xyz
10081008
[testenv:x]
10091009
10101010
[testenv:py]
1011-
whitelist_externals = xyz2
1011+
allowlist_externals = xyz2
10121012
commands=abc
10131013
""",
10141014
)
10151015
assert len(config.envconfigs) == 2
10161016
envconfig = config.envconfigs["py"]
10171017
assert envconfig.commands == [["abc"]]
1018-
assert envconfig.whitelist_externals == ["xyz2"]
1018+
assert envconfig.allowlist_externals == ["xyz2"]
10191019
envconfig = config.envconfigs["x"]
1020-
assert envconfig.whitelist_externals == ["xyz"]
1020+
assert envconfig.allowlist_externals == ["xyz"]
10211021

10221022
def test_changedir(self, newconfig):
10231023
config = newconfig(

tests/unit/session/test_parallel.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ def test_parallel_error_report(cmd, initproj, monkeypatch, live):
9898
skip_install = true
9999
commands=python -c "import sys, os; sys.stderr.write(str(12345) + os.linesep);\
100100
raise SystemExit(17)"
101-
whitelist_externals = {}
101+
allowlist_externals = {}
102102
""".format(
103103
sys.executable,
104104
),
@@ -129,7 +129,7 @@ def test_parallel_deadlock(cmd, initproj, monkeypatch):
129129
skipsdist = true
130130
131131
[testenv]
132-
whitelist_externals = {}
132+
allowlist_externals = {}
133133
commands =
134134
python -c '[print("hello world") for _ in range(5000)]'
135135
""".format(
@@ -148,7 +148,7 @@ def test_parallel_recreate(cmd, initproj, monkeypatch):
148148
skipsdist = true
149149
150150
[testenv]
151-
whitelist_externals = {}
151+
allowlist_externals = {}
152152
commands =
153153
python -c '[print("hello world") for _ in range(1)]'
154154
""".format(
@@ -177,7 +177,7 @@ def test_parallel_show_output(cmd, initproj, monkeypatch):
177177
skipsdist = true
178178
179179
[testenv]
180-
whitelist_externals = {}
180+
allowlist_externals = {}
181181
commands =
182182
python -c 'import sys; sys.stderr.write("stderr env"); sys.stdout.write("stdout env")'
183183

tests/unit/test_venv.py

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -450,6 +450,41 @@ def test_install_command_whitelisted(newmocksession):
450450
assert venv.status == "commands failed"
451451

452452

453+
def test_install_command_allowlisted(newmocksession):
454+
mocksession = newmocksession(
455+
["--recreate"],
456+
"""\
457+
[testenv]
458+
allowlist_externals = pytest
459+
xy*
460+
commands=
461+
pytest
462+
xyz
463+
""",
464+
)
465+
venv = mocksession.getvenv("python")
466+
venv.test()
467+
mocksession.report.expect("warning", "*test command found but not*", invert=True)
468+
assert venv.status == "commands failed"
469+
470+
471+
def test_install_command_allowlisted_exclusive(newmocksession):
472+
mocksession = newmocksession(
473+
["--recreate"],
474+
"""\
475+
[testenv]
476+
allowlist_externals = pytest
477+
whitelist_externals = xy*
478+
commands=
479+
pytest
480+
xyz
481+
""",
482+
)
483+
venv = mocksession.getvenv("python")
484+
with pytest.raises(tox.exception.ConfigError):
485+
venv.test()
486+
487+
453488
def test_install_command_not_installed_bash(newmocksession):
454489
mocksession = newmocksession(
455490
["--recreate"],

tests/unit/test_z_cmdline.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -821,7 +821,7 @@ def test_empty_activity_shown_verbose(initproj, cmd):
821821
[testenv]
822822
list_dependencies_command=echo
823823
commands={envpython} --version
824-
whitelist_externals = echo
824+
allowlist_externals = echo
825825
""",
826826
},
827827
)

0 commit comments

Comments
 (0)