From 3521c731088b8b237db65dc624cd1757aa881502 Mon Sep 17 00:00:00 2001 From: Lin Zhihao <59785146+LinZhihao-723@users.noreply.github.com> Date: Mon, 27 Nov 2023 23:28:19 -0500 Subject: [PATCH] Add linter checks and unit testing to Github Workflow. (#38) --- .github/workflows/build_wheels.yml | 30 +++++++++++++++++-- MANIFEST.in | 2 ++ pyproject.toml | 18 ++++++++++- requirements-dev.txt | 12 ++++---- setup.cfg | 5 ++++ src/clp_ffi_py/ir/native/PyDecoderBuffer.cpp | 19 +++++++----- src/clp_ffi_py/ir/native/decoding_methods.cpp | 19 +++++++----- 7 files changed, 82 insertions(+), 23 deletions(-) create mode 100644 setup.cfg diff --git a/.github/workflows/build_wheels.yml b/.github/workflows/build_wheels.yml index 7cce82be..1a4a580c 100644 --- a/.github/workflows/build_wheels.yml +++ b/.github/workflows/build_wheels.yml @@ -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 @@ -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 diff --git a/MANIFEST.in b/MANIFEST.in index 48c91d31..a5cc53ab 100644 --- a/MANIFEST.in +++ b/MANIFEST.in @@ -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 * \ No newline at end of file diff --git a/pyproject.toml b/pyproject.toml index 58db2e42..d31e34b2 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -36,6 +36,23 @@ target-version = ["py311"] color = true preview = true +[tool.cibuildwheel] +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"] @@ -61,4 +78,3 @@ select = ["E", "I", "F"] [tool.ruff.isort] order-by-type = false - diff --git a/requirements-dev.txt b/requirements-dev.txt index ca6ef940..97df73f7 100644 --- a/requirements-dev.txt +++ b/requirements-dev.txt @@ -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 diff --git a/setup.cfg b/setup.cfg new file mode 100644 index 00000000..b1ac2cb0 --- /dev/null +++ b/setup.cfg @@ -0,0 +1,5 @@ +[options] +install_requires = + python-dateutil >= 2.7.0 + typing-extensions >= 4.1.1 + zstandard >= 0.18.0 diff --git a/src/clp_ffi_py/ir/native/PyDecoderBuffer.cpp b/src/clp_ffi_py/ir/native/PyDecoderBuffer.cpp index d873c780..ea0a453b 100644 --- a/src/clp_ffi_py/ir/native/PyDecoderBuffer.cpp +++ b/src/clp_ffi_py/ir/native/PyDecoderBuffer.cpp @@ -32,7 +32,8 @@ auto PyDecoderBuffer_init(PyDecoderBuffer* self, PyObject* args, PyObject* keywo static char* keyword_table[]{ static_cast(keyword_input_stream), static_cast(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 @@ -54,8 +55,8 @@ auto PyDecoderBuffer_init(PyDecoderBuffer* self, PyObject* args, PyObject* keywo return -1; } - PyObjectPtr const readinto_method_obj{ - PyObject_GetAttrString(input_stream, "readinto")}; + PyObjectPtr const readinto_method_obj{PyObject_GetAttrString(input_stream, "readinto") + }; auto* readinto_method{readinto_method_obj.get()}; if (nullptr == readinto_method) { return -1; @@ -153,7 +154,8 @@ PyMethodDef PyDecoderBuffer_method_table[]{ METH_O, static_cast(cPyDecoderBufferTestStreamingDoc)}, - {nullptr}}; + {nullptr} +}; /** * Declaration of Python buffer protocol. @@ -188,7 +190,8 @@ PyType_Slot PyDecoderBuffer_slots[]{ {Py_tp_init, reinterpret_cast(PyDecoderBuffer_init)}, {Py_tp_methods, static_cast(PyDecoderBuffer_method_table)}, {Py_tp_doc, const_cast(static_cast(cPyDecoderBufferDoc))}, - {0, nullptr}}; + {0, nullptr} +}; // NOLINTEND(cppcoreguidelines-avoid-c-arrays, cppcoreguidelines-pro-type-*-cast) /** @@ -199,7 +202,8 @@ PyType_Spec PyDecoderBuffer_type_spec{ sizeof(PyDecoderBuffer), 0, Py_TPFLAGS_DEFAULT, - static_cast(PyDecoderBuffer_slots)}; + static_cast(PyDecoderBuffer_slots) +}; // NOLINTNEXTLINE(cppcoreguidelines-avoid-c-arrays) PyDoc_STRVAR( @@ -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(unconsumed_bytes_in_curr_read_buffer.size())}; + static_cast(unconsumed_bytes_in_curr_read_buffer.size()) + }; auto const buffer_capacity{static_cast(m_read_buffer.size())}; if (num_unconsumed_bytes > (buffer_capacity / 2)) { diff --git a/src/clp_ffi_py/ir/native/decoding_methods.cpp b/src/clp_ffi_py/ir/native/decoding_methods.cpp index 77136cdf..d19a95a9 100644 --- a/src/clp_ffi_py/ir/native/decoding_methods.cpp +++ b/src/clp_ffi_py/ir/native/decoding_methods.cpp @@ -50,7 +50,8 @@ auto decode( auto const unconsumed_bytes{decoder_buffer->get_unconsumed_bytes()}; BufferReader ir_buffer{ size_checked_pointer_cast(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, @@ -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(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(); @@ -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(unconsumed_bytes.data()), - unconsumed_bytes.size()}; + unconsumed_bytes.size() + }; auto const err{ffi::ir_stream::decode_preamble( ir_buffer, metadata_type_tag, @@ -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(metadata_size))}; + unconsumed_bytes.subspan(metadata_pos, static_cast(metadata_size)) + }; decoder_buffer->commit_read_buffer_consumption(static_cast(ir_buffer_cursor_pos)); PyMetadata* metadata{nullptr}; try { @@ -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) { @@ -232,7 +236,8 @@ auto decode_next_log_event(PyObject* Py_UNUSED(self), PyObject* args, PyObject* static_cast(keyword_decoder_buffer), static_cast(keyword_query), static_cast(keyword_allow_incomplete_stream), - nullptr}; + nullptr + }; PyDecoderBuffer* decoder_buffer{nullptr}; PyObject* query{Py_None};