tox4: substituting values from other sections seems to not work

Created on 30 Mar 2021  路  6Comments  路  Source: tox-dev/tox

Hi, I gave a try new tox alpha release (tox-4.0.0a6) and I found one issue with tox not respecting values substitution from other sections. I do not see any references to this section in the documentation anymore so maybe it is something you want to get rid of...

Anyway - this is how it looks like:

$ tox -rvv
ROOT: 217 D setup logging to DEBUG on pid 86537 [tox/report.py:211]
Traceback (most recent call last):
  File "/Users/mrusi/venv/lib/python3.8/site-packages/tox/config/main.py", line 51, in get_env
    return self._env_to_set[item]
KeyError: 'py'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/Users/mrusi/venv/bin/tox4", line 8, in <module>
    sys.exit(run())
  File "/Users/mrusi/venv/lib/python3.8/site-packages/tox/run.py", line 22, in run
    result = main(sys.argv[1:] if args is None else args)
  File "/Users/mrusi/venv/lib/python3.8/site-packages/tox/run.py", line 47, in main
    result = handler(state)
  File "/Users/mrusi/venv/lib/python3.8/site-packages/tox/session/cmd/legacy.py", line 104, in legacy
    return run_sequential(state)
  File "/Users/mrusi/venv/lib/python3.8/site-packages/tox/session/cmd/run/sequential.py", line 20, in run_sequential
    return execute(state, max_workers=1, has_spinner=False, live=True)
  File "/Users/mrusi/venv/lib/python3.8/site-packages/tox/session/cmd/run/common.py", line 172, in execute
    if state.tox_env(env).active:
  File "/Users/mrusi/venv/lib/python3.8/site-packages/tox/session/state.py", line 64, in tox_env
    self.conf.get_env(name)  # the lookup here will trigger register_config_set, which will build it
  File "/Users/mrusi/venv/lib/python3.8/site-packages/tox/config/main.py", line 61, in get_env
    self.register_config_set(item, env)
  File "/Users/mrusi/venv/lib/python3.8/site-packages/tox/session/state.py", line 76, in register_config_set
    self._build_run_env(config_set)
  File "/Users/mrusi/venv/lib/python3.8/site-packages/tox/session/state.py", line 91, in _build_run_env
    env: RunToxEnv = builder(env_conf, self.conf.core, self.options, journal, self.log_handler)
  File "/Users/mrusi/venv/lib/python3.8/site-packages/tox/tox_env/python/virtual_env/runner.py", line 26, in __init__
    super().__init__(conf, core, options, journal, log_handler)
  File "/Users/mrusi/venv/lib/python3.8/site-packages/tox/tox_env/python/virtual_env/api.py", line 35, in __init__
    super().__init__(conf, core, options, journal, log_handler)
  File "/Users/mrusi/venv/lib/python3.8/site-packages/tox/tox_env/python/runner.py", line 25, in __init__
    super().__init__(conf, core, options, journal, log_handler)
  File "/Users/mrusi/venv/lib/python3.8/site-packages/tox/tox_env/python/api.py", line 79, in __init__
    super().__init__(conf, core, options, journal, log_handler)
  File "/Users/mrusi/venv/lib/python3.8/site-packages/tox/tox_env/runner.py", line 27, in __init__
    super().__init__(conf, core, options, journal, log_handler)
  File "/Users/mrusi/venv/lib/python3.8/site-packages/tox/tox_env/api.py", line 40, in __init__
    self.register_config()
  File "/Users/mrusi/venv/lib/python3.8/site-packages/tox/tox_env/python/virtual_env/api.py", line 38, in register_config
    super().register_config()
  File "/Users/mrusi/venv/lib/python3.8/site-packages/tox/tox_env/python/runner.py", line 29, in register_config
    super().register_config()
  File "/Users/mrusi/venv/lib/python3.8/site-packages/tox/tox_env/python/api.py", line 82, in register_config
    super().register_config()
  File "/Users/mrusi/venv/lib/python3.8/site-packages/tox/tox_env/runner.py", line 77, in register_config
    self.has_package = self.add_package_conf()
  File "/Users/mrusi/venv/lib/python3.8/site-packages/tox/tox_env/python/virtual_env/runner.py", line 38, in add_package_conf
    develop_mode = self.conf["usedevelop"] or getattr(self.options, "develop", False)
  File "/Users/mrusi/venv/lib/python3.8/site-packages/tox/config/sets.py", line 86, in __getitem__
    return self.load(item)
  File "/Users/mrusi/venv/lib/python3.8/site-packages/tox/config/sets.py", line 97, in load
    return config_definition(self._conf, item, self.loaders, chain)
  File "/Users/mrusi/venv/lib/python3.8/site-packages/tox/config/of_type.py", line 99, in __call__
    value = loader.load(key, self.of_type, self.kwargs, conf, self.env_name, chain)
  File "/Users/mrusi/venv/lib/python3.8/site-packages/tox/config/loader/api.py", line 98, in load
    converted = self.to(prepared, of_type, kwargs)
  File "/Users/mrusi/venv/lib/python3.8/site-packages/tox/config/loader/convert.py", line 31, in to
    return self.to_bool(raw)  # type: ignore[return-value]
  File "/Users/mrusi/venv/lib/python3.8/site-packages/tox/config/loader/str_convert.py", line 90, in to_bool
    raise TypeError(f"value {value} cannot be transformed to bool, valid: {', '.join(StrConvert.VALID_BOOL)}")
