Skip to content

Commit 3521c73

Browse files
Add linter checks and unit testing to Github Workflow. (#38)
1 parent 0a9a622 commit 3521c73

File tree

7 files changed

+82
-23
lines changed

7 files changed

+82
-23
lines changed

.github/workflows/build_wheels.yml

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,37 @@ name: Build
33
on: [push, pull_request]
44

55
jobs:
6+
linters:
7+
runs-on: ubuntu-latest
8+
steps:
9+
- uses: actions/checkout@v3
10+
11+
- uses: actions/setup-python@v4
12+
with:
13+
python-version: "3.11"
14+
15+
- run: |
16+
pip install --upgrade pip
17+
pip install -r requirements-dev.txt
18+
19+
- run: docformatter --check --diff clp_ffi_py tests
20+
21+
- run: black --diff --check clp_ffi_py tests
22+
23+
- run: ruff check --output-format=github clp_ffi_py tests
24+
25+
- run: mypy clp_ffi_py tests
26+
27+
- run: |
28+
find src/clp_ffi_py/ -type f | xargs clang-format --dry-run --Werror
29+
630
build_wheels:
31+
needs: [linters]
732
name: Build wheels on ${{ matrix.os }}
833
runs-on: ${{ matrix.os }}
934
strategy:
1035
matrix:
11-
os: [ubuntu-20.04, ubuntu-22.04, macos-11]
36+
os: [ubuntu-22.04, macos-11]
1237

1338
steps:
1439
- uses: actions/checkout@v3
@@ -25,11 +50,12 @@ jobs:
2550
platforms: all
2651

2752
- name: Build wheels
28-
uses: pypa/cibuildwheel@v2.12.3
53+
uses: pypa/cibuildwheel@v2.16.2
2954
env:
3055
CIBW_ARCHS_LINUX: auto aarch64
3156
MACOSX_DEPLOYMENT_TARGET: 10.15
3257

3358
- uses: actions/upload-artifact@v3
3459
with:
60+
name: wheel-${{ matrix.os }}
3561
path: ./wheelhouse/*.whl

MANIFEST.in

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,7 @@ recursive-include src/clp_ffi_py *.inc
66
recursive-include clp_ffi_py *.py
77
recursive-include clp_ffi_py *.pyi
88
recursive-include clp_ffi_py py.typed
9+
include setup.cfg
910
include src/clp/components/core/submodules/json/single_include/nlohmann/json.hpp
1011
include src/GSL/include/gsl/*
12+
recursive-include tests *

pyproject.toml

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,23 @@ target-version = ["py311"]
3636
color = true
3737
preview = true
3838

39+
[tool.cibuildwheel]
40+
skip = "pp*"
41+
42+
test-command = [
43+
"cd {package}/tests",
44+
"python -m unittest -fv",
45+
]
46+
test-requires = [
47+
"smart_open"
48+
]
49+
test-skip = [
50+
"cp37-*",
51+
"cp39-*",
52+
"cp310-*",
53+
"*-*linux_i686",
54+
]
55+
3956
[tool.cibuildwheel.macos]
4057
archs = ["x86_64", "universal2", "arm64"]
4158

@@ -61,4 +78,3 @@ select = ["E", "I", "F"]
6178

6279
[tool.ruff.isort]
6380
order-by-type = false
64-

requirements-dev.txt

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
black>=22.10.0
1+
black>=23.11.0
22
build>=0.8.0
3-
cibuildwheel>=2.12.3
4-
clang-format>=16.0.4
3+
cibuildwheel>=2.16.2
4+
clang-format>=17.0.5
55
docformatter>=1.7.5
6-
mypy>=0.982
7-
mypy-extensions>=0.4.3
6+
mypy>=1.7.1
7+
mypy-extensions>=1.0.0
88
packaging>=21.3
9-
ruff>=0.0.278
9+
ruff>=0.1.6
1010
smart_open>=6.3.0
1111
toml>=0.10.2
1212
tomli>=2.0.1

setup.cfg

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
[options]
2+
install_requires =
3+
python-dateutil >= 2.7.0
4+
typing-extensions >= 4.1.1
5+
zstandard >= 0.18.0

src/clp_ffi_py/ir/native/PyDecoderBuffer.cpp

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,8 @@ auto PyDecoderBuffer_init(PyDecoderBuffer* self, PyObject* args, PyObject* keywo
3232
static char* keyword_table[]{
3333
static_cast<char*>(keyword_input_stream),
3434
static_cast<char*>(keyword_initial_buffer_capacity),
35-
nullptr};
35+
nullptr
36+
};
3637

3738
// If the argument parsing fails, `self` will be deallocated. We must reset
3839
// all pointers to nullptr in advance, otherwise the deallocator might
@@ -54,8 +55,8 @@ auto PyDecoderBuffer_init(PyDecoderBuffer* self, PyObject* args, PyObject* keywo
5455
return -1;
5556
}
5657

57-
PyObjectPtr<PyObject> const readinto_method_obj{
58-
PyObject_GetAttrString(input_stream, "readinto")};
58+
PyObjectPtr<PyObject> const readinto_method_obj{PyObject_GetAttrString(input_stream, "readinto")
59+
};
5960
auto* readinto_method{readinto_method_obj.get()};
6061
if (nullptr == readinto_method) {
6162
return -1;
@@ -153,7 +154,8 @@ PyMethodDef PyDecoderBuffer_method_table[]{
153154
METH_O,
154155
static_cast<char const*>(cPyDecoderBufferTestStreamingDoc)},
155156

156-
{nullptr}};
157+
{nullptr}
158+
};
157159

158160
/**
159161
* Declaration of Python buffer protocol.
@@ -188,7 +190,8 @@ PyType_Slot PyDecoderBuffer_slots[]{
188190
{Py_tp_init, reinterpret_cast<void*>(PyDecoderBuffer_init)},
189191
{Py_tp_methods, static_cast<void*>(PyDecoderBuffer_method_table)},
190192
{Py_tp_doc, const_cast<void*>(static_cast<void const*>(cPyDecoderBufferDoc))},
191-
{0, nullptr}};
193+
{0, nullptr}
194+
};
192195
// NOLINTEND(cppcoreguidelines-avoid-c-arrays, cppcoreguidelines-pro-type-*-cast)
193196

194197
/**
@@ -199,7 +202,8 @@ PyType_Spec PyDecoderBuffer_type_spec{
199202
sizeof(PyDecoderBuffer),
200203
0,
201204
Py_TPFLAGS_DEFAULT,
202-
static_cast<PyType_Slot*>(PyDecoderBuffer_slots)};
205+
static_cast<PyType_Slot*>(PyDecoderBuffer_slots)
206+
};
203207

204208
// NOLINTNEXTLINE(cppcoreguidelines-avoid-c-arrays)
205209
PyDoc_STRVAR(
@@ -225,7 +229,8 @@ auto PyDecoderBuffer::init(PyObject* input_stream, Py_ssize_t buf_capacity) -> b
225229
auto PyDecoderBuffer::populate_read_buffer(Py_ssize_t& num_bytes_read) -> bool {
226230
auto const unconsumed_bytes_in_curr_read_buffer{get_unconsumed_bytes()};
227231
auto const num_unconsumed_bytes{
228-
static_cast<Py_ssize_t>(unconsumed_bytes_in_curr_read_buffer.size())};
232+
static_cast<Py_ssize_t>(unconsumed_bytes_in_curr_read_buffer.size())
233+
};
229234
auto const buffer_capacity{static_cast<Py_ssize_t>(m_read_buffer.size())};
230235

231236
if (num_unconsumed_bytes > (buffer_capacity / 2)) {

src/clp_ffi_py/ir/native/decoding_methods.cpp

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,8 @@ auto decode(
5050
auto const unconsumed_bytes{decoder_buffer->get_unconsumed_bytes()};
5151
BufferReader ir_buffer{
5252
size_checked_pointer_cast<char const>(unconsumed_bytes.data()),
53-
unconsumed_bytes.size()};
53+
unconsumed_bytes.size()
54+
};
5455
auto const err{ffi::ir_stream::four_byte_encoding::decode_next_message(
5556
ir_buffer,
5657
decoded_message,
@@ -129,7 +130,8 @@ auto decode_preamble(PyObject* Py_UNUSED(self), PyObject* py_decoder_buffer) ->
129130
auto const unconsumed_bytes{decoder_buffer->get_unconsumed_bytes()};
130131
BufferReader ir_buffer{
131132
size_checked_pointer_cast<char const>(unconsumed_bytes.data()),
132-
unconsumed_bytes.size()};
133+
unconsumed_bytes.size()
134+
};
133135
auto const err{ffi::ir_stream::get_encoding_type(ir_buffer, is_four_byte_encoding)};
134136
if (ffi::ir_stream::IRErrorCode_Success == err) {
135137
ir_buffer_cursor_pos = ir_buffer.get_pos();
@@ -156,7 +158,8 @@ auto decode_preamble(PyObject* Py_UNUSED(self), PyObject* py_decoder_buffer) ->
156158
auto const unconsumed_bytes = decoder_buffer->get_unconsumed_bytes();
157159
BufferReader ir_buffer{
158160
size_checked_pointer_cast<char const>(unconsumed_bytes.data()),
159-
unconsumed_bytes.size()};
161+
unconsumed_bytes.size()
162+
};
160163
auto const err{ffi::ir_stream::decode_preamble(
161164
ir_buffer,
162165
metadata_type_tag,
@@ -178,7 +181,8 @@ auto decode_preamble(PyObject* Py_UNUSED(self), PyObject* py_decoder_buffer) ->
178181

179182
auto const unconsumed_bytes = decoder_buffer->get_unconsumed_bytes();
180183
auto const metadata_buffer{
181-
unconsumed_bytes.subspan(metadata_pos, static_cast<size_t>(metadata_size))};
184+
unconsumed_bytes.subspan(metadata_pos, static_cast<size_t>(metadata_size))
185+
};
182186
decoder_buffer->commit_read_buffer_consumption(static_cast<Py_ssize_t>(ir_buffer_cursor_pos));
183187
PyMetadata* metadata{nullptr};
184188
try {
@@ -187,8 +191,8 @@ auto decode_preamble(PyObject* Py_UNUSED(self), PyObject* py_decoder_buffer) ->
187191
nlohmann::json const metadata_json(
188192
nlohmann::json::parse(metadata_buffer.begin(), metadata_buffer.end())
189193
);
190-
std::string const version{
191-
metadata_json.at(ffi::ir_stream::cProtocol::Metadata::VersionKey)};
194+
std::string const version{metadata_json.at(ffi::ir_stream::cProtocol::Metadata::VersionKey)
195+
};
192196
auto const error_code{ffi::ir_stream::validate_protocol_version(version)};
193197
if (ffi::ir_stream::IRProtocolErrorCode_Supported != error_code) {
194198
switch (error_code) {
@@ -232,7 +236,8 @@ auto decode_next_log_event(PyObject* Py_UNUSED(self), PyObject* args, PyObject*
232236
static_cast<char*>(keyword_decoder_buffer),
233237
static_cast<char*>(keyword_query),
234238
static_cast<char*>(keyword_allow_incomplete_stream),
235-
nullptr};
239+
nullptr
240+
};
236241

237242
PyDecoderBuffer* decoder_buffer{nullptr};
238243
PyObject* query{Py_None};

0 commit comments

Comments
 (0)