Skip to content

Commit 2a633eb

Browse files
committed
feat(core): add JSON-RPC helpers
Signed-off-by: Ronan Abhamon <ronan.abhamon@vates.tech>
1 parent 7a054e5 commit 2a633eb

8 files changed

Lines changed: 928 additions & 2 deletions

File tree

‎.github/workflows/code-checkers.yml‎

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,3 +28,16 @@ jobs:
2828

2929
- name: Mypy check
3030
run: mypy
31+
32+
tests:
33+
name: Tests
34+
runs-on: ubuntu-latest
35+
steps:
36+
- uses: actions/checkout@v4
37+
- uses: ./.github/actions/setup-python-env
38+
39+
- name: Install Pytest
40+
run: pip install pytest
41+
42+
- name: Pytest check
43+
run: pytest

‎pyproject.toml‎

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
[tool.mypy]
22
mypy_path = "stubs"
33
files = [
4-
"src"
4+
"src",
5+
"tests"
56
]
67

78
disallow_untyped_defs = true
@@ -32,7 +33,8 @@ disallow_untyped_defs = false
3233

3334
[tool.ruff]
3435
include = [
35-
"src/**/*.py"
36+
"src/**/*.py",
37+
"tests/**/*.py"
3638
]
3739
line-length = 120
3840

@@ -116,3 +118,4 @@ ban-relative-imports = "all"
116118

117119
[tool.pytest.ini_options]
118120
pythonpath = ["src", "stubs"]
121+
testpaths = ["tests"]

‎src/xcp_storage/utils/__init__.py‎

Whitespace-only changes.

‎src/xcp_storage/utils/exception.py‎

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
# Copyright (C) 2026 Vates SAS
2+
#
3+
# This program is free software: you can redistribute it and/or modify
4+
# it under the terms of the GNU General Public License as published by
5+
# the Free Software Foundation, either version 3 of the License, or
6+
# (at your option) any later version.
7+
# This program is distributed in the hope that it will be useful,
8+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
9+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10+
# GNU General Public License for more details.
11+
#
12+
# You should have received a copy of the GNU General Public License
13+
# along with this program. If not, see <https://www.gnu.org/licenses/>.
14+
15+
# ==============================================================================
16+
17+
def stringify_exception(e: Exception) -> str:
18+
try:
19+
return str(e)
20+
except Exception:
21+
try:
22+
return f"Exception of type `{e.__class__.__name__}`."
23+
except Exception:
24+
return "Unknown Exception."
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
# Copyright (C) 2026 Vates SAS
2+
#
3+
# This program is free software: you can redistribute it and/or modify
4+
# it under the terms of the GNU General Public License as published by
5+
# the Free Software Foundation, either version 3 of the License, or
6+
# (at your option) any later version.
7+
# This program is distributed in the hope that it will be useful,
8+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
9+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10+
# GNU General Public License for more details.
11+
#
12+
# You should have received a copy of the GNU General Public License
13+
# along with this program. If not, see <https://www.gnu.org/licenses/>.
14+
15+
from xcp_storage.typing import (
16+
Dict,
17+
List,
18+
Union,
19+
)
20+
21+
# ==============================================================================
22+
23+
JsonValue = Union[
24+
str,
25+
int,
26+
float,
27+
bool,
28+
None,
29+
List["JsonValue"],
30+
Dict[str, "JsonValue"]
31+
]
32+
33+
JsonDict = Dict[str, JsonValue]
34+
JsonList = List[JsonValue]

0 commit comments

Comments
 (0)