beetbox / beetbox/beets

Use new configuration "templates" to simplify config handling

Open
#842 0 comments 0 reactions 0 assignees View on GitHub
refactor
Dominant language
Python
Stars
15.7k
Forks
2.1k
Avg merge
4d 21h
Merged PRs (30d)
31

Description

Recently, the [Confit](https://github.com/sampsyo/confit) library we use for configuration was extended to provide template validation in https://github.com/sampsyo/confit/issues/2. Beets could use this to greatly simplify repetitive and overly-verbose config handling code. For example, this:

```
config['import']['log'].as_filename()
```

can instead use this once and for all:

```
import_config = config['import'].get( ... template here ... )
```

to let the specific variable be referenced simply as:

```
import_config.log
```

This could also help with the messier parts of configuration currently handled in the `beets.ui` module, including replacements and path formats, which need to be substantially "parsed" before they're used.

As part of this, it might make sense to write a `Context` class that provides access to the validated configuration. In this case, we would probably do away with the lazy config-reading functionality in Confit. The Context class would need to be constructed for any unit test that touches the configuration.

Contributor guide

Open the contributing guide

Research direction

Start by reading the configuration handling in the beets.ui module and reviewing how Confit currently exposes values. Trace the existing parsing for replacements and path formats, then determine the scope of a validated configuration or Context abstraction. Done means repetitive configuration access is simplified and configuration-dependent unit tests have the required setup.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
cli
Issue type
Refactor
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.