str-to-obj 2023.11__py3-none-any.whl → 2025.1__py3-none-any.whl

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.
str_to_obj/__init__.py CHANGED
@@ -1,35 +1,67 @@
1
- # Copyright CNRS/Inria/UCA
2
- # Contributor(s): Eric Debreuve (since 2023)
3
- #
4
- # eric.debreuve@cnrs.fr
5
- #
6
- # This software is governed by the CeCILL license under French law and
7
- # abiding by the rules of distribution of free software. You can use,
8
- # modify and/ or redistribute the software under the terms of the CeCILL
9
- # license as circulated by CEA, CNRS and INRIA at the following URL
10
- # "http://www.cecill.info".
11
- #
12
- # As a counterpart to the access to the source code and rights to copy,
13
- # modify and redistribute granted by the license, users are provided only
14
- # with a limited warranty and the software's author, the holder of the
15
- # economic rights, and the successive licensors have only limited
16
- # liability.
17
- #
18
- # In this respect, the user's attention is drawn to the risks associated
19
- # with loading, using, modifying and/or developing or reproducing the
20
- # software by the user in light of its specific status of free software,
21
- # that may mean that it is complicated to manipulate, and that also
22
- # therefore means that it is reserved for developers and experienced
23
- # professionals having in-depth computer knowledge. Users are therefore
24
- # encouraged to load and test the software's suitability as regards their
25
- # requirements in conditions enabling the security of their systems and/or
26
- # data to be ensured and, more generally, to use and operate it in the
27
- # same conditions as regards security.
28
- #
29
- # The fact that you are presently reading this means that you have had
30
- # knowledge of the CeCILL license and that you accept its terms.
1
+ """
2
+ Copyright CNRS/Inria/UniCA
3
+ Contributor(s): Eric Debreuve (eric.debreuve@cnrs.fr) since 2023
4
+ SEE COPYRIGHT NOTICE BELOW
5
+ """
6
+
7
+ try:
8
+ from beartype.claw import beartype_this_package # noqa
9
+ except ModuleNotFoundError:
10
+ pass
11
+ else:
12
+ import site
13
+ from pathlib import Path as path_t
14
+ paths = site.getsitepackages() + [site.getusersitepackages()]
15
+ folder = path_t(__file__).parent
16
+ if folder not in paths:
17
+ beartype_this_package()
31
18
 
32
19
  from str_to_obj.main import ObjectFromStr
33
- from str_to_obj.task.casting import CastValue
34
- from str_to_obj.type.annotation import annotation_t
20
+ from str_to_obj.runtime.value import INVALID_VALUE
35
21
  from str_to_obj.version import __version__
