refactor: use yaml.v3 everywhere and remove dependency on yaml.v2

This commit is contained in:
5684185+vsariola@users.noreply.github.com
2025-10-19 17:13:00 +03:00
parent f4bb2bc754
commit 8e99c93d14
7 changed files with 20 additions and 11 deletions

3
go.mod
View File

@ -12,8 +12,7 @@ require (
github.com/viterin/vek v0.4.2
gitlab.com/gomidi/midi/v2 v2.2.10
golang.org/x/exp/shiny v0.0.0-20250408133849-7e4ce0ab07d0
golang.org/x/text v0.24.0
gopkg.in/yaml.v2 v2.3.0
golang.org/x/text v0.24.0
gopkg.in/yaml.v3 v3.0.1
pipelined.dev/audio/vst2 v0.10.1-0.20240223162706-41e9b65fb5c2
)

View File

@ -1,6 +1,7 @@
package gioui
import (
"bytes"
_ "embed"
"fmt"
"strconv"
@ -10,7 +11,7 @@ import (
"gioui.org/io/event"
"gioui.org/io/key"
"github.com/vsariola/sointu/tracker"
"gopkg.in/yaml.v2"
"gopkg.in/yaml.v3"
)
type (
@ -31,7 +32,9 @@ var defaultKeyBindings []byte
func init() {
var keyBindings, userKeybindings []KeyBinding
if err := yaml.UnmarshalStrict(defaultKeyBindings, &keyBindings); err != nil {
dec := yaml.NewDecoder(bytes.NewReader(defaultKeyBindings))
dec.KnownFields(true)
if err := dec.Decode(&keyBindings); err != nil {
panic(fmt.Errorf("failed to unmarshal default keybindings: %w", err))
}
if err := ReadCustomConfig("keybindings.yml", &userKeybindings); err == nil {

View File

@ -1,12 +1,13 @@
package gioui
import (
"bytes"
_ "embed"
"fmt"
"os"
"path/filepath"
"gopkg.in/yaml.v2"
"gopkg.in/yaml.v3"
"gioui.org/unit"
)
@ -53,7 +54,9 @@ func ReadCustomConfig(filename string, target any) error {
// return at least the default config, and the warning will just tell if there
// was a problem parsing the custom config.
func ReadConfig(defaultConfig []byte, path string, target any) (warn error) {
if err := yaml.UnmarshalStrict(defaultConfig, target); err != nil {
dec := yaml.NewDecoder(bytes.NewReader(defaultConfig))
dec.KnownFields(true)
if err := dec.Decode(target); err != nil {
panic(fmt.Errorf("ReadConfig %v failed to unmarshal the embedded default config: %w", path, err))
}
return ReadCustomConfig(path, target)

View File

@ -10,7 +10,7 @@ import (
"github.com/vsariola/sointu"
"github.com/vsariola/sointu/vm"
"gopkg.in/yaml.v2"
"gopkg.in/yaml.v3"
)
type (

View File

@ -1,6 +1,7 @@
package tracker
import (
"bytes"
"embed"
"io/fs"
"os"
@ -12,7 +13,7 @@ import (
"github.com/vsariola/sointu"
"github.com/vsariola/sointu/vm"
"gopkg.in/yaml.v2"
"gopkg.in/yaml.v3"
)
//go:generate go run generate/gmdls_entries.go
@ -169,7 +170,10 @@ func (m *Presets) loadPresetsFromFs(fsys fs.FS, userDefined bool, seenDir map[st
return nil
}
var instr sointu.Instrument
if yaml.UnmarshalStrict(data, &instr) == nil {
dec := yaml.NewDecoder(bytes.NewReader(data))
dec.KnownFields(true)
if dec.Decode(&instr) == nil {
noExt := path[:len(path)-len(filepath.Ext(path))]
splitted := splitPath(noExt)
splitted = splitted[1:] // remove "presets" from the path

View File

@ -15,7 +15,7 @@ import (
"github.com/vsariola/sointu"
"github.com/vsariola/sointu/vm/compiler/bridge"
"gopkg.in/yaml.v2"
"gopkg.in/yaml.v3"
// TODO: test the song using a mocks instead
)

View File

@ -16,7 +16,7 @@ import (
"github.com/vsariola/sointu"
"github.com/vsariola/sointu/vm"
"gopkg.in/yaml.v2"
"gopkg.in/yaml.v3"
)
const errorThreshold = 1e-2