Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Toml Configuration (take 2) #983

Merged
merged 7 commits into from
Jul 17, 2023

Conversation

ryneeverett
Copy link
Collaborator

@ryneeverett ryneeverett commented Mar 19, 2023

Based on #984.

This is a more conservative rewrite of #973 which aims to provide first-class support for both ini and toml configuration.

The biggest user impact is probably documentation, which now includes tabbed code blocks showing both ini and toml format. It can be viewed here: https://bugwarrior-docs.readthedocs.io/en/toml2/index.html. (Note: If I make changes to this branch I have to push separately to this remote to keep this rendering up to date.)

This removes the last of the periods from our option names. This will
not work with toml because periods are interpreted as nested options in
toml. That is to say:

>>> import tomllib
>>> tomllib.loads('log.level = "DEBUG"')
{'log': {'level': 'DEBUG'}}
Now that configurations are dictionaries, we can construct them
declaratively.
Add tomli as a backport of the standard library's new tomllib.

By the way, it's not just a convention to use the `.toml` extension,
it's actually part of the v1.0.0 spec:

> TOML files should use the extension `.toml`.

So we don't need to do any additional logic to determine whether a file
is ini or toml -- if it doesn't have the right extension it literally
isn't toml!
Add pytest-subtests plugin to test dependencies so that pytest will show
the parameters when a subTest fails.

Replace methods that check against specific combinations.

It would be a lot simpler to use pytest.mark.parametrize, which would
eliminate the need for pytest-subtests as well as the manual
setUp/tearDown, but that feature is unavailable for classes inheriting
from TestCase. Converting every class that inherits from ConfigTest to
pytest assertions would be too much extra noise to add to this branch,
which already has a large diff. I'm also not sure it's worth the effort
since it seems like it will take a couple more decades for python to
standardize a testing API. ("setup.py is deprecated; use pyproject.toml
and pick one of the 5 incompatible formats; use pytest as a test runner;
but unittest is in the standard library with a partially incompatible
API...")
Add a new subcommand to automatically convert bugwarriorrc to
bugwarrior.toml.

This commit adds the ini2toml package as a dependency and implements a
custom profile to handle the idiosyncrasies of our bugwarriorrc format.

The only "bug" I've noticed so far with ini2toml is that empty lines are
not preserved. This is the standard behavior of ini2toml due to the
`normalise_newlines` postprocessor, which removes all empty lines and
adds one before each section. However, this seems to be due to the issue
that upstream tomlkit adds lots of arbitrary empty lines (aka
`Whitespace()` and leaving them all would be an even worse result. See
python-poetry/tomlkit#48. This is about as far as
I care to chase this bug down the rabbit hole at the moment.
- Add sphinx-inline-tabs as a development dependency.
- Create a "config" directive for configuration blocks, which converts
  an ini code block into tabs with both configuration languages.
@ryneeverett ryneeverett merged commit ad3f724 into GothenburgBitFactory:develop Jul 17, 2023
24 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant