Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add linter checks and unit testing to Github Workflow. #38

Merged
merged 22 commits into from
Nov 28, 2023
Merged
Show file tree
Hide file tree
Changes from 21 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 28 additions & 2 deletions .github/workflows/build_wheels.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,37 @@ name: Build
on: [push, pull_request]

jobs:
linters:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3

- uses: actions/setup-python@v4
with:
python-version: "3.11"

- run: |
pip install --upgrade pip
pip install -r requirements-dev.txt

- run: docformatter --check --diff clp_ffi_py tests

- run: black --diff --check clp_ffi_py tests

- run: ruff check --output-format=github clp_ffi_py tests

- run: mypy clp_ffi_py tests

- run: |
find src/clp_ffi_py/ -type f | xargs clang-format --dry-run --Werror

build_wheels:
needs: [linters]
name: Build wheels on ${{ matrix.os }}
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [ubuntu-20.04, ubuntu-22.04, macos-11]
os: [ubuntu-22.04, macos-11]

steps:
- uses: actions/checkout@v3
Expand All @@ -25,11 +50,12 @@ jobs:
platforms: all

- name: Build wheels
uses: pypa/cibuildwheel@v2.12.3
uses: pypa/cibuildwheel@v2.16.2
env:
CIBW_ARCHS_LINUX: auto aarch64
MACOSX_DEPLOYMENT_TARGET: 10.15

