Skip to content

✨ feat(config): add --format json/toml and -o to config command - #3857

Merged
gaborbernat merged 1 commit into
tox-dev:mainfrom
gaborbernat:3854
Mar 5, 2026
Merged

gaborbernat merged 1 commit into
tox-dev:mainfrom
gaborbernat:3854

Conversation

@gaborbernat

Copy link
Copy Markdown
Member

There is currently no reliable programmatic way to retrieve tox environment configuration. The tox config command outputs colored INI-style text that's difficult for tools, scripts, and CI pipelines to consume. This forces users to resort to fragile regex parsing or screen-scraping to extract configuration values. Closes #3854

The config command now accepts --format (ini, json, toml) and -o/--output-file flags. ✨ JSON and TOML output preserves native types (booleans, integers, floats, arrays, dicts) and uses the same key structure as tox.toml — env.<name> for environments, tox for core settings — so the output schema feels familiar to anyone already writing tox configuration in TOML. Both structured formats get syntax highlighting on stdout matching the existing INI color behavior, while file output via -o is always clean for machine consumption. A new jsonify() function in src/tox/config/loader/jsonify.py handles the type conversion, parallel to the existing stringify().

📝 Documentation across all three Diataxis dimensions (tutorial, how-to, explanation) has been updated with tabbed examples showing INI, JSON, and TOML output side by side. The tomli-w package is added as a dependency for TOML serialization. All existing -k, --core, and -e flags compose naturally with the new format options.

There was no reliable programmatic way to retrieve tox environment
configuration. The existing `tox config` output is colored INI text
that's difficult for tools, scripts, and CI pipelines to consume.

The config command now accepts --format (ini/json/toml) and
-o/--output-file flags. JSON and TOML output preserves native types
and uses the same key structure as tox.toml (env.<name> for
environments, tox for core settings). Both structured formats get
syntax highlighting on stdout; file output via -o is always clean.

Splits show_config into a package with per-format modules. Adds
tomli-w as a dependency for TOML serialization. Also adds uv_seed
to env_run_base in tox.toml to fix provision test failures, and
normalizes version-specific pragma comments to covdefaults format
(>=3.11 cover / <3.11 cover).

Closes tox-dev#3854
@gaborbernat
gaborbernat merged commit 4c72887 into tox-dev:main Mar 5, 2026
48 of 49 checks passed
rares985 added a commit to rares985/tox that referenced this pull request Mar 6, 2026
…fig (tox-dev#3866)

The refactoring in tox-dev#3857 added config_format and output_file options to the
config command, but the legacy --showconfig flag handler didn't initialize
these new attributes before calling show_config(), causing an AttributeError.

This fix initializes both attributes with their default values (ini format
and no output file) when using the legacy --showconfig or --help-ini flags,
maintaining backward compatibility.

Fixes tox-dev#3866
rares985 added a commit to rares985/tox that referenced this pull request Mar 6, 2026
…fig (tox-dev#3866)

The refactoring in tox-dev#3857 added config_format and output_file options to the
config command, but the legacy --showconfig flag handler didn't initialize
these new attributes before calling show_config(), causing an AttributeError.

This fix initializes both attributes with their default values (ini format
and no output file) when using the legacy --showconfig or --help-ini flags,
maintaining backward compatibility.

Fixes tox-dev#3866
rares985 added a commit to rares985/tox that referenced this pull request Mar 6, 2026
The refactoring in tox-dev#3857 added config_format and output_file options to the
config command, but the legacy --showconfig flag handler didn't initialize
these new attributes before calling show_config(), causing an AttributeError.

This fix initializes both attributes with their default values (ini format
and no output file) when using the legacy --showconfig or --help-ini flags,
maintaining backward compatibility.
@gaborbernat
gaborbernat deleted the 3854 branch March 6, 2026 21:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

provide programatic way to retrieve information about tox environments (json)

1 participant