envbindir substitution key not found

Issue #246 on hold
Brant Knudson created an issue

If tox.ini has {envbindir} you get an exception tox.ConfigError: ConfigError: substitution key 'envbindir' not found

{envbindir} works with tox<2.0 and it's in the docs: http://tox.readthedocs.org/en/latest/config.html#substitutions-for-virtualenv-related-sections

Comments (10)

  1. Buck Evan

    {envsitepackagesdir} has the same problem. It's almost certainly the same bug.

    | setenv =
    |     TOP={toxinidir}
    |     PROJECT={[tox]project}
    |     SITEPACKAGES={envsitepackagesdir}
    
    $ tox -l
    Traceback (most recent call last):
      File "/nail/home/buck/trees/yelp/venv-update/venv-venv_update/bin/tox", line 11, in <module>
        sys.exit(cmdline())
      File "/nail/home/buck/trees/yelp/venv-update/venv-venv_update/lib/python2.7/site-packages/tox/session.py", line 38, in main
        config = prepare(args)
      File "/nail/home/buck/trees/yelp/venv-update/venv-venv_update/lib/python2.7/site-packages/tox/session.py", line 26, in prepare
        config = parseconfig(args)
      File "/nail/home/buck/trees/yelp/venv-update/venv-venv_update/lib/python2.7/site-packages/tox/config.py", line 219, in parseconfig
        parseini(config, inipath)
      File "/nail/home/buck/trees/yelp/venv-update/venv-venv_update/lib/python2.7/site-packages/tox/config.py", line 661, in __init__
        self.make_envconfig(name, section, reader._subs, config)
      File "/nail/home/buck/trees/yelp/venv-update/venv-venv_update/lib/python2.7/site-packages/tox/config.py", line 689, in make_envconfig
        res = meth(env_attr.name, env_attr.default)
      File "/nail/home/buck/trees/yelp/venv-update/venv-venv_update/lib/python2.7/site-packages/tox/config.py", line 822, in getdict
        s = self.getstring(name, None)
      File "/nail/home/buck/trees/yelp/venv-update/venv-venv_update/lib/python2.7/site-packages/tox/config.py", line 876, in getstring
        x = self._replace(x)
      File "/nail/home/buck/trees/yelp/venv-update/venv-venv_update/lib/python2.7/site-packages/tox/config.py", line 972, in _replace
        return RE_ITEM_REF.sub(self._replace_match, x)
      File "/nail/home/buck/trees/yelp/venv-update/venv-venv_update/lib/python2.7/site-packages/tox/config.py", line 968, in _replace_match
        return handler(match)
      File "/nail/home/buck/trees/yelp/venv-update/venv-venv_update/lib/python2.7/site-packages/tox/config.py", line 938, in _replace_substitution
        val = self._substitute_from_other_section(sub_key)
      File "/nail/home/buck/trees/yelp/venv-update/venv-venv_update/lib/python2.7/site-packages/tox/config.py", line 932, in _substitute_from_other_section
        "substitution key %r not found" % key)
    tox.ConfigError: ConfigError: substitution key 'envsitepackagesdir' not found
    
    $ tox --version
    2.0.1 imported from /nail/home/buck/trees/yelp/venv-update/venv-venv_update/lib/python2.7/site-packages/tox/__init__.pyc
    
  2. Florian Bruhin

    I can confirm. I currently use {envdir}/Lib/site-packages instead because I only need it to set an environment variable which is only needed on Windows.

  3. Florian Bruhin

    This is caused by the changes in 7f1bcc9.

    I might give fixing this a try later this or next week, but I'm a bit busy right now - so I hope someone else will have the time to look at it :)

  4. Florian Bruhin

    I don't really know how to fix this, as I don't fully understand the change in 7f1bcc9.

    I tried this, but it broke pretty much everything ;)

    diff -r 6d4378ce9062 tox/config.py
    --- a/tox/config.py     Mon Jun 15 14:36:26 2015 +0200
    +++ b/tox/config.py     Mon Jun 15 17:21:55 2015 +0200
    @@ -682,6 +682,8 @@
             vc = TestenvConfig(config=config, envname=name, factors=factors, reader=reader)
             reader.addsubstitutions(**subs)
             reader.addsubstitutions(envname=name)
    +        reader.addsubstitutions(envbindir=vc.envbindir, envpython=vc.envpython,
    +                                envsitepackagesdir=vc.envsitepackagesdir)
    
             for env_attr in config._testenv_attr:
                 atype = env_attr.type
    @@ -702,9 +704,6 @@
                 if atype == "path":
                     reader.addsubstitutions(**{env_attr.name: res})
    
    -            if env_attr.name == "install_command":
    -                reader.addsubstitutions(envbindir=vc.envbindir, envpython=vc.envpython,
    -                                        envsitepackagesdir=vc.envsitepackagesdir)
             return vc
    
         def _getenvdata(self, reader):
    

    I also have a test case for this bug, which passes with 1.9.2 and fails with 2.0.x:

    diff -r 6d4378ce9062 tests/test_config.py  
    --- a/tests/test_config.py      Mon Jun 15 14:36:26 2015 +0200  
    +++ b/tests/test_config.py      Mon Jun 15 17:00:22 2015 +0200
    @@ -864,6 +864,18 @@
             assert argv[7][0] == config.homedir.join(".tox", "distshare")
             assert argv[8][0] == conf.envlogdir
    
    +    def test_substitution_notfound_issue246(tmpdir, newconfig):  
    +        config = newconfig("""
    +            [testenv:py27]
    +            setenv =  
    +                FOO={envbindir}  
    +                BAR={envsitepackagesdir}
    +        """)
    +        conf = config.envconfigs['py27']
    +        env = conf.setenv
    +        assert 'FOO' in env
    +        assert 'BAR' in env
    +
         def test_substitution_positional(self, newconfig):
             inisource = """
                 [testenv:py27] 
    
  5. Holger Krekel repo owner

    mention of fix issue246: fix regression in config parsing by reordering such that {envbindir} can be used again in tox.ini. Thanks Olli Walsh.

    → <<cset 7e30b4b4591b>>

  6. Log in to comment