Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/jayvdb/tox-backticks
tox-backticks allows use of backticks within setenv to run commands to populate environment variables that can then be accessed using {env:var}
https://github.com/jayvdb/tox-backticks
backticks bash environment-variables shell tox tox-plugin
Last synced: 20 days ago
JSON representation
tox-backticks allows use of backticks within setenv to run commands to populate environment variables that can then be accessed using {env:var}
- Host: GitHub
- URL: https://github.com/jayvdb/tox-backticks
- Owner: jayvdb
- License: mit
- Created: 2019-05-21T02:17:04.000Z (over 5 years ago)
- Default Branch: master
- Last Pushed: 2022-02-22T23:30:13.000Z (over 2 years ago)
- Last Synced: 2023-12-19T17:09:40.519Z (11 months ago)
- Topics: backticks, bash, environment-variables, shell, tox, tox-plugin
- Language: Python
- Homepage: https://pypi.org/project/tox-backticks/
- Size: 14.6 KB
- Stars: 5
- Watchers: 5
- Forks: 3
- Open Issues: 13
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# tox-backticks
tox-backticks allows use of backticks within `setenv` to run commands
to populate environment variables that can then be accessed using `{env:var}`.```ini
[testenv:simple]
setenv =
FOO=`python -c 'import sys; sys.stdout.write("foo")'`
commands =
python -c 'assert "{env:FOO}" == "foo"'
```Commands within the backticks follow the standard tox rules, where
it must be an executable installed into the venv, or be an executable
permitted using `whitelist_externals`.To reduce the impact on the tox syntax, the backticks must enclose the
entire setenv line. Due to this choice, this plugin will only break
existing tox usage where a user wanted an environment variable which
started and ended with a literal backtick, deemed rather unlikely
and judged to be foolish anyway. If that is truely needed, the following
approach allows literal backticks at start and end.[testenv:literal_ignored]
setenv =
BACKTICK=`
INNERBACKTICK=``{env:BACKTICK}
commands =
python -c 'assert "{env:INNERBACKTICKS}" == "```"'To use backticks for a part of a variable, use multiple setenv.
The order of setenv is irrelevant.```ini
[testenv:nested_reversed]
setenv =
BAR=`{env:FOO} -c 'import sys; sys.stdout.write("foo")'`
FOO=`python -c 'import sys; sys.stdout.write("python")'`
commands =
python -c 'assert "{env:BAR}" == "foo"'
```Tox will report an error if multiple setenv are recursively defined,
preventing the correct order from being established.See [`tests/tox.ini`](tests/tox.ini) for samples.
## Contributing
Please do not create an issue requesting using backticks within `commands`.
While it can result in a neater `tox.ini`, the same effect can be achieved
using `setenv` and testenv that depend on other testenv.If you can find a way to correctly intercept and process backticks between
each command execution of a testenv with multiple commands, I will be keen
to merge a patch as long as the new functionality is disabled by default.
i.e. the backticks in the second command must be able to use state created
by the first command, otherwise backticks in commands is useless.The next problem with backticks within `commands` is that literal backticks
within in the commands, which is why it must be off by default, at least
initially. One non-intrusive semantics is to allow commands of form
```bash
export VAR=`do_stuff`
```
That line is useless in tox, as it wouldnt have any effect,
and is easily parsable.