22
+
23
+ """
24
+ COPYRIGHT NOTICE
25
+
26
+ This software is governed by the CeCILL license under French law and
27
+ abiding by the rules of distribution of free software. You can use,
28
+ modify and/ or redistribute the software under the terms of the CeCILL
29
+ license as circulated by CEA, CNRS and INRIA at the following URL
30
+ "http://www.cecill.info".
31
+
32
+ As a counterpart to the access to the source code and rights to copy,
33
+ modify and redistribute granted by the license, users are provided only
34
+ with a limited warranty and the software's author, the holder of the
35
+ economic rights, and the successive licensors have only limited
36
+ liability.
37
+
38
+ In this respect, the user's attention is drawn to the risks associated
39
+ with loading, using, modifying and/or developing or reproducing the
40
+ software by the user in light of its specific status of free software,
41
+ that may mean that it is complicated to manipulate, and that also
42
+ therefore means that it is reserved for developers and experienced
43
+ professionals having in-depth computer knowledge. Users are therefore
44
+ encouraged to load and test the software's suitability as regards their
45
+ requirements in conditions enabling the security of their systems and/or
46
+ data to be ensured and, more generally, to use and operate it in the
47
+ same conditions as regards security.
48
+
49
+ The fact that you are presently reading this means that you have had
50
+ knowledge of the CeCILL license and that you accept its terms.
51
+
52
+ SEE LICENCE NOTICE: file README-LICENCE-utf8.txt at project source root.
53
+
54
+ This software is being developed by Eric Debreuve, a CNRS employee and
55
+ member of team Morpheme.
56
+ Team Morpheme is a joint team between Inria, CNRS, and UniCA.
57
+ It is hosted by the Centre Inria d'Université Côte d'Azur, Laboratory
58
+ I3S, and Laboratory iBV.
59
+
60
+ CNRS: https://www.cnrs.fr/index.php/en
61
+ Inria: https://www.inria.fr/en/
62
+ UniCA: https://univ-cotedazur.eu/
63
+ Centre Inria d'Université Côte d'Azur: https://www.inria.fr/en/centre/sophia/
64
+ I3S: https://www.i3s.unice.fr/en/
65
+ iBV: http://ibv.unice.fr/
66
+ Team Morpheme: https://team.inria.fr/morpheme/
67
+ """
@@ -0,0 +1,58 @@
1
+ """
2
+ Copyright CNRS/Inria/UniCA
3
+ Contributor(s): Eric Debreuve (eric.debreuve@cnrs.fr) since 2023
4
+ SEE COPYRIGHT NOTICE BELOW
5
+ """
6
+
7
+ from str_to_obj.catalog.boolean import boolean_mode_e, boolean_t
8
+ from str_to_obj.catalog.callable import callable_t
9
+ from str_to_obj.catalog.choices import choices_t
10
+ from str_to_obj.catalog.collection import collection_t
11
+ from str_to_obj.catalog.number import number_t
12
+ from str_to_obj.catalog.path import path_purpose_e, path_t, path_type_e
13
+
14
+ """
15
+ COPYRIGHT NOTICE
16
+
17
+ This software is governed by the CeCILL license under French law and
18
+ abiding by the rules of distribution of free software. You can use,
19
+ modify and/ or redistribute the software under the terms of the CeCILL
20
+ license as circulated by CEA, CNRS and INRIA at the following URL
21
+ "http://www.cecill.info".
22
+
23
+ As a counterpart to the access to the source code and rights to copy,
24
+ modify and redistribute granted by the license, users are provided only
25
+ with a limited warranty and the software's author, the holder of the
26
+ economic rights, and the successive licensors have only limited
27
+ liability.
28
+
29
+ In this respect, the user's attention is drawn to the risks associated
30
+ with loading, using, modifying and/or developing or reproducing the
31
+ software by the user in light of its specific status of free software,
32
+ that may mean that it is complicated to manipulate, and that also
33
+ therefore means that it is reserved for developers and experienced
34
+ professionals having in-depth computer knowledge. Users are therefore
35
+ encouraged to load and test the software's suitability as regards their
36
+ requirements in conditions enabling the security of their systems and/or
37
+ data to be ensured and, more generally, to use and operate it in the
38
+ same conditions as regards security.
39
+
40
+ The fact that you are presently reading this means that you have had
41
+ knowledge of the CeCILL license and that you accept its terms.
42
+
43
+ SEE LICENCE NOTICE: file README-LICENCE-utf8.txt at project source root.
44
+
45
+ This software is being developed by Eric Debreuve, a CNRS employee and
46
+ member of team Morpheme.
47
+ Team Morpheme is a joint team between Inria, CNRS, and UniCA.
48
+ It is hosted by the Centre Inria d'Université Côte d'Azur, Laboratory
49
+ I3S, and Laboratory iBV.
50
+
51
+ CNRS: https://www.cnrs.fr/index.php/en
52
+ Inria: https://www.inria.fr/en/
53
+ UniCA: https://univ-cotedazur.eu/
54
+ Centre Inria d'Université Côte d'Azur: https://www.inria.fr/en/centre/sophia/
55
+ I3S: https://www.i3s.unice.fr/en/
56
+ iBV: http://ibv.unice.fr/
57
+ Team Morpheme: https://team.inria.fr/morpheme/
58
+ """
str_to_obj/api/type.py ADDED
@@ -0,0 +1,58 @@
1
+ """
2
+ Copyright CNRS/Inria/UniCA
3
+ Contributor(s): Eric Debreuve (eric.debreuve@cnrs.fr) since 2023
4
+ SEE COPYRIGHT NOTICE BELOW
5
+ """
6
+
7
+ from str_to_obj.runtime.type import ANY_TYPE
8
+ from str_to_obj.task.casting import CastValue
9
+ from str_to_obj.task.comparison import TypesAreCompatible
10
+ from str_to_obj.type.annotation import annotation_t
11
+ from str_to_obj.type.hint_tree import hint_t
12
+ from str_to_obj.type.type import type_t
13
+
14
+ """
15
+ COPYRIGHT NOTICE
16
+
17
+ This software is governed by the CeCILL license under French law and
18
+ abiding by the rules of distribution of free software. You can use,
19
+ modify and/ or redistribute the software under the terms of the CeCILL
20
+ license as circulated by CEA, CNRS and INRIA at the following URL
21
+ "http://www.cecill.info".
22
+
23
+ As a counterpart to the access to the source code and rights to copy,
24
+ modify and redistribute granted by the license, users are provided only
25
+ with a limited warranty and the software's author, the holder of the
26
+ economic rights, and the successive licensors have only limited
27
+ liability.
28
+
29
+ In this respect, the user's attention is drawn to the risks associated
30
+ with loading, using, modifying and/or developing or reproducing the
31
+ software by the user in light of its specific status of free software,
32
+ that may mean that it is complicated to manipulate, and that also
33
+ therefore means that it is reserved for developers and experienced
34
+ professionals having in-depth computer knowledge. Users are therefore
35
+ encouraged to load and test the software's suitability as regards their
36
+ requirements in conditions enabling the security of their systems and/or
37
+ data to be ensured and, more generally, to use and operate it in the
38
+ same conditions as regards security.
39
+
40
+ The fact that you are presently reading this means that you have had
41
+ knowledge of the CeCILL license and that you accept its terms.
42
+
43
+ SEE LICENCE NOTICE: file README-LICENCE-utf8.txt at project source root.
44
+
45
+ This software is being developed by Eric Debreuve, a CNRS employee and
46
+ member of team Morpheme.
47
+ Team Morpheme is a joint team between Inria, CNRS, and UniCA.
48
+ It is hosted by the Centre Inria d'Université Côte d'Azur, Laboratory
49
+ I3S, and Laboratory iBV.
50
+
51
+ CNRS: https://www.cnrs.fr/index.php/en
52
+ Inria: https://www.inria.fr/en/
53
+ UniCA: https://univ-cotedazur.eu/
54
+ Centre Inria d'Université Côte d'Azur: https://www.inria.fr/en/centre/sophia/
55
+ I3S: https://www.i3s.unice.fr/en/
56
+ iBV: http://ibv.unice.fr/
57
+ Team Morpheme: https://team.inria.fr/morpheme/
58
+ """
@@ -0,0 +1,99 @@
1
+ """
2
+ Copyright CNRS/Inria/UniCA
3
+ Contributor(s): Eric Debreuve (eric.debreuve@cnrs.fr) since 2023
4
+ SEE COPYRIGHT NOTICE BELOW
5
+ """
6
+
7
+ import dataclasses as d
8
+ import typing as h
9
+ from enum import Enum as enum_t
10
+
11
+ from logger_36.content import MessageWithActualExpected
12
+ from str_to_obj.type.annotation import annotation_t
13
+ from str_to_obj.type.hint import annotated_hint_t
14
+
15
+
16
+ class boolean_mode_e(enum_t):
17
+ # True value must be listed first.
18
+ true_false = ("True", "False")
19
+ yes_no = ("Yes", "No")
20
+ on_off = ("On", "Off")
21
+
22
+
23
+ _BOOLEAN_MODES = tuple(boolean_mode_e.__members__.keys())
24
+
25
+
26
+ @d.dataclass(slots=True, repr=False, eq=False)
27
+ class boolean_t(annotation_t):
28
+
29
+ ACCEPTED_TYPES: h.ClassVar[tuple[type, ...]] = (bool,)
30
+
31
+ mode: boolean_mode_e = boolean_mode_e.true_false
32
+
33
+ @classmethod
34
+ def NewAnnotatedType(
35
+ cls, /, *, mode: boolean_mode_e | str | None = None
36
+ ) -> annotated_hint_t:
37
+ """"""
38
+ if mode is None:
39
+ mode = boolean_mode_e.true_false
40
+ elif isinstance(mode, str):
41
+ if mode in _BOOLEAN_MODES:
42
+ mode = boolean_mode_e[mode].value
43
+ else:
44
+ raise ValueError(
45
+ MessageWithActualExpected(
46
+ "Invalid boolean mode",
47
+ actual=mode,
48
+ expected=" or ".join(_BOOLEAN_MODES),
49
+ )
50
+ )
51
+
52
+ return h.Annotated[bool, cls(mode=mode)]
53
+
54
+
55
+ """
56
+ COPYRIGHT NOTICE
57
+
58
+ This software is governed by the CeCILL license under French law and
59
+ abiding by the rules of distribution of free software. You can use,
60
+ modify and/ or redistribute the software under the terms of the CeCILL
61
+ license as circulated by CEA, CNRS and INRIA at the following URL
62
+ "http://www.cecill.info".
63
+
64
+ As a counterpart to the access to the source code and rights to copy,
65
+ modify and redistribute granted by the license, users are provided only
66
+ with a limited warranty and the software's author, the holder of the
67
+ economic rights, and the successive licensors have only limited
68
+ liability.
69
+
70
+ In this respect, the user's attention is drawn to the risks associated
71
+ with loading, using, modifying and/or developing or reproducing the
72
+ software by the user in light of its specific status of free software,
73
+ that may mean that it is complicated to manipulate, and that also
74
+ therefore means that it is reserved for developers and experienced
75
+ professionals having in-depth computer knowledge. Users are therefore
76
+ encouraged to load and test the software's suitability as regards their
77
+ requirements in conditions enabling the security of their systems and/or
78
+ data to be ensured and, more generally, to use and operate it in the
79
+ same conditions as regards security.
80
+
81
+ The fact that you are presently reading this means that you have had
82
+ knowledge of the CeCILL license and that you accept its terms.
83
+
84
+ SEE LICENCE NOTICE: file README-LICENCE-utf8.txt at project source root.
85
+
86
+ This software is being developed by Eric Debreuve, a CNRS employee and
87
+ member of team Morpheme.
88
+ Team Morpheme is a joint team between Inria, CNRS, and UniCA.
89
+ It is hosted by the Centre Inria d'Université Côte d'Azur, Laboratory
90
+ I3S, and Laboratory iBV.
91
+
92
+ CNRS: https://www.cnrs.fr/index.php/en
93
+ Inria: https://www.inria.fr/en/
94
+ UniCA: https://univ-cotedazur.eu/
95
+ Centre Inria d'Université Côte d'Azur: https://www.inria.fr/en/centre/sophia/
96
+ I3S: https://www.i3s.unice.fr/en/
97
+ iBV: http://ibv.unice.fr/
98
+ Team Morpheme: https://team.inria.fr/morpheme/
99
+ """
@@ -0,0 +1,99 @@
1
+ """
2
+ Copyright CNRS/Inria/UniCA
3
+ Contributor(s): Eric Debreuve (eric.debreuve@cnrs.fr) since 2023
4
+ SEE COPYRIGHT NOTICE BELOW
5
+ """
6
+
7
+ import dataclasses as d
8
+ import typing as h
9
+
10
+ from str_to_obj.catalog.choices import choices_t
11
+ from str_to_obj.type.annotation import annotation_t
12
+ from str_to_obj.type.hint import annotated_hint_t
13
+
14
+
15
+ @d.dataclass(slots=True, repr=False, eq=False)
16
+ class callable_t(annotation_t):
17
+ ACCEPTED_TYPES: h.ClassVar[tuple[type, ...]] = (str,)
18
+
19
+ DUMMY_ENTRY: h.ClassVar[str] = "Dummy entry"
20
+ SEPARATOR: h.ClassVar[str] = ":"
21
+
22
+ kind: h.Literal["class", "function"]
23
+ choices: choices_t | None = None
24
+ allow_external: bool = False
25
+
26
+ @classmethod
27
+ def NewAnnotatedType(
28
+ cls,
29
+ /,
30
+ *,
31
+ kind: h.Literal["class", "function"] = "function",
32
+ catalog: h.Sequence[str] | bool | None = None,
33
+ allow_external: bool = False,
34
+ ) -> annotated_hint_t:
35
+ """"""
36
+ if catalog is None:
37
+ annotation = cls(kind=kind, allow_external=allow_external)
38
+ elif isinstance(catalog, bool):
39
+ if catalog:
40
+ annotation = cls(
41
+ kind=kind,
42
+ choices=choices_t((cls.DUMMY_ENTRY,)),
43
+ allow_external=allow_external,
44
+ )
45
+ else:
46
+ annotation = cls(kind=kind, allow_external=allow_external)
47
+ else:
48
+ annotation = cls(
49
+ kind=kind, choices=choices_t(catalog), allow_external=allow_external
50
+ )
51
+
52
+ return h.Annotated[str, annotation]
53
+
54
+
55
+ """
56
+ COPYRIGHT NOTICE
57
+
58
+ This software is governed by the CeCILL license under French law and
59
+ abiding by the rules of distribution of free software. You can use,
60
+ modify and/ or redistribute the software under the terms of the CeCILL
61
+ license as circulated by CEA, CNRS and INRIA at the following URL
62
+ "http://www.cecill.info".
63
+
64
+ As a counterpart to the access to the source code and rights to copy,
65
+ modify and redistribute granted by the license, users are provided only
66
+ with a limited warranty and the software's author, the holder of the
67
+ economic rights, and the successive licensors have only limited
68
+ liability.
69
+
70
+ In this respect, the user's attention is drawn to the risks associated
71
+ with loading, using, modifying and/or developing or reproducing the
72
+ software by the user in light of its specific status of free software,
73
+ that may mean that it is complicated to manipulate, and that also
74
+ therefore means that it is reserved for developers and experienced
75
+ professionals having in-depth computer knowledge. Users are therefore
76
+ encouraged to load and test the software's suitability as regards their
77
+ requirements in conditions enabling the security of their systems and/or
78
+ data to be ensured and, more generally, to use and operate it in the
79
+ same conditions as regards security.
80
+
81
+ The fact that you are presently reading this means that you have had
82
+ knowledge of the CeCILL license and that you accept its terms.
83
+
84
+ SEE LICENCE NOTICE: file README-LICENCE-utf8.txt at project source root.
85
+
86
+ This software is being developed by Eric Debreuve, a CNRS employee and
87
+ member of team Morpheme.
88
+ Team Morpheme is a joint team between Inria, CNRS, and UniCA.
89
+ It is hosted by the Centre Inria d'Université Côte d'Azur, Laboratory
90
+ I3S, and Laboratory iBV.
91
+
92
+ CNRS: https://www.cnrs.fr/index.php/en
93
+ Inria: https://www.inria.fr/en/
94
+ UniCA: https://univ-cotedazur.eu/
95
+ Centre Inria d'Université Côte d'Azur: https://www.inria.fr/en/centre/sophia/
96
+ I3S: https://www.i3s.unice.fr/en/
97
+ iBV: http://ibv.unice.fr/
98
+ Team Morpheme: https://team.inria.fr/morpheme/
99
+ """
@@ -0,0 +1,101 @@
1
+ """
2
+ Copyright CNRS/Inria/UniCA
3
+ Contributor(s): Eric Debreuve (eric.debreuve@cnrs.fr) since 2023
4
+ SEE COPYRIGHT NOTICE BELOW
5
+ """
6
+
7
+ import dataclasses as d
8
+ import typing as h
9
+
10
+ from str_to_obj.type.annotation import annotation_t
11
+ from str_to_obj.type.hint import annotated_hint_t
12
+
13
+
14
+ @d.dataclass(slots=True, repr=False, eq=False)
15
+ class choices_t(annotation_t):
16
+ ACCEPTED_TYPES: h.ClassVar[tuple[type, ...]] = (h.Any,)
17
+
18
+ options: h.Sequence[h.Any]
19
+
20
+ @classmethod
21
+ def NewAnnotatedType(cls, options: h.Sequence, /) -> annotated_hint_t:
22
+ """
23
+ Note: options hint cannot be h.Sequence | h.Literal since h.Literal cannot be
24
+ used alone, although a value of type h.Literal[...] can be passed as options.
25
+ """
26
+ if h.get_origin(options) is h.Literal:
27
+ options = h.get_args(options)
28
+ else:
29
+ options = tuple(options)
30
+
31
+ stripes = tuple(set(type(_elm) for _elm in options))
32
+ if stripes.__len__() > 1:
33
+ stripe = h.Union[stripes]
34
+ else:
35
+ stripe = stripes[0]
36
+
37
+ return h.Annotated[stripe, cls(options=options)]
38
+
39
+ def ValueIssues(self, value: str | h.Any, /) -> list[str]:
40
+ """"""
41
+ issues = annotation_t.ValueIssues(self, value)
42
+ if issues.__len__() > 0:
43
+ return issues
44
+
45
+ if (self.options.__len__() == 0) or (value in self.options):
46
+ # Options can be empty for a controlling parameter whose controlled section
47
+ # has not been specified. In a GUI context, such controlled section should
48
+ # have been populated programmatically.
49
+ return []
50
+
51
+ options = map(lambda _elm: f'"{_elm}"', self.options)
52
+ options = " or ".join(options)
53
+
54
+ return [f"Invalid choice: Actual={value}; Expected={options}."]
55
+
56
+
57
+ """
58
+ COPYRIGHT NOTICE
59
+
60
+ This software is governed by the CeCILL license under French law and
61
+ abiding by the rules of distribution of free software. You can use,
62
+ modify and/ or redistribute the software under the terms of the CeCILL
63
+ license as circulated by CEA, CNRS and INRIA at the following URL
64
+ "http://www.cecill.info".
65
+
66
+ As a counterpart to the access to the source code and rights to copy,
67
+ modify and redistribute granted by the license, users are provided only
68
+ with a limited warranty and the software's author, the holder of the
69
+ economic rights, and the successive licensors have only limited
70
+ liability.
71
+
72
+ In this respect, the user's attention is drawn to the risks associated
73
+ with loading, using, modifying and/or developing or reproducing the
74
+ software by the user in light of its specific status of free software,
75
+ that may mean that it is complicated to manipulate, and that also
76
+ therefore means that it is reserved for developers and experienced
77
+ professionals having in-depth computer knowledge. Users are therefore
78
+ encouraged to load and test the software's suitability as regards their
79
+ requirements in conditions enabling the security of their systems and/or
80
+ data to be ensured and, more generally, to use and operate it in the
81
+ same conditions as regards security.
82
+
83
+ The fact that you are presently reading this means that you have had
84
+ knowledge of the CeCILL license and that you accept its terms.
85
+
86
+ SEE LICENCE NOTICE: file README-LICENCE-utf8.txt at project source root.
87
+
88
+ This software is being developed by Eric Debreuve, a CNRS employee and
89
+ member of team Morpheme.
90
+ Team Morpheme is a joint team between Inria, CNRS, and UniCA.
91
+ It is hosted by the Centre Inria d'Université Côte d'Azur, Laboratory
92
+ I3S, and Laboratory iBV.
93
+
94
+ CNRS: https://www.cnrs.fr/index.php/en
95
+ Inria: https://www.inria.fr/en/
96
+ UniCA: https://univ-cotedazur.eu/
97
+ Centre Inria d'Université Côte d'Azur: https://www.inria.fr/en/centre/sophia/
98
+ I3S: https://www.i3s.unice.fr/en/
99
+ iBV: http://ibv.unice.fr/
100
+ Team Morpheme: https://team.inria.fr/morpheme/
101
+ """