From dca9fcb7dc521a2c7369c613e52e36fc7fa65e67 Mon Sep 17 00:00:00 2001 From: Neil Mayhew Date: Fri, 31 Jan 2020 14:35:12 -0700 Subject: [PATCH] Restore the ability to use inline comments in config files The ability was lost in the switch to Python 3, because the config parser module in the standard library changed its defaults. [Python 2][2]: > Comments may appear on their own in an otherwise empty line, or > may be entered in lines holding values or section names. [Python 3][3]: > Inline comments can be harmful because they prevent users > from using the delimiting characters as parts of values. > That being said, this can be customized. [2]: https://docs.python.org/2/library/configparser.html#module-ConfigParser [3]: https://docs.python.org/3/library/configparser.html#supported-ini-file-structure Signed-off-by: Neil Mayhew --- README.md | 4 ++-- whipper/common/config.py | 3 ++- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index f7ce25a..eda1875 100644 --- a/README.md +++ b/README.md @@ -229,13 +229,13 @@ The configuration file is stored in `$XDG_CONFIG_HOME/whipper/whipper.conf`, or See [XDG Base Directory Specification](http://standards.freedesktop.org/basedir-spec/basedir-spec-latest.html) -and [ConfigParser](https://docs.python.org/3/library/configparser.html). +and [ConfigParser](https://docs.python.org/3/library/configparser.html) with `inline_comment_prefixes=(';')`. The configuration file consists of newline-delineated `[sections]` containing `key = value` pairs. The sections `[main]` and `[musicbrainz]` are special config sections for options not accessible from the command line interface. Sections beginning with `drive` are -written by whipper; certain values should not be edited. +written by whipper; certain values should not be edited. Inline comments can be added using `;`. Example configuration demonstrating all `[main]` and `[musicbrainz]` options: diff --git a/whipper/common/config.py b/whipper/common/config.py index afaac7c..57b1986 100644 --- a/whipper/common/config.py +++ b/whipper/common/config.py @@ -36,7 +36,8 @@ class Config: def __init__(self, path=None): self._path = path or directory.config_path() - self._parser = configparser.ConfigParser() + self._parser = configparser.ConfigParser( + inline_comment_prefixes=(';')) self.open()