mvx-common 0.2.1__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.
- mvx_common-0.2.1/.gitignore +40 -0
- mvx_common-0.2.1/LICENSE +42 -0
- mvx_common-0.2.1/NOTICE +4 -0
- mvx_common-0.2.1/PKG-INFO +208 -0
- mvx_common-0.2.1/README.md +175 -0
- mvx_common-0.2.1/pyproject.toml +101 -0
- mvx_common-0.2.1/scripts/check.sh +7 -0
- mvx_common-0.2.1/scripts/format.sh +5 -0
- mvx_common-0.2.1/src/mvx/common/__init__.py +1 -0
- mvx_common-0.2.1/src/mvx/common/errors/__init__.py +14 -0
- mvx_common-0.2.1/src/mvx/common/errors/invalid_function_argument_error.py +54 -0
- mvx_common-0.2.1/src/mvx/common/errors/reasoned_error.py +56 -0
- mvx_common-0.2.1/src/mvx/common/errors/runtime_errors.py +79 -0
- mvx_common-0.2.1/src/mvx/common/errors/structured_error.py +85 -0
- mvx_common-0.2.1/src/mvx/common/helpers/__init__.py +18 -0
- mvx_common-0.2.1/src/mvx/common/helpers/api_error_processor.py +122 -0
- mvx_common-0.2.1/src/mvx/common/helpers/document_enum.py +18 -0
- mvx_common-0.2.1/src/mvx/common/helpers/introspection.py +21 -0
- mvx_common-0.2.1/src/mvx/common/helpers/run_with_cancellation_policy.py +161 -0
- mvx_common-0.2.1/src/mvx/common/logger/__init__.py +694 -0
- mvx_common-0.2.1/src/mvx/common/logger/adapter_logging/__init__.py +16 -0
- mvx_common-0.2.1/src/mvx/common/logger/adapter_logging/log_record_factory.py +137 -0
- mvx_common-0.2.1/src/mvx/common/logger/adapter_logging/logging_configs.py +371 -0
- mvx_common-0.2.1/src/mvx/common/logger/adapter_logging/logging_file_sink.py +205 -0
- mvx_common-0.2.1/src/mvx/common/logger/adapter_logging/logging_stream_sink.py +187 -0
- mvx_common-0.2.1/src/mvx/common/logger/asyncio_log_sink/__init__.py +42 -0
- mvx_common-0.2.1/src/mvx/common/logger/asyncio_log_sink/common.py +39 -0
- mvx_common-0.2.1/src/mvx/common/logger/asyncio_log_sink/errors.py +208 -0
- mvx_common-0.2.1/src/mvx/common/logger/asyncio_log_sink/log_sink.py +846 -0
- mvx_common-0.2.1/src/mvx/common/logger/errors.py +332 -0
- mvx_common-0.2.1/src/mvx/common/logger/helpers.py +34 -0
- mvx_common-0.2.1/src/mvx/common/logger/log_components/__init__.py +16 -0
- mvx_common-0.2.1/src/mvx/common/logger/log_components/log_invocation.py +878 -0
- mvx_common-0.2.1/src/mvx/common/logger/log_components/protocols.py +157 -0
- mvx_common-0.2.1/src/mvx/common/logger/log_context/__init__.py +8 -0
- mvx_common-0.2.1/src/mvx/common/logger/log_context/log_context.py +800 -0
- mvx_common-0.2.1/src/mvx/common/logger/log_payload_processor/__init__.py +19 -0
- mvx_common-0.2.1/src/mvx/common/logger/log_payload_processor/log_payload_processor.py +514 -0
- mvx_common-0.2.1/src/mvx/common/logger/log_payload_processor/types.py +52 -0
- mvx_common-0.2.1/src/mvx/common/logger/models.py +279 -0
- mvx_common-0.2.1/src/mvx/common/py.typed +0 -0
- mvx_common-0.2.1/tests/test_errors/test_invalid_function_argument_error.py +249 -0
- mvx_common-0.2.1/tests/test_errors/test_reasoned_error.py +105 -0
- mvx_common-0.2.1/tests/test_errors/test_runtime_errors.py +128 -0
- mvx_common-0.2.1/tests/test_errors/test_structured_error.py +183 -0
- mvx_common-0.2.1/tests/test_helpers/test_api_error_processor.py +286 -0
- mvx_common-0.2.1/tests/test_helpers/test_run_with_cancellation_policy.py +1148 -0
- mvx_common-0.2.1/tests/test_logger/adapter_logging/test_log_record_factory.py +490 -0
- mvx_common-0.2.1/tests/test_logger/adapter_logging/test_logging_configs.py +596 -0
- mvx_common-0.2.1/tests/test_logger/adapter_logging/test_logging_file_sink.py +741 -0
- mvx_common-0.2.1/tests/test_logger/adapter_logging/test_logging_stream_sink.py +631 -0
- mvx_common-0.2.1/tests/test_logger/asyncio_log_sink/test_asyncio_log_sink.py +3922 -0
- mvx_common-0.2.1/tests/test_logger/log_components/log_invocation/doc_examples/conftest.py +32 -0
- mvx_common-0.2.1/tests/test_logger/log_components/log_invocation/doc_examples/test_awaitable_result.py +66 -0
- mvx_common-0.2.1/tests/test_logger/log_components/log_invocation/doc_examples/test_cancellation.py +56 -0
- mvx_common-0.2.1/tests/test_logger/log_components/log_invocation/doc_examples/test_context_fields.py +58 -0
- mvx_common-0.2.1/tests/test_logger/log_components/log_invocation/doc_examples/test_context_formatter.py +88 -0
- mvx_common-0.2.1/tests/test_logger/log_components/log_invocation/doc_examples/test_error_policy.py +54 -0
- mvx_common-0.2.1/tests/test_logger/log_components/log_invocation/doc_examples/test_invoke_kwargs.py +63 -0
- mvx_common-0.2.1/tests/test_logger/log_components/log_invocation/doc_examples/test_public_api_method.py +49 -0
- mvx_common-0.2.1/tests/test_logger/log_components/log_invocation/doc_examples/test_result_logging.py +65 -0
- mvx_common-0.2.1/tests/test_logger/log_components/log_invocation/doc_examples/test_standalone_function.py +53 -0
- mvx_common-0.2.1/tests/test_logger/log_components/log_invocation/doc_examples/test_verbosity.py +152 -0
- mvx_common-0.2.1/tests/test_logger/log_components/log_invocation/test_log_invocation.py +1647 -0
- mvx_common-0.2.1/tests/test_logger/log_context/test_log_context.py +1306 -0
- mvx_common-0.2.1/tests/test_logger/log_payload_processor/test_log_payload_processor.py +1859 -0
- mvx_common-0.2.1/tests/test_logger/test_errors.py +383 -0
- mvx_common-0.2.1/tests/test_logger/test_manual_log_context_wiring.py +209 -0
- mvx_common-0.2.1/tests/test_logger/test_package_bootstrap.py +77 -0
- mvx_common-0.2.1/tests/test_logger/test_package_file_sink_smoke.py +222 -0
- mvx_common-0.2.1/tests/test_logger/test_package_internals.py +641 -0
- mvx_common-0.2.1/tests/test_logger/test_package_log_invocation_integration.py +366 -0
- mvx_common-0.2.1/tests/test_logger/test_package_public_api.py +383 -0
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
# Python bytecode
|
|
2
|
+
__pycache__/
|
|
3
|
+
*.py[cod]
|
|
4
|
+
*$py.class
|
|
5
|
+
|
|
6
|
+
# Virtual environments
|
|
7
|
+
.venv/
|
|
8
|
+
venv/
|
|
9
|
+
env/
|
|
10
|
+
|
|
11
|
+
# Build artifacts
|
|
12
|
+
build/
|
|
13
|
+
dist/
|
|
14
|
+
*.egg-info/
|
|
15
|
+
.eggs/
|
|
16
|
+
|
|
17
|
+
# Test / coverage artifacts
|
|
18
|
+
.pytest_cache/
|
|
19
|
+
.mypy_cache/
|
|
20
|
+
.ruff_cache/
|
|
21
|
+
.coverage
|
|
22
|
+
coverage.xml
|
|
23
|
+
htmlcov/
|
|
24
|
+
|
|
25
|
+
# Documentation build
|
|
26
|
+
docs/_build/
|
|
27
|
+
common/docs/_build/
|
|
28
|
+
|
|
29
|
+
# IDE
|
|
30
|
+
.idea/
|
|
31
|
+
|
|
32
|
+
# OS
|
|
33
|
+
.DS_Store
|
|
34
|
+
Thumbs.db
|
|
35
|
+
|
|
36
|
+
# Logs
|
|
37
|
+
*.log
|
|
38
|
+
|
|
39
|
+
# Local IDE/tool configs
|
|
40
|
+
mypy_ide.ini
|
mvx_common-0.2.1/LICENSE
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
"License" shall mean the terms and conditions for use, reproduction, and distribution as defined by Sections 1 through 9 of this document.
|
|
9
|
+
|
|
10
|
+
"Licensor" shall mean the copyright owner or entity authorized by the copyright owner that is granting the License.
|
|
11
|
+
|
|
12
|
+
"Legal Entity" shall mean the union of the acting entity and all other entities that control, are controlled by, or are under common control with that entity. For the purposes of this definition, "control" means (i) the power, direct or indirect, to cause the direction or management of such entity, whether by contract or otherwise, or (ii) ownership of fifty percent (50%) or more of the outstanding shares, or (iii) beneficial ownership of such entity.
|
|
13
|
+
|
|
14
|
+
"You" (or "Your") shall mean an individual or Legal Entity exercising permissions granted by this License.
|
|
15
|
+
|
|
16
|
+
"Source" form shall mean the preferred form for making modifications, including but not limited to software source code, documentation source, and configuration files.
|
|
17
|
+
|
|
18
|
+
"Object" form shall mean any form resulting from mechanical transformation or translation of a Source form, including but not limited to compiled object code, generated documentation, and conversions to other media types.
|
|
19
|
+
|
|
20
|
+
"Work" shall mean the work of authorship, whether in Source or Object form, made available under the License, as indicated by a copyright notice that is included in or attached to the work (an example is provided in the Appendix below).
|
|
21
|
+
|
|
22
|
+
"Derivative Works" shall mean any work, whether in Source or Object form, that is based on (or derived from) the Work and for which the editorial revisions, annotations, elaborations, or other modifications represent, as a whole, an original work of authorship. For the purposes of this License, Derivative Works shall not include works that remain separable from, or merely link (or bind by name) to the interfaces of, the Work and Derivative Works thereof.
|
|
23
|
+
|
|
24
|
+
"Contribution" shall mean any work of authorship, including the original version of the Work and any modifications or additions to that Work or Derivative Works thereof, that is intentionally submitted to Licensor for inclusion in the Work by the copyright owner or by an individual or Legal Entity authorized to submit on behalf of the copyright owner. For the purposes of this definition, "submitted" means any form of electronic, verbal, or written communication sent to the Licensor or its representatives, including but not limited to communication on electronic mailing lists, source code control systems, and issue tracking systems that are managed by, or on behalf of, the Licensor for the purpose of discussing and improving the Work, but excluding communication that is conspicuously marked or otherwise designated in writing by the copyright owner as "Not a Contribution."
|
|
25
|
+
|
|
26
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity on behalf of whom a Contribution has been received by Licensor and subsequently incorporated within the Work.
|
|
27
|
+
|
|
28
|
+
2. Grant of Copyright License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable copyright license to reproduce, prepare Derivative Works of, publicly display, publicly perform, sublicense, and distribute the Work and such Derivative Works in Source or Object form.
|
|
29
|
+
3. Grant of Patent License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable (except as stated in this section) patent license to make, have made, use, offer to sell, sell, import, and otherwise transfer the Work, where such license applies only to those patent claims licensable by such Contributor that are necessarily infringed by their Contribution(s) alone or by combination of their Contribution(s) with the Work to which such Contribution(s) was submitted. If You institute patent litigation against any entity (including a cross-claim or counterclaim in a lawsuit) alleging that the Work or a Contribution incorporated within the Work constitutes direct or contributory patent infringement, then any patent licenses granted to You under this License for that Work shall terminate as of the date such litigation is filed.
|
|
30
|
+
4. Redistribution. You may reproduce and distribute copies of the Work or Derivative Works thereof in any medium, with or without modifications, and in Source or Object form, provided that You meet the following conditions:
|
|
31
|
+
(a) You must give any other recipients of the Work or Derivative Works a copy of this License; and
|
|
32
|
+
(b) You must cause any modified files to carry prominent notices stating that You changed the files; and
|
|
33
|
+
(c) You must retain, in the Source form of any Derivative Works that You distribute, all copyright, patent, trademark, and attribution notices from the Source form of the Work, excluding those notices that do not pertain to any part of the Derivative Works; and
|
|
34
|
+
(d) If the Work includes a "NOTICE" text file as part of its distribution, then any Derivative Works that You distribute must include a readable copy of the attribution notices contained within such NOTICE file, excluding those notices that do not pertain to any part of the Derivative Works, in at least one of the following places: within a NOTICE text file distributed as part of the Derivative Works; within the Source form or documentation, if provided along with the Derivative Works; or, within a display generated by the Derivative Works, if and wherever such third-party notices normally appear. The contents of the NOTICE file are for informational purposes only and do not modify the License. You may add Your own attribution notices within Derivative Works that You distribute, alongside or as an addendum to the NOTICE text from the Work, provided that such additional attribution notices cannot be construed as modifying the License.
|
|
35
|
+
You may add Your own copyright statement to Your modifications and may provide additional or different license terms and conditions for use, reproduction, or distribution of Your modifications, or for any such Derivative Works as a whole, provided Your use, reproduction, and distribution of the Work otherwise complies with the conditions stated in this License.
|
|
36
|
+
|
|
37
|
+
5. Submission of Contributions. Unless You explicitly state otherwise, any Contribution intentionally submitted for inclusion in the Work by You to the Licensor shall be under the terms and conditions of this License, without any additional terms or conditions. Notwithstanding the above, nothing herein shall supersede or modify the terms of any separate license agreement you may have executed with Licensor regarding such Contributions.
|
|
38
|
+
6. Trademarks. This License does not grant permission to use the trade names, trademarks, service marks, or product names of the Licensor, except as required for reasonable and customary use in describing the origin of the Work and reproducing the content of the NOTICE file.
|
|
39
|
+
7. Disclaimer of Warranty. Unless required by applicable law or agreed to in writing, Licensor provides the Work (and each Contributor provides its Contributions) on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied, including, without limitation, any warranties or conditions of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A PARTICULAR PURPOSE. You are solely responsible for determining the appropriateness of using or redistributing the Work and assume any risks associated with Your exercise of permissions under this License.
|
|
40
|
+
8. Limitation of Liability. In no event and under no legal theory, whether in tort (including negligence), contract, or otherwise, unless required by applicable law (such as deliberate and grossly negligent acts) or agreed to in writing, shall any Contributor be liable to You for damages, including any direct, indirect, special, incidental, or consequential damages of any character arising as a result of this License or out of the use or inability to use the Work (including but not limited to damages for loss of goodwill, work stoppage, computer failure or malfunction, or any and all other commercial damages or losses), even if such Contributor has been advised of the possibility of such damages.
|
|
41
|
+
9. Accepting Warranty or Additional Liability. While redistributing the Work or Derivative Works thereof, You may choose to offer, and charge a fee for, acceptance of support, warranty, indemnity, or other liability obligations and/or rights consistent with this License. However, in accepting such obligations, You may act only on Your own behalf and on Your sole responsibility, not on behalf of any other Contributor, and only if You agree to indemnify, defend, and hold each Contributor harmless for any liability incurred by, or claims asserted against, such Contributor by reason of your accepting any such warranty or additional liability.
|
|
42
|
+
END OF TERMS AND CONDITIONS
|
mvx_common-0.2.1/NOTICE
ADDED
|
@@ -0,0 +1,208 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: mvx-common
|
|
3
|
+
Version: 0.2.1
|
|
4
|
+
Summary: Common utilities for MVX Python packages.
|
|
5
|
+
Project-URL: Documentation, https://mvx-lib.readthedocs.io/en/latest/
|
|
6
|
+
Project-URL: Source, https://github.com/makarovvvdream-dev/mvx-lib
|
|
7
|
+
Project-URL: Issues, https://github.com/makarovvvdream-dev/mvx-lib/issues
|
|
8
|
+
Project-URL: Changelog, https://mvx-lib.readthedocs.io/en/latest/common/version_history/
|
|
9
|
+
Author: Vladimir Makarov
|
|
10
|
+
License-Expression: Apache-2.0
|
|
11
|
+
License-File: LICENSE
|
|
12
|
+
License-File: NOTICE
|
|
13
|
+
Classifier: License :: OSI Approved :: Apache Software License
|
|
14
|
+
Classifier: Programming Language :: Python :: 3
|
|
15
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
16
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
17
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
18
|
+
Requires-Python: >=3.11
|
|
19
|
+
Provides-Extra: dev
|
|
20
|
+
Requires-Dist: black; extra == 'dev'
|
|
21
|
+
Requires-Dist: mypy; extra == 'dev'
|
|
22
|
+
Requires-Dist: pytest; extra == 'dev'
|
|
23
|
+
Requires-Dist: pytest-asyncio; extra == 'dev'
|
|
24
|
+
Requires-Dist: pytest-cov; extra == 'dev'
|
|
25
|
+
Requires-Dist: ruff; extra == 'dev'
|
|
26
|
+
Provides-Extra: docs
|
|
27
|
+
Requires-Dist: enum-tools[sphinx]; extra == 'docs'
|
|
28
|
+
Requires-Dist: myst-parser; extra == 'docs'
|
|
29
|
+
Requires-Dist: sphinx-autodoc-typehints; extra == 'docs'
|
|
30
|
+
Requires-Dist: sphinx-rtd-theme; extra == 'docs'
|
|
31
|
+
Requires-Dist: sphinx<9; extra == 'docs'
|
|
32
|
+
Description-Content-Type: text/markdown
|
|
33
|
+
|
|
34
|
+
# MVX Common
|
|
35
|
+
|
|
36
|
+
[](https://github.com/makarovvvdream-dev/mvx-lib/actions/workflows/common-ci.yml)
|
|
37
|
+
|
|
38
|
+
`mvx-common` is a Python package with foundation-level infrastructure for MVX Python projects.
|
|
39
|
+
|
|
40
|
+
Its main public component is **MVX Logger**.
|
|
41
|
+
|
|
42
|
+
MVX Logger is a lightweight structured event logging infrastructure for applications and reusable Python libraries that need rich and flexible diagnostic visibility.
|
|
43
|
+
|
|
44
|
+
Most logging tools focus on formatting, routing, or collecting log records. MVX Logger focuses on the step before that: how code creates structured diagnostic events, controls their diagnostic data, and hands them over for delivery.
|
|
45
|
+
|
|
46
|
+
## Key features
|
|
47
|
+
|
|
48
|
+
* log structured events with rich, flexible, and structured diagnostic info instead of hand-written log strings
|
|
49
|
+
* control logging width through event policies without changing calling code, focusing logs on current diagnostic needs
|
|
50
|
+
* keep event diagnostic data well-shaped and clean through centralized payload normalization
|
|
51
|
+
* change logging destination and formatting without changing event-producing code
|
|
52
|
+
* deliver events to standard logging streams, files, async sinks, or custom backends
|
|
53
|
+
* keep the logging path fast and thread-safe while slow backends are handled outside the business flow
|
|
54
|
+
* log standardized business operation lifecycles without writing logging code inside the operation body
|
|
55
|
+
* capture selected call arguments, results, errors, and context fields as structured event diagnostic info
|
|
56
|
+
* keep business logic focused on the operation itself instead of repetitive try/except logging blocks
|
|
57
|
+
* start using it almost as simply as regular logging, then move to deeper structured diagnostics when needed
|
|
58
|
+
|
|
59
|
+
## What MVX Logger is not
|
|
60
|
+
|
|
61
|
+
MVX Logger is not a replacement for `logging`, `structlog`, `loguru`, or OpenTelemetry.
|
|
62
|
+
|
|
63
|
+
It is a structured event creation layer that can sit before those tools or other delivery backends.
|
|
64
|
+
|
|
65
|
+
The goal is not to own the whole observability stack. The goal is to make diagnostic event creation explicit, structured, configurable, and safe to use across project boundaries.
|
|
66
|
+
|
|
67
|
+
## Other utilities
|
|
68
|
+
|
|
69
|
+
`mvx-common` also includes smaller foundation utilities used by MVX packages:
|
|
70
|
+
|
|
71
|
+
```text
|
|
72
|
+
structured errors
|
|
73
|
+
public API error normalization helpers
|
|
74
|
+
asyncio cancellation helpers
|
|
75
|
+
```
|
|
76
|
+
|
|
77
|
+
These utilities support predictable public errors, explicit cancellation behavior, and consistent diagnostics.
|
|
78
|
+
|
|
79
|
+
## Requirements
|
|
80
|
+
|
|
81
|
+
`mvx-common` requires Python 3.11 or newer.
|
|
82
|
+
|
|
83
|
+
```text
|
|
84
|
+
Python >= 3.11
|
|
85
|
+
```
|
|
86
|
+
|
|
87
|
+
## Installation for development
|
|
88
|
+
|
|
89
|
+
From the package directory:
|
|
90
|
+
|
|
91
|
+
```bash
|
|
92
|
+
cd common
|
|
93
|
+
python -m pip install -e ".[dev]"
|
|
94
|
+
```
|
|
95
|
+
|
|
96
|
+
To install documentation dependencies as well:
|
|
97
|
+
|
|
98
|
+
```bash
|
|
99
|
+
python -m pip install -e ".[dev,docs]"
|
|
100
|
+
```
|
|
101
|
+
|
|
102
|
+
## Running checks
|
|
103
|
+
|
|
104
|
+
From the package directory:
|
|
105
|
+
|
|
106
|
+
```bash
|
|
107
|
+
scripts/check.sh
|
|
108
|
+
```
|
|
109
|
+
|
|
110
|
+
The check script runs:
|
|
111
|
+
|
|
112
|
+
```text
|
|
113
|
+
black --check
|
|
114
|
+
ruff check
|
|
115
|
+
mypy
|
|
116
|
+
pytest with branch coverage
|
|
117
|
+
```
|
|
118
|
+
|
|
119
|
+
The package requires at least 90% branch coverage.
|
|
120
|
+
|
|
121
|
+
## Documentation
|
|
122
|
+
|
|
123
|
+
Full documentation:
|
|
124
|
+
|
|
125
|
+
```text
|
|
126
|
+
https://mvx-lib.readthedocs.io/en/latest/
|
|
127
|
+
```
|
|
128
|
+
|
|
129
|
+
MVX Logger overview:
|
|
130
|
+
|
|
131
|
+
```text
|
|
132
|
+
https://mvx-lib.readthedocs.io/en/latest/common/logger/overview.html
|
|
133
|
+
```
|
|
134
|
+
|
|
135
|
+
Getting started:
|
|
136
|
+
|
|
137
|
+
```text
|
|
138
|
+
https://mvx-lib.readthedocs.io/en/latest/common/logger/getting_started/
|
|
139
|
+
```
|
|
140
|
+
|
|
141
|
+
Advanced usage:
|
|
142
|
+
|
|
143
|
+
```text
|
|
144
|
+
https://mvx-lib.readthedocs.io/en/latest/common/logger/advanced_usage/
|
|
145
|
+
```
|
|
146
|
+
|
|
147
|
+
`log_invocation` guide:
|
|
148
|
+
|
|
149
|
+
```text
|
|
150
|
+
https://mvx-lib.readthedocs.io/en/latest/common/logger/log_components/log_invocation/overview.html
|
|
151
|
+
```
|
|
152
|
+
|
|
153
|
+
Version history:
|
|
154
|
+
|
|
155
|
+
```text
|
|
156
|
+
https://mvx-lib.readthedocs.io/en/latest/common/version_history/
|
|
157
|
+
```
|
|
158
|
+
|
|
159
|
+
## Building documentation
|
|
160
|
+
|
|
161
|
+
From the repository root:
|
|
162
|
+
|
|
163
|
+
```bash
|
|
164
|
+
scripts/docs.sh
|
|
165
|
+
```
|
|
166
|
+
|
|
167
|
+
The built HTML documentation is written to:
|
|
168
|
+
|
|
169
|
+
```text
|
|
170
|
+
docs/_build/html/
|
|
171
|
+
```
|
|
172
|
+
|
|
173
|
+
## Project status
|
|
174
|
+
|
|
175
|
+
This is an early public project.
|
|
176
|
+
|
|
177
|
+
The implementation reflects the needs of the project at this stage. The code is covered with tests, CI checks, and documentation that describes both ordinary usage and extension points.
|
|
178
|
+
|
|
179
|
+
Feedback, bug reports, documentation corrections, and practical feature requests are welcome.
|
|
180
|
+
|
|
181
|
+
## Contributing
|
|
182
|
+
|
|
183
|
+
Repository-level contribution rules are documented in:
|
|
184
|
+
|
|
185
|
+
```text
|
|
186
|
+
../CONTRIBUTING.md
|
|
187
|
+
```
|
|
188
|
+
|
|
189
|
+
## License
|
|
190
|
+
|
|
191
|
+
`mvx-common` is licensed under the Apache License, Version 2.0.
|
|
192
|
+
|
|
193
|
+
See:
|
|
194
|
+
|
|
195
|
+
```text
|
|
196
|
+
LICENSE
|
|
197
|
+
NOTICE
|
|
198
|
+
```
|
|
199
|
+
|
|
200
|
+
## Author
|
|
201
|
+
|
|
202
|
+
Vladimir Makarov
|
|
203
|
+
|
|
204
|
+
Contact:
|
|
205
|
+
|
|
206
|
+
```text
|
|
207
|
+
makarovvv.dream@gmail.com
|
|
208
|
+
```
|
|
@@ -0,0 +1,175 @@
|
|
|
1
|
+
# MVX Common
|
|
2
|
+
|
|
3
|
+
[](https://github.com/makarovvvdream-dev/mvx-lib/actions/workflows/common-ci.yml)
|
|
4
|
+
|
|
5
|
+
`mvx-common` is a Python package with foundation-level infrastructure for MVX Python projects.
|
|
6
|
+
|
|
7
|
+
Its main public component is **MVX Logger**.
|
|
8
|
+
|
|
9
|
+
MVX Logger is a lightweight structured event logging infrastructure for applications and reusable Python libraries that need rich and flexible diagnostic visibility.
|
|
10
|
+
|
|
11
|
+
Most logging tools focus on formatting, routing, or collecting log records. MVX Logger focuses on the step before that: how code creates structured diagnostic events, controls their diagnostic data, and hands them over for delivery.
|
|
12
|
+
|
|
13
|
+
## Key features
|
|
14
|
+
|
|
15
|
+
* log structured events with rich, flexible, and structured diagnostic info instead of hand-written log strings
|
|
16
|
+
* control logging width through event policies without changing calling code, focusing logs on current diagnostic needs
|
|
17
|
+
* keep event diagnostic data well-shaped and clean through centralized payload normalization
|
|
18
|
+
* change logging destination and formatting without changing event-producing code
|
|
19
|
+
* deliver events to standard logging streams, files, async sinks, or custom backends
|
|
20
|
+
* keep the logging path fast and thread-safe while slow backends are handled outside the business flow
|
|
21
|
+
* log standardized business operation lifecycles without writing logging code inside the operation body
|
|
22
|
+
* capture selected call arguments, results, errors, and context fields as structured event diagnostic info
|
|
23
|
+
* keep business logic focused on the operation itself instead of repetitive try/except logging blocks
|
|
24
|
+
* start using it almost as simply as regular logging, then move to deeper structured diagnostics when needed
|
|
25
|
+
|
|
26
|
+
## What MVX Logger is not
|
|
27
|
+
|
|
28
|
+
MVX Logger is not a replacement for `logging`, `structlog`, `loguru`, or OpenTelemetry.
|
|
29
|
+
|
|
30
|
+
It is a structured event creation layer that can sit before those tools or other delivery backends.
|
|
31
|
+
|
|
32
|
+
The goal is not to own the whole observability stack. The goal is to make diagnostic event creation explicit, structured, configurable, and safe to use across project boundaries.
|
|
33
|
+
|
|
34
|
+
## Other utilities
|
|
35
|
+
|
|
36
|
+
`mvx-common` also includes smaller foundation utilities used by MVX packages:
|
|
37
|
+
|
|
38
|
+
```text
|
|
39
|
+
structured errors
|
|
40
|
+
public API error normalization helpers
|
|
41
|
+
asyncio cancellation helpers
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
These utilities support predictable public errors, explicit cancellation behavior, and consistent diagnostics.
|
|
45
|
+
|
|
46
|
+
## Requirements
|
|
47
|
+
|
|
48
|
+
`mvx-common` requires Python 3.11 or newer.
|
|
49
|
+
|
|
50
|
+
```text
|
|
51
|
+
Python >= 3.11
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
## Installation for development
|
|
55
|
+
|
|
56
|
+
From the package directory:
|
|
57
|
+
|
|
58
|
+
```bash
|
|
59
|
+
cd common
|
|
60
|
+
python -m pip install -e ".[dev]"
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
To install documentation dependencies as well:
|
|
64
|
+
|
|
65
|
+
```bash
|
|
66
|
+
python -m pip install -e ".[dev,docs]"
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
## Running checks
|
|
70
|
+
|
|
71
|
+
From the package directory:
|
|
72
|
+
|
|
73
|
+
```bash
|
|
74
|
+
scripts/check.sh
|
|
75
|
+
```
|
|
76
|
+
|
|
77
|
+
The check script runs:
|
|
78
|
+
|
|
79
|
+
```text
|
|
80
|
+
black --check
|
|
81
|
+
ruff check
|
|
82
|
+
mypy
|
|
83
|
+
pytest with branch coverage
|
|
84
|
+
```
|
|
85
|
+
|
|
86
|
+
The package requires at least 90% branch coverage.
|
|
87
|
+
|
|
88
|
+
## Documentation
|
|
89
|
+
|
|
90
|
+
Full documentation:
|
|
91
|
+
|
|
92
|
+
```text
|
|
93
|
+
https://mvx-lib.readthedocs.io/en/latest/
|
|
94
|
+
```
|
|
95
|
+
|
|
96
|
+
MVX Logger overview:
|
|
97
|
+
|
|
98
|
+
```text
|
|
99
|
+
https://mvx-lib.readthedocs.io/en/latest/common/logger/overview.html
|
|
100
|
+
```
|
|
101
|
+
|
|
102
|
+
Getting started:
|
|
103
|
+
|
|
104
|
+
```text
|
|
105
|
+
https://mvx-lib.readthedocs.io/en/latest/common/logger/getting_started/
|
|
106
|
+
```
|
|
107
|
+
|
|
108
|
+
Advanced usage:
|
|
109
|
+
|
|
110
|
+
```text
|
|
111
|
+
https://mvx-lib.readthedocs.io/en/latest/common/logger/advanced_usage/
|
|
112
|
+
```
|
|
113
|
+
|
|
114
|
+
`log_invocation` guide:
|
|
115
|
+
|
|
116
|
+
```text
|
|
117
|
+
https://mvx-lib.readthedocs.io/en/latest/common/logger/log_components/log_invocation/overview.html
|
|
118
|
+
```
|
|
119
|
+
|
|
120
|
+
Version history:
|
|
121
|
+
|
|
122
|
+
```text
|
|
123
|
+
https://mvx-lib.readthedocs.io/en/latest/common/version_history/
|
|
124
|
+
```
|
|
125
|
+
|
|
126
|
+
## Building documentation
|
|
127
|
+
|
|
128
|
+
From the repository root:
|
|
129
|
+
|
|
130
|
+
```bash
|
|
131
|
+
scripts/docs.sh
|
|
132
|
+
```
|
|
133
|
+
|
|
134
|
+
The built HTML documentation is written to:
|
|
135
|
+
|
|
136
|
+
```text
|
|
137
|
+
docs/_build/html/
|
|
138
|
+
```
|
|
139
|
+
|
|
140
|
+
## Project status
|
|
141
|
+
|
|
142
|
+
This is an early public project.
|
|
143
|
+
|
|
144
|
+
The implementation reflects the needs of the project at this stage. The code is covered with tests, CI checks, and documentation that describes both ordinary usage and extension points.
|
|
145
|
+
|
|
146
|
+
Feedback, bug reports, documentation corrections, and practical feature requests are welcome.
|
|
147
|
+
|
|
148
|
+
## Contributing
|
|
149
|
+
|
|
150
|
+
Repository-level contribution rules are documented in:
|
|
151
|
+
|
|
152
|
+
```text
|
|
153
|
+
../CONTRIBUTING.md
|
|
154
|
+
```
|
|
155
|
+
|
|
156
|
+
## License
|
|
157
|
+
|
|
158
|
+
`mvx-common` is licensed under the Apache License, Version 2.0.
|
|
159
|
+
|
|
160
|
+
See:
|
|
161
|
+
|
|
162
|
+
```text
|
|
163
|
+
LICENSE
|
|
164
|
+
NOTICE
|
|
165
|
+
```
|
|
166
|
+
|
|
167
|
+
## Author
|
|
168
|
+
|
|
169
|
+
Vladimir Makarov
|
|
170
|
+
|
|
171
|
+
Contact:
|
|
172
|
+
|
|
173
|
+
```text
|
|
174
|
+
makarovvv.dream@gmail.com
|
|
175
|
+
```
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
[project]
|
|
2
|
+
name = "mvx-common"
|
|
3
|
+
version = "0.2.1"
|
|
4
|
+
description = "Common utilities for MVX Python packages."
|
|
5
|
+
readme = "README.md"
|
|
6
|
+
requires-python = ">=3.11"
|
|
7
|
+
license = "Apache-2.0"
|
|
8
|
+
license-files = ["LICENSE", "NOTICE"]
|
|
9
|
+
authors = [
|
|
10
|
+
{ name = "Vladimir Makarov" }
|
|
11
|
+
]
|
|
12
|
+
classifiers = [
|
|
13
|
+
"License :: OSI Approved :: Apache Software License",
|
|
14
|
+
"Programming Language :: Python :: 3",
|
|
15
|
+
"Programming Language :: Python :: 3.11",
|
|
16
|
+
"Programming Language :: Python :: 3.12",
|
|
17
|
+
"Programming Language :: Python :: 3.13",
|
|
18
|
+
]
|
|
19
|
+
dependencies = [
|
|
20
|
+
]
|
|
21
|
+
|
|
22
|
+
[project.urls]
|
|
23
|
+
Documentation = "https://mvx-lib.readthedocs.io/en/latest/"
|
|
24
|
+
Source = "https://github.com/makarovvvdream-dev/mvx-lib"
|
|
25
|
+
Issues = "https://github.com/makarovvvdream-dev/mvx-lib/issues"
|
|
26
|
+
Changelog = "https://mvx-lib.readthedocs.io/en/latest/common/version_history/"
|
|
27
|
+
|
|
28
|
+
[project.optional-dependencies]
|
|
29
|
+
dev = [
|
|
30
|
+
"pytest",
|
|
31
|
+
"pytest-asyncio",
|
|
32
|
+
"pytest-cov",
|
|
33
|
+
"ruff",
|
|
34
|
+
"black",
|
|
35
|
+
"mypy",
|
|
36
|
+
]
|
|
37
|
+
docs = [
|
|
38
|
+
"Sphinx<9",
|
|
39
|
+
"sphinx-rtd-theme",
|
|
40
|
+
"myst-parser",
|
|
41
|
+
"sphinx-autodoc-typehints",
|
|
42
|
+
"enum-tools[sphinx]",
|
|
43
|
+
]
|
|
44
|
+
|
|
45
|
+
[build-system]
|
|
46
|
+
requires = ["hatchling"]
|
|
47
|
+
build-backend = "hatchling.build"
|
|
48
|
+
|
|
49
|
+
[tool.hatch.build.targets.wheel]
|
|
50
|
+
packages = ["src/mvx"]
|
|
51
|
+
|
|
52
|
+
[tool.pytest.ini_options]
|
|
53
|
+
asyncio_mode = "auto"
|
|
54
|
+
|
|
55
|
+
[tool.black]
|
|
56
|
+
line-length = 100
|
|
57
|
+
target-version = ["py311", "py312", "py313"]
|
|
58
|
+
|
|
59
|
+
[tool.mypy]
|
|
60
|
+
files = ["src"]
|
|
61
|
+
python_version = "3.11"
|
|
62
|
+
strict = false
|
|
63
|
+
warn_unused_ignores = true
|
|
64
|
+
warn_return_any = true
|
|
65
|
+
disallow_untyped_defs = true
|
|
66
|
+
ignore_missing_imports = true
|
|
67
|
+
namespace_packages = true
|
|
68
|
+
explicit_package_bases = true
|
|
69
|
+
mypy_path = ["src"]
|
|
70
|
+
|
|
71
|
+
[tool.ruff]
|
|
72
|
+
line-length = 100
|
|
73
|
+
src = ["src"]
|
|
74
|
+
target-version = "py311"
|
|
75
|
+
|
|
76
|
+
[tool.ruff.lint.per-file-ignores]
|
|
77
|
+
"tests/**" = [
|
|
78
|
+
"F841",
|
|
79
|
+
"S101",
|
|
80
|
+
"SLF001",
|
|
81
|
+
"PLR2004",
|
|
82
|
+
"D",
|
|
83
|
+
"ANN",
|
|
84
|
+
"ARG001",
|
|
85
|
+
]
|
|
86
|
+
|
|
87
|
+
[tool.coverage.run]
|
|
88
|
+
branch = true
|
|
89
|
+
source = ["src/mvx/common"]
|
|
90
|
+
|
|
91
|
+
[tool.coverage.report]
|
|
92
|
+
show_missing = true
|
|
93
|
+
skip_covered = false
|
|
94
|
+
fail_under = 90
|
|
95
|
+
exclude_lines = [
|
|
96
|
+
"pragma: no cover",
|
|
97
|
+
"if TYPE_CHECKING:",
|
|
98
|
+
"if __name__ == .__main__.:",
|
|
99
|
+
"raise NotImplementedError",
|
|
100
|
+
"\\.\\.\\.",
|
|
101
|
+
]
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
# common/src/mvx/common/__init__.py
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
# common/src/mvx/common/errors/__init__.py
|
|
2
|
+
|
|
3
|
+
from .structured_error import StructuredError
|
|
4
|
+
from .reasoned_error import ReasonedError
|
|
5
|
+
from .runtime_errors import RuntimeExtendedError, RuntimeUnexpectedError
|
|
6
|
+
from .invalid_function_argument_error import InvalidFunctionArgumentError
|
|
7
|
+
|
|
8
|
+
__all__ = (
|
|
9
|
+
"StructuredError",
|
|
10
|
+
"ReasonedError",
|
|
11
|
+
"RuntimeExtendedError",
|
|
12
|
+
"RuntimeUnexpectedError",
|
|
13
|
+
"InvalidFunctionArgumentError",
|
|
14
|
+
)
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
# common/src/mvx/common/errors/invalid_function_argument_error.py
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
from typing import Any, Mapping, Optional
|
|
5
|
+
|
|
6
|
+
from .structured_error import StructuredError
|
|
7
|
+
|
|
8
|
+
__all__ = ("InvalidFunctionArgumentError",)
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
class InvalidFunctionArgumentError(StructuredError):
|
|
12
|
+
"""
|
|
13
|
+
Error raised when a function argument fails validation.
|
|
14
|
+
|
|
15
|
+
Wraps an underlying validation exception and adds structured context about
|
|
16
|
+
the function, argument, offending value, and validation error type.
|
|
17
|
+
|
|
18
|
+
Args:
|
|
19
|
+
func: Function name where validation failed.
|
|
20
|
+
arg: Argument name that failed validation.
|
|
21
|
+
value: Offending argument value, when safe and useful to log.
|
|
22
|
+
cause: Underlying validation exception.
|
|
23
|
+
details: Additional log-friendly diagnostic context.
|
|
24
|
+
"""
|
|
25
|
+
|
|
26
|
+
def __init__(
|
|
27
|
+
self,
|
|
28
|
+
*,
|
|
29
|
+
func: Optional[str],
|
|
30
|
+
arg: Optional[str],
|
|
31
|
+
value: Optional[Any] = None,
|
|
32
|
+
cause: Exception,
|
|
33
|
+
details: Optional[Mapping[str, Any]] = None,
|
|
34
|
+
) -> None:
|
|
35
|
+
msg = f"invalid argument -> {str(cause)}"
|
|
36
|
+
|
|
37
|
+
func = func or "<unknown>"
|
|
38
|
+
arg = arg or "<unknown>"
|
|
39
|
+
|
|
40
|
+
base_details: dict[str, Any] = {
|
|
41
|
+
"func": func,
|
|
42
|
+
"arg": arg,
|
|
43
|
+
"error_type": type(cause).__name__,
|
|
44
|
+
}
|
|
45
|
+
if value is not None:
|
|
46
|
+
base_details["value"] = value
|
|
47
|
+
if details:
|
|
48
|
+
base_details.update(details)
|
|
49
|
+
|
|
50
|
+
super().__init__(
|
|
51
|
+
message=msg,
|
|
52
|
+
details=base_details,
|
|
53
|
+
cause=cause,
|
|
54
|
+
)
|