Change theme.ini format to support Python ConfigParser defaults
See original GitHub issueI think the theme.ini file should be able to be loaded with ConfigParser defaults. It currently cannot.
Expected
- Default ConfigParser will load theme.ini without exception
- Values will not have quotes around them
- PyCharm will not show errors in the ui due to keys starting with spaces
Actual
- theme.ini raises
configparser.MissingSectionHeaderError: File contains no section headers.
because the contents do not start with a section header. It starts with keys. - Because values have quotes around them, when printing the values, the quotes remain by default
- PyCharm highlights in red,
name
under theauthor
section. Removing the leading spaces removes this error/warning.
Steps to repro
code
from configparser import ConfigParser
parser = ConfigParser()
with open("theme.ini", 'r', encoding='utf-8') as f:
parser.readfp(f)
print(parser)
sample config
name = "ThemeName"
license = "MIT"
licenselink = "https://google.com"
description = "Simple Theme "
homepage = "https://github.com"
tags = ["simple", "minimal", "blog"]
features = ["blog"]
lektor_required_version = 3.1
[author]
name = "foobar"
homepage = "http://github.io/"
[original]
author = "origAuthor"
homepage = "https://github.com"
repo = "https://github.com/repo"
[packages]
lektor-disqus-comments = 0.2
Suggestion
- Require all keys be in sections
- Do not quote values
- Do not start keys with leading spaces
- EDIT: Lists/Arrays should just be a CSV string
Sample Suggested theme.ini
[theme]
name = ThemeName
license = MIT
licenselink = https://google.com
description = Simple Theme
homepage = https://github.com
tags = simple, minimal, blog
features = blog,
lektor_required_version = 3.1
[author]
name = foobar
homepage = http://github.io/
[original]
author = origAuthor
homepage = https://github.com
repo = https://github.com/repo
[packages]
lektor-disqus-comments = 0.2
Issue Analytics
- State:
- Created 5 years ago
- Comments:12 (8 by maintainers)
Top Results From Across the Web
configparser — Configuration file parser — Python 3.11.1 ...
Supported INI File Structure By default, section names are case sensitive but keys are not 1. Leading and trailing whitespace is removed from...
Read more >How to read and write INI file with Python3? - Stack Overflow
This can be something to start with: import configparser config = configparser.ConfigParser() config.read('FILE.INI') print(config['DEFAULT']['path']) ...
Read more >Configuring Python Projects with INI, TOML, YAML, and ENV ...
Explore Python project configs by diving into INI, TOML, YAML, and ENV file formats. Find the configuration format which suits your project and...
Read more >configparser 5.3.1.dev22+ga277231.d20221217 documentation
Write the configuration state in .ini format. If `space_around_delimiters' is True (the default), delimiters between keys and values are surrounded by spaces.
Read more >Chapter 14 - configparser — Python 101 1.0 documentation
To read an option in your config file, we call our ConfigParser object's get method, passing it the section name and the option...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
There is currently nothing public that parses this file yet, but @Andrew-Shay is working on a private plugin for lektor-website that would use it, and of course the other theme tickets would start using it.
I want to stay consistent with what we’re doing elsewhere in this project. We don’t currently (and likely won’t for a while if ever) support alternatives to inis elsewhere in lektor, and they shouldn’t be supported here separately.
If you look through the docs, you’ll see the de facto standard in lektor projects is to use csv strings instead of arrays. Good catch. So that’s the way we should do it in these files too.
This is completed as far as this repo is concerned in #601, and nearly complete everywhere. I’ve done all I can. I pulled your PRs @Andrew-Shay, updated the lektor-themes readme, and my own theme, and submitted a few quick PRs to the other themes, owned by @Andrew-Shay, @rlaverde, and @hannylicious.