GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — GitHub - AccessibleApps/basic_config: Load and validate ConfigObj settings files against a spec, filling in defaults

BranchesTags
Open more actions menu

Latest commit

 

History

26 Commits
26 Commits

Folders and files

NameName
Last commit message
Last commit date
.hgignore
.hgignore
 
 
README.md
README.md
 
 
basic_config.py
basic_config.py
 
 
pyproject.toml
pyproject.toml
 
 

Repository files navigation

basic_config

Load a settings file, check it against a spec, fill in the defaults, and save it back, all in one call. It's a thin layer over ConfigObj that every Accessible Apps desktop app uses for its settings.

Install

pip install git+https://github.com/accessibleapps/basic_config.git

Needs Python 3.8 or newer. The only dependency is configobj.

Use it

Write a spec describing your settings:

# myapp.confspec
[general]
username = string(default="")
check_for_updates = boolean(default=True)
volume = integer(min=0, max=100, default=50)

Then load the user's file against it:

from basic_config import load_configuration, ConfigLoadError

try:
    config = load_configuration("settings.ini", "myapp.confspec")
except ConfigLoadError:
    ...  # the file is broken or doesn't match the spec

config["general"]["volume"]  # 50 the first time, an int, not a string
config["general"]["volume"] = 80
config.write()

What load_configuration(config_path, configspec_path=None, copy=True, ...) does:

  • Creates the file if it doesn't exist yet.
  • Reads it as UTF-8 and validates it against the spec, converting values to the right types.
  • With copy=True (the default), writes the defaults from the spec into the file, so users can see and edit every setting.
  • Saves the file and returns the ConfigObj.
  • Raises ConfigLoadError if the file can't be parsed or fails validation.

Any extra arguments go straight through to ConfigObj.

License

MIT.

About

Load and validate ConfigObj settings files against a spec, filling in defaults

Topics

configobjconfigurationpythonsettings

Resources

Readme
Activity
Custom properties

Stars

1 star

Watchers

1 watching

Forks

1 fork
Report repository

Releases

Packages

Contributors

Languages

You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.