voluptuous-errors 0.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
Metadata-Version: 2.1
|
|
2
|
+
Name: voluptuous_errors
|
|
3
|
+
Version: 0.0
|
|
4
|
+
Summary: report voluptuous errors
|
|
5
|
+
Requires-Python: >=3.6
|
|
6
|
+
Description-Content-Type: text/x-rst
|
|
7
|
+
Requires-Dist: inform
|
|
8
|
+
Requires-Dist: nestedtext>=3.7
|
|
9
|
+
Requires-Dist: voluptuous
|
|
10
|
+
|
|
11
|
+
Voluptuous Errors — Error Reporting for Voluptuous with NestedText and Inform
|
|
12
|
+
=============================================================================
|
|
13
|
+
|
|
14
|
+
.. ignore for now:
|
|
15
|
+
|
|
16
|
+
.. image:: https://pepy.tech/badge/voluptuous_errors/month
|
|
17
|
+
:target: https://pepy.tech/project/voluptuous_errors
|
|
18
|
+
|
|
19
|
+
.. image:: https://github.com/KenKundert/voluptuous_errors/actions/workflows/build.yaml/badge.svg
|
|
20
|
+
:target: https://github.com/KenKundert/voluptuous_errors/actions/workflows/build.yaml
|
|
21
|
+
|
|
22
|
+
.. image:: https://coveralls.io/repos/github/KenKundert/voluptuous_errors/badge.svg?branch=master
|
|
23
|
+
:target: https://coveralls.io/github/KenKundert/voluptuous_errors?branch=master
|
|
24
|
+
|
|
25
|
+
.. image:: https://img.shields.io/pypi/v/voluptuous_errors.svg
|
|
26
|
+
:target: https://pypi.python.org/pypi/voluptuous_errors
|
|
27
|
+
|
|
28
|
+
.. image:: https://img.shields.io/pypi/pyversions/voluptuous_errors.svg
|
|
29
|
+
:target: https://pypi.python.org/pypi/voluptuous_errors/
|
|
30
|
+
|
|
31
|
+
:Author: Ken Kundert
|
|
32
|
+
:Version: 0.0.0
|
|
33
|
+
:Released: 2024-02-25
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
A convenience function used for reporting voluptuous_ errors from nestedtext_
|
|
37
|
+
with inform_. Here is a typical use of this function::
|
|
38
|
+
|
|
39
|
+
>>> from voluptuous import Schema, Invalid, MultipleInvalid, Required
|
|
40
|
+
>>> from voluptuous_errors import report_voluptuous_errors
|
|
41
|
+
>>> from inform import error, os_error, terminate
|
|
42
|
+
>>> import nestedtext as nt
|
|
43
|
+
|
|
44
|
+
>>> try:
|
|
45
|
+
... settings_path = Path('settings.nt')
|
|
46
|
+
... settings = nt.load(
|
|
47
|
+
... settings_path,
|
|
48
|
+
... keymap = (keymap:={}),
|
|
49
|
+
... )
|
|
50
|
+
... settings = schema(settings)
|
|
51
|
+
>>> except nt.NestedTextError as e:
|
|
52
|
+
... e.report()
|
|
53
|
+
>>> except MultipleInvalid as e:
|
|
54
|
+
... report_voluptuous_errors(e, keymap, settings_path)
|
|
55
|
+
>>> except OSError as e:
|
|
56
|
+
... error(os_error(e))
|
|
57
|
+
>>> terminate()
|
|
58
|
+
|
|
59
|
+
This code will report all errors found by Voluptuous when reading the settings
|
|
60
|
+
file.
|
|
61
|
+
|
|
62
|
+
|
|
63
|
+
Releases
|
|
64
|
+
--------
|
|
65
|
+
|
|
66
|
+
**Latest development release**:
|
|
67
|
+
| Version: 0.5.0
|
|
68
|
+
| Released: 2022-09-02
|
|
69
|
+
|
|
70
|
+
**0.0 (2024-02-25)**:
|
|
71
|
+
Initial version.
|
|
72
|
+
|
|
73
|
+
.. _voluptuous: https://github.com/alecthomas/voluptuous
|
|
74
|
+
.. _nestedtext: https://nestedtext.org
|
|
75
|
+
.. _inform: https://readthedocs.io/inform
|
|
76
|
+
|
|
77
|
+
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
Voluptuous Errors — Error Reporting for Voluptuous with NestedText and Inform
|
|
2
|
+
=============================================================================
|
|
3
|
+
|
|
4
|
+
.. ignore for now:
|
|
5
|
+
|
|
6
|
+
.. image:: https://pepy.tech/badge/voluptuous_errors/month
|
|
7
|
+
:target: https://pepy.tech/project/voluptuous_errors
|
|
8
|
+
|
|
9
|
+
.. image:: https://github.com/KenKundert/voluptuous_errors/actions/workflows/build.yaml/badge.svg
|
|
10
|
+
:target: https://github.com/KenKundert/voluptuous_errors/actions/workflows/build.yaml
|
|
11
|
+
|
|
12
|
+
.. image:: https://coveralls.io/repos/github/KenKundert/voluptuous_errors/badge.svg?branch=master
|
|
13
|
+
:target: https://coveralls.io/github/KenKundert/voluptuous_errors?branch=master
|
|
14
|
+
|
|
15
|
+
.. image:: https://img.shields.io/pypi/v/voluptuous_errors.svg
|
|
16
|
+
:target: https://pypi.python.org/pypi/voluptuous_errors
|
|
17
|
+
|
|
18
|
+
.. image:: https://img.shields.io/pypi/pyversions/voluptuous_errors.svg
|
|
19
|
+
:target: https://pypi.python.org/pypi/voluptuous_errors/
|
|
20
|
+
|
|
21
|
+
:Author: Ken Kundert
|
|
22
|
+
:Version: 0.0.0
|
|
23
|
+
:Released: 2024-02-25
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
A convenience function used for reporting voluptuous_ errors from nestedtext_
|
|
27
|
+
with inform_. Here is a typical use of this function::
|
|
28
|
+
|
|
29
|
+
>>> from voluptuous import Schema, Invalid, MultipleInvalid, Required
|
|
30
|
+
>>> from voluptuous_errors import report_voluptuous_errors
|
|
31
|
+
>>> from inform import error, os_error, terminate
|
|
32
|
+
>>> import nestedtext as nt
|
|
33
|
+
|
|
34
|
+
>>> try:
|
|
35
|
+
... settings_path = Path('settings.nt')
|
|
36
|
+
... settings = nt.load(
|
|
37
|
+
... settings_path,
|
|
38
|
+
... keymap = (keymap:={}),
|
|
39
|
+
... )
|
|
40
|
+
... settings = schema(settings)
|
|
41
|
+
>>> except nt.NestedTextError as e:
|
|
42
|
+
... e.report()
|
|
43
|
+
>>> except MultipleInvalid as e:
|
|
44
|
+
... report_voluptuous_errors(e, keymap, settings_path)
|
|
45
|
+
>>> except OSError as e:
|
|
46
|
+
... error(os_error(e))
|
|
47
|
+
>>> terminate()
|
|
48
|
+
|
|
49
|
+
This code will report all errors found by Voluptuous when reading the settings
|
|
50
|
+
file.
|
|
51
|
+
|
|
52
|
+
|
|
53
|
+
Releases
|
|
54
|
+
--------
|
|
55
|
+
|
|
56
|
+
**Latest development release**:
|
|
57
|
+
| Version: 0.5.0
|
|
58
|
+
| Released: 2022-09-02
|
|
59
|
+
|
|
60
|
+
**0.0 (2024-02-25)**:
|
|
61
|
+
Initial version.
|
|
62
|
+
|
|
63
|
+
.. _voluptuous: https://github.com/alecthomas/voluptuous
|
|
64
|
+
.. _nestedtext: https://nestedtext.org
|
|
65
|
+
.. _inform: https://readthedocs.io/inform
|
|
66
|
+
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
[project]
|
|
2
|
+
name = "voluptuous_errors"
|
|
3
|
+
version = "0.0"
|
|
4
|
+
description = "report voluptuous errors"
|
|
5
|
+
readme = "README.rst"
|
|
6
|
+
requires-python = ">=3.6"
|
|
7
|
+
dependencies = [
|
|
8
|
+
"inform",
|
|
9
|
+
"nestedtext>=3.7",
|
|
10
|
+
"voluptuous",
|
|
11
|
+
]
|
|
12
|
+
|
|
13
|
+
[build-system]
|
|
14
|
+
requires = ["flit_core >=2,<4"]
|
|
15
|
+
build-backend = "flit_core.buildapi"
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
# DESCRIPTION {{{1
|
|
2
|
+
# Provides a convenience function used for reporting voluptuous errors when
|
|
3
|
+
# using with NestedText and inform. Uses Inform's error() function when
|
|
4
|
+
# reporting the errors as it allows for multiple errors to be reported.
|
|
5
|
+
|
|
6
|
+
# IMPORTS {{{1
|
|
7
|
+
from inform import cull, error, full_stop
|
|
8
|
+
import nestedtext as nt
|
|
9
|
+
|
|
10
|
+
# GLOBALS {{{1
|
|
11
|
+
voluptuous_error_msg_mappings = {
|
|
12
|
+
"extra keys not allowed": ("unknown key", "key"),
|
|
13
|
+
"expected a dictionary": ("expected a key-value pair", "value"),
|
|
14
|
+
"required key not provided": ("required key is missing", "value"),
|
|
15
|
+
}
|
|
16
|
+
__version__ = '0.0.0'
|
|
17
|
+
__released__ = '2024-02-25'
|
|
18
|
+
|
|
19
|
+
# report_voluptuous_errors() {{{1
|
|
20
|
+
def report_voluptuous_errors(multiple_invalid, keymap, source=None, sep="›"):
|
|
21
|
+
source = str(source) if source else ""
|
|
22
|
+
|
|
23
|
+
for err in multiple_invalid.errors:
|
|
24
|
+
|
|
25
|
+
# convert message to something easier for non-savvy user to understand
|
|
26
|
+
msg, kind = voluptuous_error_msg_mappings.get(
|
|
27
|
+
err.msg, (err.msg, 'value')
|
|
28
|
+
)
|
|
29
|
+
|
|
30
|
+
# get metadata about error
|
|
31
|
+
if keymap:
|
|
32
|
+
culprit = nt.get_keys(err.path, keymap=keymap, strict="found", sep=sep)
|
|
33
|
+
line_nums = nt.get_line_numbers(err.path, keymap, kind=kind, sep="-", strict=False)
|
|
34
|
+
loc = nt.get_location(err.path, keymap)
|
|
35
|
+
if loc:
|
|
36
|
+
codicil = loc.as_line(kind)
|
|
37
|
+
else: # required key is missing
|
|
38
|
+
missing = nt.get_keys(err.path, keymap, strict="missing", sep=sep)
|
|
39
|
+
codicil = f"‘{missing}’ was not found."
|
|
40
|
+
|
|
41
|
+
file_and_lineno = f"{source!s}@{line_nums}"
|
|
42
|
+
culprit = cull((file_and_lineno, culprit))
|
|
43
|
+
else:
|
|
44
|
+
keys = sep.join(str(c) for c in err.path)
|
|
45
|
+
culprit=cull([source, keys])
|
|
46
|
+
codicil = None
|
|
47
|
+
|
|
48
|
+
# report error
|
|
49
|
+
error(full_stop(msg), culprit=culprit, codicil=codicil)
|