-
Notifications
You must be signed in to change notification settings - Fork 153
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Carmen Bianca BAKKER <[email protected]>
- Loading branch information
1 parent
a121a6f
commit 206b68f
Showing
4 changed files
with
48 additions
and
2 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,6 +8,8 @@ | |
from gettext import gettext as _ | ||
from typing import Any, Dict, Optional | ||
|
||
import yaml | ||
|
||
|
||
@dataclass | ||
class AnnotateOptions: | ||
|
@@ -49,6 +51,23 @@ def from_dict(cls, value: Dict[str, Any]) -> "Config": | |
] = _annotate_options_from_dict(override) | ||
return config | ||
|
||
@classmethod | ||
def from_yaml(cls, text: str) -> "Config": | ||
"""Parse yaml to generate a Config object. | ||
An example of a yaml file:: | ||
annotate: | ||
default_name: Jane Doe | ||
default_contact: [email protected] | ||
default_license: GPL-3.0-or-later | ||
overrides: | ||
- path: ~/Projects/FSFE | ||
default_contact: [email protected] | ||
""" | ||
return cls.from_dict(yaml.load(text, Loader=yaml.Loader)) | ||
|
||
|
||
def _annotate_options_from_dict(value: Dict[str, str]) -> AnnotateOptions: | ||
return AnnotateOptions( | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,6 +4,8 @@ | |
|
||
"""Tests for some _config.""" | ||
|
||
from inspect import cleandoc | ||
|
||
from reuse._config import Config | ||
|
||
# REUSE-IgnoreStart | ||
|
@@ -61,4 +63,28 @@ def test_config_from_dict_override(): | |
assert result.override_annotate_options["bar"].license == "MIT" | ||
|
||
|
||
def test_config_from_yaml_simple(): | ||
"""Load Config from yaml.""" | ||
text = cleandoc( | ||
""" | ||
annotate: | ||
default_name: Jane Doe | ||
default_contact: [email protected] | ||
default_license: GPL-3.0-or-later | ||
overrides: | ||
- path: ~/Projects/FSFE | ||
default_contact: [email protected] | ||
""" | ||
) | ||
result = Config.from_yaml(text) | ||
assert result.global_annotate_options.name == "Jane Doe" | ||
assert result.global_annotate_options.contact == "[email protected]" | ||
assert result.global_annotate_options.license == "GPL-3.0-or-later" | ||
assert ( | ||
result.override_annotate_options["~/Projects/FSFE"].contact | ||
== "[email protected]" | ||
) | ||
|
||
|
||
# REUSE-IgnoreEnd |