question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Change theme.ini format to support Python ConfigParser defaults

See original GitHub issue

I think the theme.ini file should be able to be loaded with ConfigParser defaults. It currently cannot.

Expected

  1. Default ConfigParser will load theme.ini without exception
  2. Values will not have quotes around them
  3. PyCharm will not show errors in the ui due to keys starting with spaces

Actual

  1. theme.ini raises configparser.MissingSectionHeaderError: File contains no section headers. because the contents do not start with a section header. It starts with keys.
  2. Because values have quotes around them, when printing the values, the quotes remain by default
  3. PyCharm highlights in red, name under the author 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

  1. Require all keys be in sections
  2. Do not quote values
  3. Do not start keys with leading spaces
  4. 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:closed
  • Created 5 years ago
  • Comments:12 (8 by maintainers)

github_iconTop GitHub Comments

1reaction
nixjdmcommented, Sep 25, 2018

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.

0reactions
nixjdmcommented, Oct 1, 2018

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.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found