How to create tox.ini variables

2024/9/21 21:16:34

Is there a way to set arbitrary variables within tox.ini?

An example would be a project name that might be used in a variety of ways. With a rather complex tox.ini, I find myself copy and pasting all over where I should just need to set a variable at the top.

For reference, an example tox.ini:

[tox]
envlist = clean, py{27,35,py}, license, style
skipsdist = True
skip_missing_interpreters = True
sitepackages = False[testenv:clean]
deps = coverage
skip_install = true
commands =hash -rfind {toxinidir} -name '*.pyc' -deletefind {toxinidir} -name '__pycache__' -deletecoverage eraserm -Rf {toxinidir}/docs/_build {toxinidir}/docs/coverage {toxinidir}/docs/reports[testenv]
passenv = *
whitelist_externals = *
install_command = {envpython} -m pip install -q --process-dependency-links {opts} {packages}
envdir = {env:WORKON_HOME}/tox-<project_name>/{envname}
sitepackages = False
recreate = True
commands =# hash -rpy{27,35,py}: {envpython} -m pytest --cov-append --cov=<project_name> --html=docs/reports/{envname}-report.html {posargs}smoke: {envpython} -m pytest -m smoke --cov-append --cov=<project_name> --html=docs/reports/{envname}-report.html {posargs}unit: {envpython} -m pytest -m unit --cov-append --cov=<project_name> --html=docs/reports/{envname}-report.html {posargs}integration: {envpython} -m pytest -m integration --long-running --cov-append --cov=<project_name> --html=docs/reports/{envname}-report.html {posargs}requirements: {envpython} -m pytest --cov-append --cov=<project_name> --html=docs/reports/{envname}-report.html {posargs}license: {envpython} -m pytest -m license --license --cov-append --html=docs/reports/{envname}-report.html {posargs}py{27,35,py}-smoke: {envpython} -m pytest -m smoke --cov-append --cov=<project_name> --html=docs/reports/{envname}-report.html {posargs}py{27,35,py}-unit: {envpython} -m pytest -m unit --cov-append --cov=<project_name> --html=docs/reports/{envname}-report.html {posargs}py{27,35,py}-integration: {envpython} -m pytest -m integration --long-running --cov-append --cov=<project_name> --html=docs/reports/{envname}-report.html {posargs}py{27,35,py}-requirements: {envpython} -m pytest --cov-append --cov=<project_name> --html=docs/reports/{envname}-report.html {posargs}py{27,35,py}-license: {envpython} -m pytest -m license --cov-append --html=docs/reports/{envname}-report.html {posargs}
deps =--editable=file:///{toxinidir}[tests]--editable=file:///{toxinidir}py{27,35,py}-requirements: -r{toxinidir}/requirements.txt[testenv:coverage-report]
deps = coverage
skip_install = true
whitelist_externals = *
commands =hash -rcoverage combinecoverage report -m[testenv:docs]
sitepackages = False
whitelist_externals = *
recreate = True
deps = --editable=file:///{toxinidir}[docs]
commands =hash -rcoverage html --directory=docs/coveragecoverage html{envpython} setup.py build_sphinx[testenv:style]
whitelist_externals = *
sitepackages = False
recreate = True
commands =py.test -q --flake8 <project_name>/ --html=docs/reports/{envname}-report.html {posargs}[testenv:vagrant]
passenv = *
whitelist_externals = *
sitepackages = False
recreate = False
skip_install = true
changedir = {toxinidir}/provision/vagrant
commands =hash -rvagrant destroy --forcevagrant up
Answer

You can refer to variables within tox.ini with {[section]varname}.

This is an example of how you can work with the variable ignore_list:

[main]
ignore_list = "E201,E202,E203,E221,E231,E241,E265,E266,E272,E402,W293,W391"[testenv]
commands =pep8 \--max-line-length=120 \--ignore={[main]ignore_list}      
https://en.xdnf.cn/q/71984.html

Related Q&A

How to apply json_normalize on entire pandas column

I have a dataframe with LISTS(with dicts) as column values . My intention is to normalize entire column(all rows). I found way to normalize a single row . However, Im unable to apply the same function …

Configure Vs code version 2.0.0 Build Task for python

I need help in configuring my Vs code to run scripts in python using Cntrl Shift B, I was working fine until Vs code upgraded to version 2.0.0 now it wants me to configure the Build. And I am clueless…

Generate N-Grams from strings with pandas

I have a DataFrame df like this: Pattern String 101 hi, how are you? 104 what are you doing? 108 Python is good to learn.I want to crea…

Merge dataframes on multiple columns with fuzzy match in Python

I have two example dataframes as follows:df1 = pd.DataFrame({Name: {0: John, 1: Bob, 2: Shiela}, Degree: {0: Masters, 1: Graduate, 2: Graduate}, Age: {0: 27, 1: 23, 2: 21}}) df2 = pd.DataFrame({Name: {…

Prevent Celery Beat from running the same task

I have a scheduled celery running tasks every 30 seconds. I have one that runs as task daily, and another one that runs weekly on a user specified time and day of the week. It checks for the "star…

Tastypie with application/x-www-form-urlencoded

Im having a bit of difficulty figuring out what my next steps should be. I am using tastypie to create an API for my web application. From another application, specifically ifbyphone.com, I am receivin…

Check for areas that are too thin in an image

I am trying to validate black and white images (more of a clipart images - not photos) for an engraving machine. One of the major things I need to take into consideration is the size of areas (or width…

Sort Python Dictionary by Absolute Value of Values

Trying to build off of the advice on sorting a Python dictionary here, how would I go about printing a Python dictionary in sorted order based on the absolute value of the values?I have tried:sorted(m…

impyla hangs when connecting to HiveServer2

Im writing some ETL flows in Python that, for part of the process, use Hive. Clouderas impyla client, according to the documentation, works with both Impala and Hive.In my experience, the client worked…

django prevent delete of model instance

I have a models.Model subclass which represents a View on my mysql database (ie managed=False).However, when running my unit tests, I get:DatabaseError: (1288, The target table my_view_table of the DEL…