Skip to content

Commit ca04958

Browse files
committed
QDB-16709 - Add stubgen support (#97)
1 parent 4559bff commit ca04958

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

59 files changed

+1390
-514
lines changed

.github/workflows/lint.yml

Lines changed: 27 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,18 @@
1-
name: Lint
1+
name: Format check
22

33
on:
44
push:
55
branches:
66
- master
77
paths:
88
- '**.py'
9+
- '**.pyi'
910
pull_request:
1011
branches:
1112
- master
1213
paths:
1314
- '**.py'
15+
- '**.pyi'
1416

1517
jobs:
1618
lint:
@@ -28,15 +30,30 @@ jobs:
2830
run: |
2931
pip install -r scripts/github_actions/requirements.txt
3032
31-
- name: Run black
32-
id: run_black
33+
- name: Run black on Python files
3334
run: |
3435
black --check --verbose .
3536
36-
# - name: Run post-lint actions
37-
# if: ${{ !cancelled() }}
38-
# env:
39-
# SLACK_BOT_TOKEN: ${{ secrets.SLACK_BOT_TOKEN }}
40-
# SLACK_BOT_CHANNEL: ${{ vars.SLACK_BOT_CHANNEL }}
41-
# run: |
42-
# python scripts/github_actions/post_lint.py ${{ steps.run_black.outcome }}
37+
- name: Run black on stub files
38+
run: |
39+
black --include '\.pyi$' --check --verbose .
40+
41+
# typing:
42+
# runs-on: ubuntu-latest
43+
# steps:
44+
# - name: Check out code
45+
# uses: actions/checkout@v4
46+
47+
# - name: Setup Python version
48+
# uses: actions/setup-python@v5
49+
# with:
50+
# python-version: '3.13'
51+
52+
# - name: Install dependencies
53+
# run: |
54+
# pip install -r scripts/github_actions/requirements.txt
55+
# pip install -r dev-requirements.txt
56+
57+
# - name: Run mypy
58+
# run: |
59+
# mypy --check quasardb

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,9 @@ venv
138138
# PyCharm
139139
.idea
140140

141+
# MacOS
142+
.DS_Store
143+
141144
# Test specific
142145
cluster_private.key
143146
cluster_public.key

dev-requirements.txt

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
# FreeBSD), and there are some conflicting requirements. For example, Numpy
44
# doesn't have any version that works on both Python 3.6 and Python 3.10.
55

6-
numpy ~= 1.19.5; python_version <= '3.7'
6+
# numpy ~= 1.19.5; python_version <= '3.7'
77
numpy ~= 1.20.3; python_version == '3.8'
88
numpy ~= 1.20.3; python_version == '3.9'
99
numpy >= 2.0.1; python_version > '3.9'
@@ -36,4 +36,8 @@ teamcity-messages == 1.29
3636
setuptools-git == 1.2
3737

3838
# Linting
39-
black
39+
black==24.10.0
40+
41+
# Stubs
42+
mypy
43+
pybind11-stubgen

pyproject.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,3 +24,6 @@ addopts = ["-s", "-x"]
2424
xfail_strict = true
2525
filterwarnings = []
2626
testpaths = ["tests"]
27+
28+
# [tool.mypy]
29+
# python_version = "3.9"

quasardb/__init__.py

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,10 @@
3636
"""
3737

3838

39-
def generic_error_msg(msg, e=None):
39+
from typing import List, Optional
40+
41+
42+
def generic_error_msg(msg: List[str], e: Optional[BaseException] = None) -> str:
4043
msg_str = "\n".join(msg)
4144

4245
if e is None:
@@ -47,7 +50,7 @@ def generic_error_msg(msg, e=None):
4750
4851
**************************************************************************
4952
""".format(
50-
msg_str, type(e), str(e)
53+
msg_str
5154
)
5255
else:
5356
return """
@@ -68,7 +71,7 @@ def generic_error_msg(msg, e=None):
6871
)
6972

7073

71-
def link_error_msg(e):
74+
def link_error_msg(e: BaseException) -> str:
7275
msg = [
7376
"QuasarDB was unable to find all expected symbols in the compiled library.",
7477
"This is usually caused by running an incorrect version of the QuasarDB C",
@@ -82,7 +85,7 @@ def link_error_msg(e):
8285
return generic_error_msg(msg, e)
8386

8487

85-
def glibc_error_msg(e):
88+
def glibc_error_msg(e: BaseException) -> str:
8689
msg = [
8790
"QuasarDB was unable to find the expected GLIBC version on this machine.",
8891
"This is usually caused by compiling the Python API on a different machine "
@@ -99,7 +102,7 @@ def glibc_error_msg(e):
99102
return generic_error_msg(msg, e)
100103

101104

102-
def unknown_error_msg():
105+
def unknown_error_msg() -> str:
103106
msg = [
104107
"Unable to import quasardb module: unknown error. ",
105108
"",

quasardb/__init__.pyi

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
"""
2+
3+
.. module: quasardb
4+
:platform: Unix, Windows
5+
:synopsis: quasardb official Python API
6+
7+
.. moduleauthor: quasardb SAS. All rights reserved
8+
"""
9+
10+
from __future__ import annotations
11+
12+
from quasardb.quasardb import (
13+
AliasAlreadyExistsError,
14+
AliasNotFoundError,
15+
AsyncPipelineFullError,
16+
BatchColumnInfo,
17+
Cluster,
18+
ColumnInfo,
19+
ColumnType,
20+
Error,
21+
IncompatibleTypeError,
22+
IndexedColumnInfo,
23+
InputBufferTooSmallError,
24+
InternalLocalError,
25+
InvalidArgumentError,
26+
InvalidDatetimeError,
27+
InvalidHandleError,
28+
InvalidQueryError,
29+
Node,
30+
NotImplementedError,
31+
OutOfBoundsError,
32+
RetryOptions,
33+
TryAgainError,
34+
UninitializedError,
35+
WriterData,
36+
WriterPushMode,
37+
build,
38+
metrics,
39+
never_expires,
40+
version,
41+
)
42+
43+
__all__ = [
44+
"AliasAlreadyExistsError",
45+
"AliasNotFoundError",
46+
"AsyncPipelineFullError",
47+
"BatchColumnInfo",
48+
"Cluster",
49+
"ColumnInfo",
50+
"ColumnType",
51+
"Error",
52+
"IncompatibleTypeError",
53+
"IndexedColumnInfo",
54+
"InputBufferTooSmallError",
55+
"InternalLocalError",
56+
"InvalidArgumentError",
57+
"InvalidDatetimeError",
58+
"InvalidHandleError",
59+
"InvalidQueryError",
60+
"Node",
61+
"NotImplementedError",
62+
"OutOfBoundsError",
63+
"RetryOptions",
64+
"TryAgainError",
65+
"UninitializedError",
66+
"WriterData",
67+
"WriterPushMode",
68+
"build",
69+
"metrics",
70+
"never_expires",
71+
"version",
72+
]

quasardb/batch_column.hpp

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -67,14 +67,14 @@ static inline void register_batch_column(Module & m)
6767
{
6868
namespace py = pybind11;
6969

70-
py::class_<qdb::batch_column_info>{m, "BatchColumnInfo"} //
71-
.def(py::init<const std::string &, const std::string &, qdb_size_t>(), //
72-
py::arg("ts_name"), //
73-
py::arg("col_name"), //
74-
py::arg("size_hint") = 0) //
75-
.def_readwrite("timeseries", &qdb::batch_column_info::timeseries) //
76-
.def_readwrite("column", &qdb::batch_column_info::column) //
77-
.def_readwrite("elements_count_hint", &qdb::batch_column_info::elements_count_hint); //
70+
py::class_<qdb::batch_column_info>{m, "BatchColumnInfo"}
71+
.def(py::init<const std::string &, const std::string &, qdb_size_t>(),
72+
py::arg("ts_name"),
73+
py::arg("col_name"),
74+
py::arg("size_hint") = 0)
75+
.def_readwrite("timeseries", &qdb::batch_column_info::timeseries)
76+
.def_readwrite("column", &qdb::batch_column_info::column)
77+
.def_readwrite("elements_count_hint", &qdb::batch_column_info::elements_count_hint);
7878
}
7979

8080
} // namespace qdb

quasardb/batch_inserter.hpp

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -225,18 +225,21 @@ static inline void register_batch_inserter(Module & m)
225225
{
226226
namespace py = pybind11;
227227

228-
py::class_<qdb::batch_inserter>{m, "TimeSeriesBatch"} //
229-
.def(py::init<qdb::handle_ptr, const std::vector<batch_column_info> &>()) //
228+
py::class_<qdb::batch_inserter>{m, "TimeSeriesBatch"}
229+
.def(py::init([](py::args, py::kwargs) {
230+
throw qdb::direct_instantiation_exception{"conn.ts_batch(...)"};
231+
return nullptr;
232+
}))
230233
.def("start_row", &qdb::batch_inserter::start_row,
231-
"Calling this function marks the beginning of processing a new row.") //
232-
.def("set_blob", &qdb::batch_inserter::set_blob) //
233-
.def("set_string", &qdb::batch_inserter::set_string) //
234-
.def("set_double", &qdb::batch_inserter::set_double) //
235-
.def("set_int64", &qdb::batch_inserter::set_int64) //
236-
.def("set_timestamp", &qdb::batch_inserter::set_timestamp) //
237-
.def("push", &qdb::batch_inserter::push, "Regular batch push") //
234+
"Calling this function marks the beginning of processing a new row.")
235+
.def("set_blob", &qdb::batch_inserter::set_blob)
236+
.def("set_string", &qdb::batch_inserter::set_string)
237+
.def("set_double", &qdb::batch_inserter::set_double)
238+
.def("set_int64", &qdb::batch_inserter::set_int64)
239+
.def("set_timestamp", &qdb::batch_inserter::set_timestamp)
240+
.def("push", &qdb::batch_inserter::push, "Regular batch push")
238241
.def("push_async", &qdb::batch_inserter::push_async,
239-
"Asynchronous batch push that buffers data inside the QuasarDB daemon") //
242+
"Asynchronous batch push that buffers data inside the QuasarDB daemon")
240243
.def("push_fast", &qdb::batch_inserter::push_fast,
241244
"Fast, in-place batch push that is efficient when doing lots of small, incremental pushes.")
242245
.def("push_truncate", &qdb::batch_inserter::push_truncate,

quasardb/blob.hpp

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -133,18 +133,21 @@ static inline void register_blob(Module & m)
133133
{
134134
namespace py = pybind11;
135135

136-
py::class_<qdb::blob_entry, qdb::expirable_entry>(m, "Blob") //
137-
.def(py::init<qdb::handle_ptr, std::string>()) //
138-
.def("get", &qdb::blob_entry::get) //
139-
.def("put", &qdb::blob_entry::put, py::arg("data")) //
136+
py::class_<qdb::blob_entry, qdb::expirable_entry>(m, "Blob")
137+
.def(py::init([](py::args, py::kwargs) {
138+
throw qdb::direct_instantiation_exception{"conn.blob(...)"};
139+
return nullptr;
140+
}))
141+
.def("get", &qdb::blob_entry::get)
142+
.def("put", &qdb::blob_entry::put, py::arg("data"))
140143
.def("update", &qdb::blob_entry::update, py::arg("data"),
141-
py::arg("expiry") = std::chrono::system_clock::time_point{}) //
142-
.def("remove_if", &qdb::blob_entry::remove_if, py::arg("comparand")) //
143-
.def("get_and_remove", &qdb::blob_entry::get_and_remove) //
144-
.def("get_and_update", &qdb::blob_entry::get_and_update, //
145-
py::arg("data")) //
146-
.def("compare_and_swap", &qdb::blob_entry::compare_and_swap, //
147-
py::arg("new_content"), py::arg("comparand")); //
144+
py::arg("expiry") = std::chrono::system_clock::time_point{})
145+
.def("remove_if", &qdb::blob_entry::remove_if, py::arg("comparand"))
146+
.def("get_and_remove", &qdb::blob_entry::get_and_remove)
147+
.def("get_and_update", &qdb::blob_entry::get_and_update,
148+
py::arg("data"))
149+
.def("compare_and_swap", &qdb::blob_entry::compare_and_swap,
150+
py::arg("new_content"), py::arg("comparand"));
148151
}
149152

150153
} // namespace qdb

0 commit comments

Comments
 (0)