TypeError: value {[project-info]develop} cannot be transformed to bool, valid: , 0, 1, false, no, off, on, true, yes

$ cat tox.ini
[project-info]
develop = false
[testenv]
deps=-rrequirements.txt
usedevelop = {[project-info]develop}
commands=echo "commands"
normal tox4

Most helpful comment

Here is a clearer reproducer:

[tox]
skipsdist = True

[nodash]
a = value-from-nodash

[with-dash]
a = value-from-with-dash

[testenv:envnodash]
a = value-from-testenv:envnodash

[testenv:env-with-dash]
a = value-from-testenv:env-with-dash

[testenv]
commands =
    echo {[nodash]a}
    echo {[with-dash]a}
    echo {[testenv:envnodash]a}
    echo {[testenv:env-with-dash]a}
/home/ob/oss/tox-dev/tox/.tox/dev/bin/tox4 -r
py: remove tox env folder /home/ob/oss/tox-dev/lab/1985/.tox/4/py
py: commands[0]> echo value-from-nodash
value-from-nodash
py: commands[1]> echo '{[with-dash]a}'
{[with-dash]a}
py: commands[2]> echo value-from-testenv:envnodash
value-from-testenv:envnodash
py: commands[3]> echo value-from-testenv:env-with-dash
value-from-testenv:env-with-dash
  py: OK (0.16=setup[0.13]+cmd[0.01,0.01,0.00,0.01] seconds)
  congratulations :) (0.20 seconds)

So, for "real" testenvs it even works correctly already, only if non testenv section name consists a dash, there is still trouble.

All 6 comments

This should work, will check, thanks 馃憤馃徎

This issue is unaffected of #1991 and still remains open.

I'd like to give it a try.

I had a fun session with @eumiro and @obestwalter - the problem boils down to the dash/hyphen in the section name. We'll have another look tomorrow.

Can you clarify?

Here is a clearer reproducer:

[tox]
skipsdist = True

[nodash]
a = value-from-nodash

[with-dash]
a = value-from-with-dash

[testenv:envnodash]
a = value-from-testenv:envnodash

[testenv:env-with-dash]
a = value-from-testenv:env-with-dash

[testenv]
commands =
    echo {[nodash]a}
    echo {[with-dash]a}
    echo {[testenv:envnodash]a}
    echo {[testenv:env-with-dash]a}
/home/ob/oss/tox-dev/tox/.tox/dev/bin/tox4 -r
py: remove tox env folder /home/ob/oss/tox-dev/lab/1985/.tox/4/py
py: commands[0]> echo value-from-nodash
value-from-nodash
py: commands[1]> echo '{[with-dash]a}'
{[with-dash]a}
py: commands[2]> echo value-from-testenv:envnodash
value-from-testenv:envnodash
py: commands[3]> echo value-from-testenv:env-with-dash
value-from-testenv:env-with-dash
  py: OK (0.16=setup[0.13]+cmd[0.01,0.01,0.00,0.01] seconds)
  congratulations :) (0.20 seconds)

So, for "real" testenvs it even works correctly already, only if non testenv section name consists a dash, there is still trouble.

You should not do a run or echo to find out what's happening. All you need is tox4 c -k commands to make it truly minimalistic (same in the test suite).

Was this page helpful?
0 / 5 - 0 ratings