Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

tox4: Environment files for setenv are not working #2435

Closed
johannesloibl opened this issue Jun 2, 2022 · 5 comments
Closed

tox4: Environment files for setenv are not working #2435

johannesloibl opened this issue Jun 2, 2022 · 5 comments
Assignees
Labels
bug:normal affects many people or has quite an impact needs:more-info
Milestone

Comments

@johannesloibl
Copy link

This is working as expected in tox 3.25, but failing with 4.0.0b4.

[tox]
envlist =
    check
setenv =
    file|ci/tox_setenv.txt

Error message

PS C:\git\pyverify> tox -e check -r
←[1m←[35mROOT:←[0m←[36m will run in automatically provisioned tox, host c:\python39\python.exe is missing [requires (has)]: tox-current-env←[0m
Traceback (most recent call last):
  File "c:\python39\lib\runpy.py", line 197, in _run_module_as_main
    return _run_code(code, main_globals, None,
  File "c:\python39\lib\runpy.py", line 87, in _run_code
    exec(code, run_globals)
  File "C:\Python39\Scripts\tox.exe\__main__.py", line 7, in <module>
  File "c:\python39\lib\site-packages\tox\run.py", line 18, in run
    result = main(sys.argv[1:] if args is None else args)
  File "c:\python39\lib\site-packages\tox\run.py", line 40, in main
    result = provision(state)
  File "c:\python39\lib\site-packages\tox\provision.py", line 124, in provision
    return run_provision(provision_tox_env, state)
  File "c:\python39\lib\site-packages\tox\provision.py", line 143, in run_provision
    env_python = tox_env.env_python()
  File "c:\python39\lib\site-packages\tox\tox_env\python\virtual_env\api.py", line 156, in env_python
    return cast(Path, self.creator.exe)
  File "c:\python39\lib\site-packages\tox\tox_env\python\virtual_env\api.py", line 127, in creator
    return self.session.creator
  File "c:\python39\lib\site-packages\tox\tox_env\python\virtual_env\api.py", line 107, in session
    env = self.virtualenv_env_vars()
  File "c:\python39\lib\site-packages\tox\tox_env\python\virtual_env\api.py", line 112, in virtualenv_env_vars
    env = self.environment_variables.copy()
  File "c:\python39\lib\site-packages\tox\tox_env\python\virtual_env\api.py", line 167, in environment_variables
    environment_variables = super().environment_variables
  File "c:\python39\lib\site-packages\tox\tox_env\runner.py", line 196, in environment_variables
    environment_variables = super().environment_variables
  File "c:\python39\lib\site-packages\tox\tox_env\api.py", line 310, in environment_variables
    for key in set_env:
  File "c:\python39\lib\site-packages\tox\config\set_env.py", line 91, in __iter__
    sub_raw = dict(self._extract_key_value(sub_line) for sub_line in expanded_line.splitlines() if sub_line)
  File "c:\python39\lib\site-packages\tox\config\set_env.py", line 91, in <genexpr>
    sub_raw = dict(self._extract_key_value(sub_line) for sub_line in expanded_line.splitlines() if sub_line)
  File "c:\python39\lib\site-packages\tox\config\set_env.py", line 67, in _extract_key_value
    raise ValueError(f"invalid line {line!r} in set_env")
ValueError: invalid line 'file|ci/tox_setenv.txt' in set_env

@johannesloibl johannesloibl added the bug:normal affects many people or has quite an impact label Jun 2, 2022
@gaborbernat gaborbernat changed the title Environment files for setenv are not working tox4: Environment files for setenv are not working Jun 3, 2022
@gaborbernat gaborbernat added this to the 4.0 milestone Jun 3, 2022
@jugmac00 jugmac00 self-assigned this Oct 1, 2022
@jugmac00
Copy link
Member

jugmac00 commented Oct 1, 2022

I'll have a look these days.

@jugmac00
Copy link
Member

jugmac00 commented Oct 1, 2022

I cannot reproduce your problem on Linux at least, as here it works.

When I have a look at your traceback, I wonder what content is in your env file.

  File "c:\python39\lib\site-packages\tox\config\set_env.py", line 67, in _extract_key_value
    raise ValueError(f"invalid line {line!r} in set_env")
ValueError: invalid line 'file|ci/tox_setenv.txt' in set_env

Line 67 is already checking the contents of the env file, not the tox.ini file / configuration setting.

Also see

        for env_line in env_file.read_text().splitlines():
            env_line = env_line.strip()
            if not env_line or env_line.startswith("#"):
                continue
            key, value = self._extract_key_value(env_line)
            self._raw[key] = value

So, did you accidentally write

file|ci/tox_setenv.txt

in your env file and not in tox.ini?

@gaborbernat
Copy link
Member

Lacking more information.

@pcharmoille
Copy link

@gaborbernat I can provide a reproducible configuration since I stumble this issue :

[tox]
envlist =
    check

[testenv]
setenv =
    file|whatever.env

[testenv:check]
setenv =
    {[testenv]setenv}
commands =
    any_command

this would work in tox<4 (3.28.0 at least) but not in tox>4 since in can remember (at least a year).

Hope it helps.

@gaborbernat
Copy link
Member

PR welcome to fix it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug:normal affects many people or has quite an impact needs:more-info
Projects
None yet
Development

No branches or pull requests

4 participants