enumerific 0.0.0__py3-none-any.whl → 1.0.0__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.
enumerific/version.txt ADDED
@@ -0,0 +1 @@
1
+ 1.0.0
@@ -0,0 +1,168 @@
1
+ Metadata-Version: 2.2
2
+ Name: enumerific
3
+ Version: 1.0.0
4
+ Summary: Simplifies working with Python enums.
5
+ Author: Daniel Sissman
6
+ License: MIT License
7
+
8
+ Copyright © 2024–2025 Daniel Sissman.
9
+
10
+ Permission is hereby granted, free of charge, to any person obtaining a copy
11
+ of this software and associated documentation files (the "Software"), to deal
12
+ in the Software without restriction, including without limitation the rights
13
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
14
+ copies of the Software, and to permit persons to whom the Software is
15
+ furnished to do so, subject to the following conditions:
16
+
17
+ The above copyright notice and this permission notice shall be included in all
18
+ copies or substantial portions of the Software.
19
+
20
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
21
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
22
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
23
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
24
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
25
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
26
+ SOFTWARE.
27
+ Project-URL: Documentation, https://github.com/bluebinary/enumerific/blob/main/README.md
28
+ Project-URL: Changelog, https://github.com/bluebinary/enumerific/blob/main/CHANGELOG.md
29
+ Project-URL: Repository, https://github.com/bluebinary/enumerific
30
+ Project-URL: Issues, https://github.com/bluebinary/enumerific/issues
31
+ Keywords: enum,enumeration,enumerations
32
+ Classifier: License :: OSI Approved :: MIT License
33
+ Classifier: Programming Language :: Python :: 3
34
+ Classifier: Programming Language :: Python :: 3.9
35
+ Classifier: Programming Language :: Python :: 3.10
36
+ Classifier: Programming Language :: Python :: 3.11
37
+ Classifier: Programming Language :: Python :: 3.12
38
+ Classifier: Programming Language :: Python :: 3.13
39
+ Requires-Python: >=3.9
40
+ Description-Content-Type: text/markdown
41
+ License-File: LICENSE.md
42
+
43
+ # Enumerific Enums
44
+
45
+ The `enumerific` library provides several useful extensions to the Python built-in `enums` library.
46
+
47
+ ### Requirements
48
+
49
+ The Enumerific library has been tested with Python 3.9, 3.10, 3.11, 3.12 and 3.13 but may work with some earlier versions such as 3.8, but has not been tested against this version or any earlier. The library is not compatible with Python 2.* or earlier.
50
+
51
+ ### Installation
52
+
53
+ The Enumerific library is available from PyPi, so may be added to a project's dependencies via its `requirements.txt` file or similar by referencing the Enumerific library's name, `enumerific`, or the library may be installed directly into your local runtime environment using `pip install` by entering the following command, and following any prompts:
54
+
55
+ $ pip install enumerific
56
+
57
+ ### Usage
58
+
59
+ To use the Enumerific library, simply import the library and use it like you would the built-in `enum` library as a drop-in replacement:
60
+
61
+ ```
62
+ import enumerific
63
+
64
+ class MyEnum(enumerific.Enum):
65
+ Option1 = "ABC"
66
+ Option2 = "DEF"
67
+
68
+ val = MyEnum.Option1
69
+ ```
70
+
71
+ You can also import the `Enum` class directly from the `enumerific` library and use it directly:
72
+
73
+ ```
74
+ from enumerific import Enum
75
+
76
+ class MyEnum(Enum):
77
+ Option1 = "ABC"
78
+ ...
79
+ ```
80
+
81
+ The Enumerific library's own `Enum` class is a subclass of the built-in `enum.Enum` class, so all of the built-in functionality of `enum.Enum` is available, as well as several additional class methods:
82
+
83
+ * `reconcile(value: object, default: Enum = None, raises: bool = False) -> Enum` – The `reconcile` method allows for an enumeration's value or an enumeration option's name to be reconciled against a matching enumeration option. If the provided value can be matched against one of the enumeration's available options, that option will be returned, otherwise there are two possible behaviours: if the `raises` keyword argument has been set to or left as `False` (its default), the value assigned to the `default` keyword argument will be returned, which may be `None` if no default value has been specified; if the `raises` argument has been set to `True` an `EnumValueError` exception will be raised as an alert that the provided value could not be matched. One can also provide an enumeration option as the input value to the `reconcile` method, and these will be validated and returned as-is.
84
+ * `validate(value: object) -> bool` – The `validate` method takes the same range of input values as the `reconcile` method, and returns `True` when the provided value can be reconciled against an enumeration option, or `False` otherwise.
85
+ * `options() -> list[Enum]` – The `options` method provides easy access to the list of the enumeration's available options.
86
+
87
+ The benefits of being able to validate and reconcile various input values against an enumeration, include allowing for a controlled vocabulary of options to be checked against, and the ability to convert enumeration values into their corresponding enumeration option. This can be especially useful when working with input data where you need to convert those values to their corresponding enumeration options, and to be able to do so without maintaining boilerplate code to perform the matching and assignment.
88
+
89
+ Some examples of use include the following code samples, where each make use of the example `MyEnum` class, defined as follows:
90
+
91
+ ```
92
+ from enumerific import Enum
93
+
94
+ class MyEnum(Enum):
95
+ Option1 = "ABC"
96
+ Option2 = "DEF"
97
+ ```
98
+
99
+ #### Example 1: Reconciling a Value
100
+
101
+ ```
102
+ # Given a string value in this case
103
+ value = "ABC"
104
+
105
+ # Reconcile it to the associated enumeration option
106
+ value = MyEnum.reconcile(value)
107
+
108
+ assert value == MyEnum.Option1 # asserts successfully
109
+ assert value is MyEnum.Option1 # asserts successfully as enums are singletons
110
+ ```
111
+
112
+ #### Example 2: Reconciling an Enumeration Option Name
113
+
114
+ ```
115
+ # Given a string value in this case
116
+ value = "Option1"
117
+
118
+ # Reconcile it to the associated enumeration option
119
+ value = MyEnum.reconcile(value)
120
+
121
+ assert value == MyEnum.Option1 # asserts successfully
122
+ assert value is MyEnum.Option1 # asserts successfully as enums are singletons
123
+ ```
124
+
125
+ #### Example 3: Validating a Value
126
+
127
+ ```
128
+ # The value can be an enumeration option's name, its value, or the enumeration option
129
+ value = "Option1"
130
+ value = "ABC"
131
+ value = MyEnum.Option1
132
+
133
+ if MyEnum.validate(value) is True:
134
+ # do something if the value could be validated
135
+ else:
136
+ # do something else if the value could not be validated
137
+ ```
138
+
139
+ #### Example 4: Iterating Over Enumeration Options
140
+
141
+ ```
142
+ for option in MyEnum.options():
143
+ # do something with each option
144
+ print(option.name, option.value)
145
+ ```
146
+
147
+ ### Unit Tests
148
+
149
+ The Enumerific library includes a suite of comprehensive unit tests which ensure that the library functionality operates as expected. The unit tests were developed with and are run via `pytest`.
150
+
151
+ To ensure that the unit tests are run within a predictable runtime environment where all of the necessary dependencies are available, a [Docker](https://www.docker.com) image is created within which the tests are run. To run the unit tests, ensure Docker and Docker Compose is [installed](https://docs.docker.com/engine/install/), and perform the following commands, which will build the Docker image via `docker compose build` and then run the tests via `docker compose run` – the output of running the tests will be displayed:
152
+
153
+ ```
154
+ $ docker compose build
155
+ $ docker compose run tests
156
+ ```
157
+
158
+ To run the unit tests with optional command line arguments being passed to `pytest`, append the relevant arguments to the `docker compose run tests` command, as follows, for example passing `-vv` to enable verbose output:
159
+
160
+ ```
161
+ $ docker compose run tests -vv
162
+ ```
163
+
164
+ See the documentation for [PyTest](https://docs.pytest.org/en/latest/) regarding available optional command line arguments.
165
+
166
+ ### Copyright & License Information
167
+
168
+ Copyright © 2024–2025 Daniel Sissman; Licensed under the MIT License.
@@ -0,0 +1,8 @@
1
+ enumerific/__init__.py,sha256=GWEZBAT_ml4VXTQLjUKLnkQtf3AUljF0vokd8-cINk8,3227
2
+ enumerific/version.txt,sha256=klIfw8vZZL3J9YSpkbif3apXVO0cyW1tQkRTOGacEwU,5
3
+ enumerific-1.0.0.dist-info/LICENSE.md,sha256=j1XidOCGUhPx7CyXA31uC0XGKDRnvUcZpMp161qHI6g,1077
4
+ enumerific-1.0.0.dist-info/METADATA,sha256=MHKN_mQRKEneFtNS5VAX4bJd33Z0NhRTKVzAUL9xb6M,8066
5
+ enumerific-1.0.0.dist-info/WHEEL,sha256=In9FTNxeP60KnTkGw7wk6mJPYd_dQSjEZmXdBdMCI-8,91
6
+ enumerific-1.0.0.dist-info/top_level.txt,sha256=hyemsMgPYZgSx71XHmFRF-gvc_2Y4rDAESR8e0hbYHU,11
7
+ enumerific-1.0.0.dist-info/zip-safe,sha256=AbpHGcgLb-kRsJGnwFEktk7uzpZOCcBY74-YBdrKVGs,1
8
+ enumerific-1.0.0.dist-info/RECORD,,
@@ -1,4 +0,0 @@
1
- Metadata-Version: 2.2
2
- Name: enumerific
3
- Version: 0.0.0
4
- License-File: LICENSE.md
@@ -1,7 +0,0 @@
1
- enumerific/__init__.py,sha256=GWEZBAT_ml4VXTQLjUKLnkQtf3AUljF0vokd8-cINk8,3227
2
- enumerific-0.0.0.dist-info/LICENSE.md,sha256=j1XidOCGUhPx7CyXA31uC0XGKDRnvUcZpMp161qHI6g,1077
3
- enumerific-0.0.0.dist-info/METADATA,sha256=xTLu0rdVXG3rz6ct3SytxKUsA4ZJaRbgyyDOSguvEKs,79
4
- enumerific-0.0.0.dist-info/WHEEL,sha256=In9FTNxeP60KnTkGw7wk6mJPYd_dQSjEZmXdBdMCI-8,91
5
- enumerific-0.0.0.dist-info/top_level.txt,sha256=hyemsMgPYZgSx71XHmFRF-gvc_2Y4rDAESR8e0hbYHU,11
6
- enumerific-0.0.0.dist-info/zip-safe,sha256=AbpHGcgLb-kRsJGnwFEktk7uzpZOCcBY74-YBdrKVGs,1
7
- enumerific-0.0.0.dist-info/RECORD,,