- uses: actions/upload-artifact@v3
with:
name: wheel-${{ matrix.os }}
path: ./wheelhouse/*.whl
2 changes: 2 additions & 0 deletions MANIFEST.in
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,7 @@ recursive-include src/clp_ffi_py *.inc
recursive-include clp_ffi_py *.py
recursive-include clp_ffi_py *.pyi
recursive-include clp_ffi_py py.typed
include setup.cfg
include src/clp/components/core/submodules/json/single_include/nlohmann/json.hpp
include src/GSL/include/gsl/*
recursive-include tests *
23 changes: 22 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,28 @@ target-version = ["py311"]
color = true
preview = true

[tool.cibuildwheel]
musllinux-aarch64-image = "musllinux_1_2"
musllinux-i686-image = "musllinux_1_2"
musllinux-ppc64le-image = "musllinux_1_2"
musllinux-s390x-image = "musllinux_1_2"
musllinux-x86_64-image = "musllinux_1_2"
skip = "pp*"

test-command = [
"cd {package}/tests",
"python -m unittest -fv",
]
test-requires = [
"smart_open"
]
test-skip = [
"cp37-*",
"cp39-*",
"cp310-*",
"*-*linux_i686",
]

[tool.cibuildwheel.macos]
archs = ["x86_64", "universal2", "arm64"]

Expand All @@ -61,4 +83,3 @@ select = ["E", "I", "F"]

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

12 changes: 6 additions & 6 deletions requirements-dev.txt
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
black>=22.10.0
black>=23.11.0
build>=0.8.0
cibuildwheel>=2.12.3
clang-format>=16.0.4
cibuildwheel>=2.16.2
clang-format>=17.0.5
docformatter>=1.7.5
mypy>=0.982
mypy-extensions>=0.4.3
mypy>=1.7.1
mypy-extensions>=1.0.0
packaging>=21.3
ruff>=0.0.278
ruff>=0.1.6
smart_open>=6.3.0
toml>=0.10.2
tomli>=2.0.1
Expand Down
5 changes: 5 additions & 0 deletions setup.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
[options]
install_requires =
python-dateutil >= 2.7.0
typing-extensions >= 4.1.1
zstandard >= 0.18.0
19 changes: 12 additions & 7 deletions src/clp_ffi_py/ir/native/PyDecoderBuffer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@ auto PyDecoderBuffer_init(PyDecoderBuffer* self, PyObject* args, PyObject* keywo
static char* keyword_table[]{
static_cast<char*>(keyword_input_stream),
static_cast<char*>(keyword_initial_buffer_capacity),
nullptr};
nullptr
};

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

PyObjectPtr<PyObject> const readinto_method_obj{
PyObject_GetAttrString(input_stream, "readinto")};
PyObjectPtr<PyObject> const readinto_method_obj{PyObject_GetAttrString(input_stream, "readinto")
};
auto* readinto_method{readinto_method_obj.get()};
if (nullptr == readinto_method) {
return -1;
Expand Down Expand Up @@ -153,7 +154,8 @@ PyMethodDef PyDecoderBuffer_method_table[]{
METH_O,
static_cast<char const*>(cPyDecoderBufferTestStreamingDoc)},

{nullptr}};
{nullptr}
};

/**
* Declaration of Python buffer protocol.
Expand Down Expand Up @@ -188,7 +190,8 @@ PyType_Slot PyDecoderBuffer_slots[]{
{Py_tp_init, reinterpret_cast<void*>(PyDecoderBuffer_init)},
{Py_tp_methods, static_cast<void*>(PyDecoderBuffer_method_table)},
{Py_tp_doc, const_cast<void*>(static_cast<void const*>(cPyDecoderBufferDoc))},
{0, nullptr}};
{0, nullptr}
};
// NOLINTEND(cppcoreguidelines-avoid-c-arrays, cppcoreguidelines-pro-type-*-cast)

/**
Expand All @@ -199,7 +202,8 @@ PyType_Spec PyDecoderBuffer_type_spec{
sizeof(PyDecoderBuffer),
0,
Py_TPFLAGS_DEFAULT,
static_cast<PyType_Slot*>(PyDecoderBuffer_slots)};
static_cast<PyType_Slot*>(PyDecoderBuffer_slots)
};

// NOLINTNEXTLINE(cppcoreguidelines-avoid-c-arrays)
PyDoc_STRVAR(
Expand All @@ -225,7 +229,8 @@ auto PyDecoderBuffer::init(PyObject* input_stream, Py_ssize_t buf_capacity) -> b
auto PyDecoderBuffer::populate_read_buffer(Py_ssize_t& num_bytes_read) -> bool {
auto const unconsumed_bytes_in_curr_read_buffer{get_unconsumed_bytes()};
auto const num_unconsumed_bytes{
static_cast<Py_ssize_t>(unconsumed_bytes_in_curr_read_buffer.size())};
static_cast<Py_ssize_t>(unconsumed_bytes_in_curr_read_buffer.size())
};
auto const buffer_capacity{static_cast<Py_ssize_t>(m_read_buffer.size())};

if (num_unconsumed_bytes > (buffer_capacity / 2)) {
Expand Down
19 changes: 12 additions & 7 deletions src/clp_ffi_py/ir/native/decoding_methods.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,8 @@ auto decode(
auto const unconsumed_bytes{decoder_buffer->get_unconsumed_bytes()};
BufferReader ir_buffer{
size_checked_pointer_cast<char const>(unconsumed_bytes.data()),
unconsumed_bytes.size()};
unconsumed_bytes.size()
};
auto const err{ffi::ir_stream::four_byte_encoding::decode_next_message(
ir_buffer,
decoded_message,
Expand Down Expand Up @@ -129,7 +130,8 @@ auto decode_preamble(PyObject* Py_UNUSED(self), PyObject* py_decoder_buffer) ->
auto const unconsumed_bytes{decoder_buffer->get_unconsumed_bytes()};
BufferReader ir_buffer{
size_checked_pointer_cast<char const>(unconsumed_bytes.data()),
unconsumed_bytes.size()};
unconsumed_bytes.size()
};
auto const err{ffi::ir_stream::get_encoding_type(ir_buffer, is_four_byte_encoding)};
if (ffi::ir_stream::IRErrorCode_Success == err) {
ir_buffer_cursor_pos = ir_buffer.get_pos();
Expand All @@ -156,7 +158,8 @@ auto decode_preamble(PyObject* Py_UNUSED(self), PyObject* py_decoder_buffer) ->
auto const unconsumed_bytes = decoder_buffer->get_unconsumed_bytes();
BufferReader ir_buffer{
size_checked_pointer_cast<char const>(unconsumed_bytes.data()),
unconsumed_bytes.size()};
unconsumed_bytes.size()
};
auto const err{ffi::ir_stream::decode_preamble(
ir_buffer,
metadata_type_tag,
Expand All @@ -178,7 +181,8 @@ auto decode_preamble(PyObject* Py_UNUSED(self), PyObject* py_decoder_buffer) ->

auto const unconsumed_bytes = decoder_buffer->get_unconsumed_bytes();
auto const metadata_buffer{
unconsumed_bytes.subspan(metadata_pos, static_cast<size_t>(metadata_size))};
unconsumed_bytes.subspan(metadata_pos, static_cast<size_t>(metadata_size))
};
decoder_buffer->commit_read_buffer_consumption(static_cast<Py_ssize_t>(ir_buffer_cursor_pos));
PyMetadata* metadata{nullptr};
try {
Expand All @@ -187,8 +191,8 @@ auto decode_preamble(PyObject* Py_UNUSED(self), PyObject* py_decoder_buffer) ->
nlohmann::json const metadata_json(
nlohmann::json::parse(metadata_buffer.begin(), metadata_buffer.end())
);
std::string const version{
metadata_json.at(ffi::ir_stream::cProtocol::Metadata::VersionKey)};
std::string const version{metadata_json.at(ffi::ir_stream::cProtocol::Metadata::VersionKey)
};
auto const error_code{ffi::ir_stream::validate_protocol_version(version)};
if (ffi::ir_stream::IRProtocolErrorCode_Supported != error_code) {
switch (error_code) {
Expand Down Expand Up @@ -232,7 +236,8 @@ auto decode_next_log_event(PyObject* Py_UNUSED(self), PyObject* args, PyObject*
static_cast<char*>(keyword_decoder_buffer),
static_cast<char*>(keyword_query),
static_cast<char*>(keyword_allow_incomplete_stream),
nullptr};
nullptr
};

PyDecoderBuffer* decoder_buffer{nullptr};
PyObject* query{Py_None};
Expand Down
Loading