1

I have a tox environment in which I want to run a bash command (basename) on {posargs} and use the result in a subsequent command. I've tried the various ways it is possible to do this in bash, but they haven't been working. This snippet captures the spirit of what I'm trying to accomplish.

[testenv:docs]
commands =
    export PACKAGE=$(basename {posargs})
    ls $PACKAGE
2
  • Doesn't work with env vars: tox runs every command in a new shell so when the first command finishes the env var disappears. You have to save it somewhere in a permanent storage like a file. Or change approach completely like passing preprocessed {posargs} and use them in all commands down the pipeline. Commented Jul 20, 2020 at 14:26
  • Another thing I tried was ls $(basename {posagrs}) but that doesn't work either because tox doesn't really use a shell. Commented Jul 23, 2020 at 13:37

1 Answer 1

2

This won't work as is. Simply because of what phd said above. The only one way is output through a file. However..

What you could do is:

tox.ini

[testenv:docs]
passenv =
    PACKAGE
whitelist_externals =
    ls
commands =
    ls {env:PACKAGE}

Inside whatever script runs tox..

export PACKAGE=$(basename {posargs})
tox
  • This makes use of tox's variable substitution.
  • The passenv configuration option alows the PACKAGE environment variable to be passed (exist) into tox.
  • The whitelist_externals sections enables commands (ls) not installed by tox (outside it's environment basically).
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.