From c79ffc8794fc41c96b8969711cb96d91e91c7fff Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Fri, 6 May 2022 11:41:02 +0000 Subject: [PATCH 01/13] Bump docker/setup-qemu-action from 1 to 2 Bumps [docker/setup-qemu-action](https://github.com/docker/setup-qemu-action) from 1 to 2. - [Release notes](https://github.com/docker/setup-qemu-action/releases) - [Commits](https://github.com/docker/setup-qemu-action/compare/v1...v2) --- updated-dependencies: - dependency-name: docker/setup-qemu-action dependency-type: direct:production update-type: version-update:semver-major ... Signed-off-by: dependabot[bot] --- .github/workflows/python-package.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/python-package.yml b/.github/workflows/python-package.yml index a199475..2a12acc 100644 --- a/.github/workflows/python-package.yml +++ b/.github/workflows/python-package.yml @@ -70,7 +70,7 @@ jobs: - name: Install QEMU # install QEMU if building for arm linux - uses: docker/setup-qemu-action@v1 + uses: docker/setup-qemu-action@v2 if: runner.os == 'linux' && matrix.arch[3] == 'aarch64' with: platforms: arm64 From 9eaaf901f34eb6aeb8ae3f79542fb69b6cfbb6e0 Mon Sep 17 00:00:00 2001 From: Andrew Cassidy Date: Sun, 8 May 2022 16:06:36 -0700 Subject: [PATCH 02/13] Fix compilation of test wrapper --- CMakeLists.txt | 9 ++++++++- setup.py | 20 ++++++-------------- 2 files changed, 14 insertions(+), 15 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 0bd1c44..7f26a43 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -5,7 +5,14 @@ include(tools/CompilerWarnings.cmake) project(quicktex) # Find dependencies -find_package(Python COMPONENTS Interpreter Development.Module) +if (DEFINED QUICKTEX_MODULE_ONLY) + # Not all python installs include the headers necessary for embedding. If we are only building the module, + # we can ignore the embed headers + find_package(Python COMPONENTS Interpreter Development.Module) +else () + find_package(Python COMPONENTS Interpreter Development) +endif () + find_package(pybind11 CONFIG REQUIRED) find_package(OpenMP) diff --git a/setup.py b/setup.py index c7af897..b5d9f98 100644 --- a/setup.py +++ b/setup.py @@ -1,9 +1,9 @@ import os import re -import sys import subprocess -import pybind11 +import sys +import pybind11 from setuptools import setup, Extension from setuptools.command.build_ext import build_ext @@ -43,7 +43,8 @@ class CMakeBuild(build_ext): "-Dpybind11_DIR={}".format(pybind11.get_cmake_dir()), "-DPython_EXECUTABLE={}".format(sys.executable), "-DPython_ROOT_DIR={}".format(os.path.dirname(sys.executable)), - "-DQUICKTEX_VERSION_INFO={}".format(version), + "-DQUICKTEX_VERSION_INFO={}".format(version), # include version info in module + "-DQUICKTEX_MODULE_ONLY=TRUE", # only build the module, not the wrapper "-DCMAKE_BUILD_TYPE={}".format(cfg), # not used on MSVC, but no harm # clear cached make program binary, see https://github.com/pypa/setuptools/issues/2912 "-U", @@ -68,12 +69,7 @@ class CMakeBuild(build_ext): contains_arch = any(x in cmake_generator for x in {"ARM", "Win64"}) # Convert distutils Windows platform specifiers to CMake -A arguments - plat_to_cmake = { - "win32": "Win32", - "win-amd64": "x64", - "win-arm32": "ARM", - "win-arm64": "ARM64", - } + plat_to_cmake = {"win32": "Win32", "win-amd64": "x64", "win-arm32": "ARM", "win-arm64": "ARM64"} # Specify the arch if using MSVC generator, but only if it doesn't # contain a backward-compatibility arch spec already in the @@ -110,8 +106,4 @@ class CMakeBuild(build_ext): # The information here can also be placed in setup.cfg - better separation of # logic and declaration, and simpler if you include description/version in a file. -setup( - use_scm_version=True, - ext_modules=[CMakeExtension("_quicktex")], - cmdclass={"build_ext": CMakeBuild}, -) +setup(use_scm_version=True, ext_modules=[CMakeExtension("_quicktex")], cmdclass={"build_ext": CMakeBuild}) From 5c947828767c9140b2e5cd7cbf524064f7941530 Mon Sep 17 00:00:00 2001 From: Andrew Cassidy Date: Tue, 10 May 2022 22:08:01 -0700 Subject: [PATCH 03/13] Remove debug wrapper, now that I know how to use a debug python build --- CMakeLists.txt | 31 ++++++------------------------- setup.py | 4 +++- tests/run_tests.cpp | 44 -------------------------------------------- 3 files changed, 9 insertions(+), 70 deletions(-) delete mode 100644 tests/run_tests.cpp diff --git a/CMakeLists.txt b/CMakeLists.txt index 7f26a43..ba125f3 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,18 +1,11 @@ cmake_minimum_required(VERSION 3.18) -include(CheckIPOSupported) include(tools/CompilerWarnings.cmake) +set(CMAKE_VERBOSE_MAKEFILE ON) project(quicktex) # Find dependencies -if (DEFINED QUICKTEX_MODULE_ONLY) - # Not all python installs include the headers necessary for embedding. If we are only building the module, - # we can ignore the embed headers - find_package(Python COMPONENTS Interpreter Development.Module) -else () - find_package(Python COMPONENTS Interpreter Development) -endif () - +find_package(Python COMPONENTS Interpreter Development.Module) find_package(pybind11 CONFIG REQUIRED) find_package(OpenMP) @@ -37,8 +30,6 @@ file(GLOB HEADER_FILES "quicktex/s3tc/interpolator/*.h" ) -file(GLOB TEST_FILES "tests/*.cpp") - file(GLOB_RECURSE PYTHON_FILES "src/**/*.py") # Organize source files together for some IDEs @@ -49,34 +40,24 @@ pybind11_add_module(_quicktex ${SOURCE_FILES} ${HEADER_FILES}) -add_executable(test_quicktex - ${SOURCE_FILES} - ${HEADER_FILES} - ${TEST_FILES}) - -target_link_libraries(test_quicktex PRIVATE pybind11::embed) - -target_compile_definitions(test_quicktex PRIVATE -DCUSTOM_SYS_PATH="${CMAKE_HOME_DIRECTORY}/env/lib/python3.9/site-packages") +# Set Quicktex version info target_compile_definitions(_quicktex PRIVATE VERSION_INFO=${QUICKTEX_VERSION_INFO}) # enable openMP if available if (OpenMP_CXX_FOUND) target_link_libraries(_quicktex PUBLIC OpenMP::OpenMP_CXX) - target_link_libraries(test_quicktex PUBLIC OpenMP::OpenMP_CXX) endif () # Set module features, like C/C++ standards target_compile_features(_quicktex PUBLIC cxx_std_17 c_std_11) -target_compile_features(test_quicktex PUBLIC cxx_std_17 c_std_11) +# Set compiler warnings set_project_warnings(_quicktex) -set_project_warnings(test_quicktex) - -set(CMAKE_VERBOSE_MAKEFILE ON) +# Clang-specific if (CMAKE_CXX_COMPILER_ID MATCHES ".*Clang") set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -stdlib=libc++ -lc++abi") - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -stdlib=libc++") + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -stdlib=libc++ -fno-omit-frame-pointer -mno-omit-leaf-frame-pointer") set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -stdlib=libc++ -fsanitize=undefined") set(PROJECT_WARNINGS ${CLANG_WARNINGS}) endif () diff --git a/setup.py b/setup.py index b5d9f98..eafe2ad 100644 --- a/setup.py +++ b/setup.py @@ -31,7 +31,9 @@ class CMakeBuild(build_ext): if not extdir.endswith(os.path.sep): extdir += os.path.sep - cfg = "Debug" if self.debug else "Release" + cfg = "Debug" if self.debug else "RelWithDebInfo" + if 'QUICKTEX_DEBUG' in os.environ: + cfg = "Debug" # CMake lets you override the generator - we need to check this. # Can be set with Conda-Build, for example. diff --git a/tests/run_tests.cpp b/tests/run_tests.cpp deleted file mode 100644 index c78d5ad..0000000 --- a/tests/run_tests.cpp +++ /dev/null @@ -1,44 +0,0 @@ -/* Quicktex Texture Compression Library - Copyright (C) 2021 Andrew Cassidy - Partially derived from rgbcx.h written by Richard Geldreich - and licenced under the public domain - - This program is free software: you can redistribute it and/or modify - it under the terms of the GNU Lesser General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public License - along with this program. If not, see . - */ - -// This file allows for easy debugging in CLion or other IDEs that dont natively support cross-debugging between Python and C++ - -#include - -#include -#include - -namespace py = pybind11; -using namespace pybind11::literals; - -#define STRINGIFY(x) #x -#define MACRO_STRINGIFY(x) STRINGIFY(x) - -int main() { - py::scoped_interpreter guard{}; - - py::module_ site = py::module_::import("site"); - - site.attr("addsitedir")(CUSTOM_SYS_PATH); - - py::module_ nose = py::module_::import("nose"); - py::module_ tests = py::module_::import("tests"); - py::list argv(1); - nose.attr("runmodule")("name"_a = "tests.test_bc1", "exit"_a = false); -} \ No newline at end of file From ddbeff43cb68402d6b2330740758100a71d14ece Mon Sep 17 00:00:00 2001 From: Andrew Cassidy Date: Wed, 11 May 2022 20:51:35 -0700 Subject: [PATCH 04/13] Update copyright year --- quicktex/Color.cpp | 2 +- quicktex/Color.h | 2 +- quicktex/ColorBlock.h | 2 +- quicktex/Decoder.h | 2 +- quicktex/Encoder.h | 2 +- quicktex/Matrix4x4.cpp | 2 +- quicktex/Matrix4x4.h | 2 +- quicktex/Texture.h | 2 +- quicktex/Vector4.h | 2 +- quicktex/Vector4Int.h | 2 +- quicktex/_bindings.cpp | 2 +- quicktex/_bindings.h | 2 +- quicktex/bitwiseEnums.h | 2 +- quicktex/s3tc/_bindings.cpp | 2 +- quicktex/s3tc/bc1/BC1Block.cpp | 2 +- quicktex/s3tc/bc1/BC1Block.h | 2 +- quicktex/s3tc/bc1/BC1Decoder.cpp | 2 +- quicktex/s3tc/bc1/BC1Decoder.h | 2 +- quicktex/s3tc/bc1/BC1Encoder.cpp | 2 +- quicktex/s3tc/bc1/BC1Encoder.h | 2 +- quicktex/s3tc/bc1/Histogram.h | 2 +- quicktex/s3tc/bc1/OrderTable.cpp | 2 +- quicktex/s3tc/bc1/OrderTable.h | 2 +- quicktex/s3tc/bc1/OrderTable4.cpp | 2 +- quicktex/s3tc/bc1/SingleColorTable.h | 2 +- quicktex/s3tc/bc1/_bindings.cpp | 2 +- quicktex/s3tc/bc3/BC3Block.h | 2 +- quicktex/s3tc/bc3/BC3Decoder.cpp | 2 +- quicktex/s3tc/bc3/BC3Decoder.h | 2 +- quicktex/s3tc/bc3/BC3Encoder.cpp | 2 +- quicktex/s3tc/bc3/BC3Encoder.h | 2 +- quicktex/s3tc/bc3/_bindings.cpp | 2 +- quicktex/s3tc/bc4/BC4Block.cpp | 2 +- quicktex/s3tc/bc4/BC4Block.h | 2 +- quicktex/s3tc/bc4/BC4Decoder.cpp | 2 +- quicktex/s3tc/bc4/BC4Decoder.h | 2 +- quicktex/s3tc/bc4/BC4Encoder.cpp | 2 +- quicktex/s3tc/bc4/BC4Encoder.h | 2 +- quicktex/s3tc/bc4/_bindings.cpp | 2 +- quicktex/s3tc/bc5/BC5Block.h | 2 +- quicktex/s3tc/bc5/BC5Decoder.cpp | 2 +- quicktex/s3tc/bc5/BC5Decoder.h | 2 +- quicktex/s3tc/bc5/BC5Encoder.cpp | 2 +- quicktex/s3tc/bc5/BC5Encoder.h | 2 +- quicktex/s3tc/bc5/_bindings.cpp | 2 +- quicktex/s3tc/interpolator/Interpolator.cpp | 2 +- quicktex/s3tc/interpolator/Interpolator.h | 2 +- quicktex/s3tc/interpolator/_bindings.cpp | 2 +- quicktex/util.h | 2 +- 49 files changed, 49 insertions(+), 49 deletions(-) diff --git a/quicktex/Color.cpp b/quicktex/Color.cpp index 5ebe072..a80802a 100644 --- a/quicktex/Color.cpp +++ b/quicktex/Color.cpp @@ -1,5 +1,5 @@ /* Quicktex Texture Compression Library - Copyright (C) 2021 Andrew Cassidy + Copyright (C) 2021-2022 Andrew Cassidy Partially derived from rgbcx.h written by Richard Geldreich and licenced under the public domain diff --git a/quicktex/Color.h b/quicktex/Color.h index 53bc3ef..618c60c 100644 --- a/quicktex/Color.h +++ b/quicktex/Color.h @@ -1,5 +1,5 @@ /* Quicktex Texture Compression Library - Copyright (C) 2021 Andrew Cassidy + Copyright (C) 2021-2022 Andrew Cassidy Partially derived from rgbcx.h written by Richard Geldreich and licenced under the public domain diff --git a/quicktex/ColorBlock.h b/quicktex/ColorBlock.h index 28dcc87..32e0fff 100644 --- a/quicktex/ColorBlock.h +++ b/quicktex/ColorBlock.h @@ -1,5 +1,5 @@ /* Quicktex Texture Compression Library - Copyright (C) 2021 Andrew Cassidy + Copyright (C) 2021-2022 Andrew Cassidy Partially derived from rgbcx.h written by Richard Geldreich and licenced under the public domain diff --git a/quicktex/Decoder.h b/quicktex/Decoder.h index fee4726..94892d9 100644 --- a/quicktex/Decoder.h +++ b/quicktex/Decoder.h @@ -1,5 +1,5 @@ /* Quicktex Texture Compression Library - Copyright (C) 2021 Andrew Cassidy + Copyright (C) 2021-2022 Andrew Cassidy Partially derived from rgbcx.h written by Richard Geldreich 2020 and licenced under the public domain diff --git a/quicktex/Encoder.h b/quicktex/Encoder.h index 47fdb2a..abe44b4 100644 --- a/quicktex/Encoder.h +++ b/quicktex/Encoder.h @@ -1,5 +1,5 @@ /* Quicktex Texture Compression Library - Copyright (C) 2021 Andrew Cassidy + Copyright (C) 2021-2022 Andrew Cassidy Partially derived from rgbcx.h written by Richard Geldreich 2020 and licenced under the public domain diff --git a/quicktex/Matrix4x4.cpp b/quicktex/Matrix4x4.cpp index d25a53c..16e28a1 100644 --- a/quicktex/Matrix4x4.cpp +++ b/quicktex/Matrix4x4.cpp @@ -1,5 +1,5 @@ /* Quicktex Texture Compression Library - Copyright (C) 2021 Andrew Cassidy + Copyright (C) 2021-2022 Andrew Cassidy Partially derived from rgbcx.h written by Richard Geldreich and licenced under the public domain diff --git a/quicktex/Matrix4x4.h b/quicktex/Matrix4x4.h index 9feec5a..86b9be7 100644 --- a/quicktex/Matrix4x4.h +++ b/quicktex/Matrix4x4.h @@ -1,5 +1,5 @@ /* Quicktex Texture Compression Library - Copyright (C) 2021 Andrew Cassidy + Copyright (C) 2021-2022 Andrew Cassidy Partially derived from rgbcx.h written by Richard Geldreich and licenced under the public domain diff --git a/quicktex/Texture.h b/quicktex/Texture.h index 8975e28..27cb856 100644 --- a/quicktex/Texture.h +++ b/quicktex/Texture.h @@ -1,5 +1,5 @@ /* Quicktex Texture Compression Library - Copyright (C) 2021 Andrew Cassidy + Copyright (C) 2021-2022 Andrew Cassidy Partially derived from rgbcx.h written by Richard Geldreich and licenced under the public domain diff --git a/quicktex/Vector4.h b/quicktex/Vector4.h index f2ad50d..e060490 100644 --- a/quicktex/Vector4.h +++ b/quicktex/Vector4.h @@ -1,5 +1,5 @@ /* Quicktex Texture Compression Library - Copyright (C) 2021 Andrew Cassidy + Copyright (C) 2021-2022 Andrew Cassidy Partially derived from rgbcx.h written by Richard Geldreich and licenced under the public domain diff --git a/quicktex/Vector4Int.h b/quicktex/Vector4Int.h index 9829a93..915337a 100644 --- a/quicktex/Vector4Int.h +++ b/quicktex/Vector4Int.h @@ -1,5 +1,5 @@ /* Quicktex Texture Compression Library - Copyright (C) 2021 Andrew Cassidy + Copyright (C) 2021-2022 Andrew Cassidy Partially derived from rgbcx.h written by Richard Geldreich and licenced under the public domain diff --git a/quicktex/_bindings.cpp b/quicktex/_bindings.cpp index 988df5b..9988fe0 100644 --- a/quicktex/_bindings.cpp +++ b/quicktex/_bindings.cpp @@ -1,5 +1,5 @@ /* Quicktex Texture Compression Library - Copyright (C) 2021 Andrew Cassidy + Copyright (C) 2021-2022 Andrew Cassidy Partially derived from rgbcx.h written by Richard Geldreich and licenced under the public domain diff --git a/quicktex/_bindings.h b/quicktex/_bindings.h index 11ca831..80db078 100644 --- a/quicktex/_bindings.h +++ b/quicktex/_bindings.h @@ -1,5 +1,5 @@ /* Quicktex Texture Compression Library - Copyright (C) 2021 Andrew Cassidy + Copyright (C) 2021-2022 Andrew Cassidy Partially derived from rgbcx.h written by Richard Geldreich and licenced under the public domain diff --git a/quicktex/bitwiseEnums.h b/quicktex/bitwiseEnums.h index 57b0dc5..b5174f0 100644 --- a/quicktex/bitwiseEnums.h +++ b/quicktex/bitwiseEnums.h @@ -1,5 +1,5 @@ /* Quicktex Texture Compression Library - Copyright (C) 2021 Andrew Cassidy + Copyright (C) 2021-2022 Andrew Cassidy Partially derived from rgbcx.h written by Richard Geldreich 2020 and licenced under the public domain diff --git a/quicktex/s3tc/_bindings.cpp b/quicktex/s3tc/_bindings.cpp index 7a593d9..22dd70f 100644 --- a/quicktex/s3tc/_bindings.cpp +++ b/quicktex/s3tc/_bindings.cpp @@ -1,5 +1,5 @@ /* Quicktex Texture Compression Library - Copyright (C) 2021 Andrew Cassidy + Copyright (C) 2021-2022 Andrew Cassidy Partially derived from rgbcx.h written by Richard Geldreich and licenced under the public domain diff --git a/quicktex/s3tc/bc1/BC1Block.cpp b/quicktex/s3tc/bc1/BC1Block.cpp index 53f3d86..4a73644 100644 --- a/quicktex/s3tc/bc1/BC1Block.cpp +++ b/quicktex/s3tc/bc1/BC1Block.cpp @@ -1,5 +1,5 @@ /* Quicktex Texture Compression Library - Copyright (C) 2021 Andrew Cassidy + Copyright (C) 2021-2022 Andrew Cassidy Partially derived from rgbcx.h written by Richard Geldreich and licenced under the public domain diff --git a/quicktex/s3tc/bc1/BC1Block.h b/quicktex/s3tc/bc1/BC1Block.h index 9aa6dbf..3e8beee 100644 --- a/quicktex/s3tc/bc1/BC1Block.h +++ b/quicktex/s3tc/bc1/BC1Block.h @@ -1,5 +1,5 @@ /* Quicktex Texture Compression Library - Copyright (C) 2021 Andrew Cassidy + Copyright (C) 2021-2022 Andrew Cassidy Partially derived from rgbcx.h written by Richard Geldreich and licenced under the public domain diff --git a/quicktex/s3tc/bc1/BC1Decoder.cpp b/quicktex/s3tc/bc1/BC1Decoder.cpp index 57fd379..e1c840a 100644 --- a/quicktex/s3tc/bc1/BC1Decoder.cpp +++ b/quicktex/s3tc/bc1/BC1Decoder.cpp @@ -1,5 +1,5 @@ /* Quicktex Texture Compression Library - Copyright (C) 2021 Andrew Cassidy + Copyright (C) 2021-2022 Andrew Cassidy Partially derived from rgbcx.h written by Richard Geldreich and licenced under the public domain diff --git a/quicktex/s3tc/bc1/BC1Decoder.h b/quicktex/s3tc/bc1/BC1Decoder.h index f1a82b2..a215923 100644 --- a/quicktex/s3tc/bc1/BC1Decoder.h +++ b/quicktex/s3tc/bc1/BC1Decoder.h @@ -1,5 +1,5 @@ /* Quicktex Texture Compression Library - Copyright (C) 2021 Andrew Cassidy + Copyright (C) 2021-2022 Andrew Cassidy Partially derived from rgbcx.h written by Richard Geldreich and licenced under the public domain diff --git a/quicktex/s3tc/bc1/BC1Encoder.cpp b/quicktex/s3tc/bc1/BC1Encoder.cpp index 5951c2c..396f6e4 100644 --- a/quicktex/s3tc/bc1/BC1Encoder.cpp +++ b/quicktex/s3tc/bc1/BC1Encoder.cpp @@ -1,5 +1,5 @@ /* Quicktex Texture Compression Library - Copyright (C) 2021 Andrew Cassidy + Copyright (C) 2021-2022 Andrew Cassidy Partially derived from rgbcx.h written by Richard Geldreich and licenced under the public domain diff --git a/quicktex/s3tc/bc1/BC1Encoder.h b/quicktex/s3tc/bc1/BC1Encoder.h index bcf3fc2..e42f6ef 100644 --- a/quicktex/s3tc/bc1/BC1Encoder.h +++ b/quicktex/s3tc/bc1/BC1Encoder.h @@ -1,5 +1,5 @@ /* Quicktex Texture Compression Library - Copyright (C) 2021 Andrew Cassidy + Copyright (C) 2021-2022 Andrew Cassidy Partially derived from rgbcx.h written by Richard Geldreich and licenced under the public domain diff --git a/quicktex/s3tc/bc1/Histogram.h b/quicktex/s3tc/bc1/Histogram.h index e30dc50..1a70cd2 100644 --- a/quicktex/s3tc/bc1/Histogram.h +++ b/quicktex/s3tc/bc1/Histogram.h @@ -1,5 +1,5 @@ /* Quicktex Texture Compression Library - Copyright (C) 2021 Andrew Cassidy + Copyright (C) 2021-2022 Andrew Cassidy Partially derived from rgbcx.h written by Richard Geldreich and licenced under the public domain diff --git a/quicktex/s3tc/bc1/OrderTable.cpp b/quicktex/s3tc/bc1/OrderTable.cpp index 843ddd8..7f69200 100644 --- a/quicktex/s3tc/bc1/OrderTable.cpp +++ b/quicktex/s3tc/bc1/OrderTable.cpp @@ -1,5 +1,5 @@ /* Quicktex Texture Compression Library - Copyright (C) 2021 Andrew Cassidy + Copyright (C) 2021-2022 Andrew Cassidy Partially derived from rgbcx.h written by Richard Geldreich and licenced under the public domain diff --git a/quicktex/s3tc/bc1/OrderTable.h b/quicktex/s3tc/bc1/OrderTable.h index 9d29d1f..6d4b564 100644 --- a/quicktex/s3tc/bc1/OrderTable.h +++ b/quicktex/s3tc/bc1/OrderTable.h @@ -1,5 +1,5 @@ /* Quicktex Texture Compression Library - Copyright (C) 2021 Andrew Cassidy + Copyright (C) 2021-2022 Andrew Cassidy Partially derived from rgbcx.h written by Richard Geldreich and licenced under the public domain diff --git a/quicktex/s3tc/bc1/OrderTable4.cpp b/quicktex/s3tc/bc1/OrderTable4.cpp index df9dabe..19dcede 100644 --- a/quicktex/s3tc/bc1/OrderTable4.cpp +++ b/quicktex/s3tc/bc1/OrderTable4.cpp @@ -1,5 +1,5 @@ /* Quicktex Texture Compression Library - Copyright (C) 2021 Andrew Cassidy + Copyright (C) 2021-2022 Andrew Cassidy Partially derived from rgbcx.h written by Richard Geldreich and licenced under the public domain diff --git a/quicktex/s3tc/bc1/SingleColorTable.h b/quicktex/s3tc/bc1/SingleColorTable.h index 627695d..bf8a341 100644 --- a/quicktex/s3tc/bc1/SingleColorTable.h +++ b/quicktex/s3tc/bc1/SingleColorTable.h @@ -1,5 +1,5 @@ /* Quicktex Texture Compression Library - Copyright (C) 2021 Andrew Cassidy + Copyright (C) 2021-2022 Andrew Cassidy Partially derived from rgbcx.h written by Richard Geldreich and licenced under the public domain diff --git a/quicktex/s3tc/bc1/_bindings.cpp b/quicktex/s3tc/bc1/_bindings.cpp index 9880059..9f85486 100644 --- a/quicktex/s3tc/bc1/_bindings.cpp +++ b/quicktex/s3tc/bc1/_bindings.cpp @@ -1,5 +1,5 @@ /* Quicktex Texture Compression Library - Copyright (C) 2021 Andrew Cassidy + Copyright (C) 2021-2022 Andrew Cassidy Partially derived from rgbcx.h written by Richard Geldreich and licenced under the public domain diff --git a/quicktex/s3tc/bc3/BC3Block.h b/quicktex/s3tc/bc3/BC3Block.h index c91ac0b..6c921ab 100644 --- a/quicktex/s3tc/bc3/BC3Block.h +++ b/quicktex/s3tc/bc3/BC3Block.h @@ -1,5 +1,5 @@ /* Quicktex Texture Compression Library - Copyright (C) 2021 Andrew Cassidy + Copyright (C) 2021-2022 Andrew Cassidy Partially derived from rgbcx.h written by Richard Geldreich and licenced under the public domain diff --git a/quicktex/s3tc/bc3/BC3Decoder.cpp b/quicktex/s3tc/bc3/BC3Decoder.cpp index c13327f..528975b 100644 --- a/quicktex/s3tc/bc3/BC3Decoder.cpp +++ b/quicktex/s3tc/bc3/BC3Decoder.cpp @@ -1,5 +1,5 @@ /* Quicktex Texture Compression Library - Copyright (C) 2021 Andrew Cassidy + Copyright (C) 2021-2022 Andrew Cassidy Partially derived from rgbcx.h written by Richard Geldreich and licenced under the public domain diff --git a/quicktex/s3tc/bc3/BC3Decoder.h b/quicktex/s3tc/bc3/BC3Decoder.h index eb4df24..32bd957 100644 --- a/quicktex/s3tc/bc3/BC3Decoder.h +++ b/quicktex/s3tc/bc3/BC3Decoder.h @@ -1,5 +1,5 @@ /* Quicktex Texture Compression Library - Copyright (C) 2021 Andrew Cassidy + Copyright (C) 2021-2022 Andrew Cassidy Partially derived from rgbcx.h written by Richard Geldreich and licenced under the public domain diff --git a/quicktex/s3tc/bc3/BC3Encoder.cpp b/quicktex/s3tc/bc3/BC3Encoder.cpp index e218f13..4694e08 100644 --- a/quicktex/s3tc/bc3/BC3Encoder.cpp +++ b/quicktex/s3tc/bc3/BC3Encoder.cpp @@ -1,5 +1,5 @@ /* Quicktex Texture Compression Library - Copyright (C) 2021 Andrew Cassidy + Copyright (C) 2021-2022 Andrew Cassidy Partially derived from rgbcx.h written by Richard Geldreich and licenced under the public domain diff --git a/quicktex/s3tc/bc3/BC3Encoder.h b/quicktex/s3tc/bc3/BC3Encoder.h index fa90d06..5ea98a8 100644 --- a/quicktex/s3tc/bc3/BC3Encoder.h +++ b/quicktex/s3tc/bc3/BC3Encoder.h @@ -1,5 +1,5 @@ /* Quicktex Texture Compression Library - Copyright (C) 2021 Andrew Cassidy + Copyright (C) 2021-2022 Andrew Cassidy Partially derived from rgbcx.h written by Richard Geldreich and licenced under the public domain diff --git a/quicktex/s3tc/bc3/_bindings.cpp b/quicktex/s3tc/bc3/_bindings.cpp index 43cf2ff..c1715fa 100644 --- a/quicktex/s3tc/bc3/_bindings.cpp +++ b/quicktex/s3tc/bc3/_bindings.cpp @@ -1,5 +1,5 @@ /* Quicktex Texture Compression Library - Copyright (C) 2021 Andrew Cassidy + Copyright (C) 2021-2022 Andrew Cassidy Partially derived from rgbcx.h written by Richard Geldreich and licenced under the public domain diff --git a/quicktex/s3tc/bc4/BC4Block.cpp b/quicktex/s3tc/bc4/BC4Block.cpp index 75ed739..478c90d 100644 --- a/quicktex/s3tc/bc4/BC4Block.cpp +++ b/quicktex/s3tc/bc4/BC4Block.cpp @@ -1,5 +1,5 @@ /* Quicktex Texture Compression Library - Copyright (C) 2021 Andrew Cassidy + Copyright (C) 2021-2022 Andrew Cassidy Partially derived from rgbcx.h written by Richard Geldreich and licenced under the public domain diff --git a/quicktex/s3tc/bc4/BC4Block.h b/quicktex/s3tc/bc4/BC4Block.h index f51fb12..88d268e 100644 --- a/quicktex/s3tc/bc4/BC4Block.h +++ b/quicktex/s3tc/bc4/BC4Block.h @@ -1,5 +1,5 @@ /* Quicktex Texture Compression Library - Copyright (C) 2021 Andrew Cassidy + Copyright (C) 2021-2022 Andrew Cassidy Partially derived from rgbcx.h written by Richard Geldreich and licenced under the public domain diff --git a/quicktex/s3tc/bc4/BC4Decoder.cpp b/quicktex/s3tc/bc4/BC4Decoder.cpp index de6bf0b..fe6bb4e 100644 --- a/quicktex/s3tc/bc4/BC4Decoder.cpp +++ b/quicktex/s3tc/bc4/BC4Decoder.cpp @@ -1,5 +1,5 @@ /* Quicktex Texture Compression Library - Copyright (C) 2021 Andrew Cassidy + Copyright (C) 2021-2022 Andrew Cassidy Partially derived from rgbcx.h written by Richard Geldreich and licenced under the public domain diff --git a/quicktex/s3tc/bc4/BC4Decoder.h b/quicktex/s3tc/bc4/BC4Decoder.h index 7b88c3c..69027fb 100644 --- a/quicktex/s3tc/bc4/BC4Decoder.h +++ b/quicktex/s3tc/bc4/BC4Decoder.h @@ -1,5 +1,5 @@ /* Quicktex Texture Compression Library - Copyright (C) 2021 Andrew Cassidy + Copyright (C) 2021-2022 Andrew Cassidy Partially derived from rgbcx.h written by Richard Geldreich and licenced under the public domain diff --git a/quicktex/s3tc/bc4/BC4Encoder.cpp b/quicktex/s3tc/bc4/BC4Encoder.cpp index a443315..1e968b9 100644 --- a/quicktex/s3tc/bc4/BC4Encoder.cpp +++ b/quicktex/s3tc/bc4/BC4Encoder.cpp @@ -1,5 +1,5 @@ /* Quicktex Texture Compression Library - Copyright (C) 2021 Andrew Cassidy + Copyright (C) 2021-2022 Andrew Cassidy Partially derived from rgbcx.h written by Richard Geldreich and licenced under the public domain diff --git a/quicktex/s3tc/bc4/BC4Encoder.h b/quicktex/s3tc/bc4/BC4Encoder.h index f8579f1..6d41466 100644 --- a/quicktex/s3tc/bc4/BC4Encoder.h +++ b/quicktex/s3tc/bc4/BC4Encoder.h @@ -1,5 +1,5 @@ /* Quicktex Texture Compression Library - Copyright (C) 2021 Andrew Cassidy + Copyright (C) 2021-2022 Andrew Cassidy Partially derived from rgbcx.h written by Richard Geldreich and licenced under the public domain diff --git a/quicktex/s3tc/bc4/_bindings.cpp b/quicktex/s3tc/bc4/_bindings.cpp index 4b5e3eb..466029d 100644 --- a/quicktex/s3tc/bc4/_bindings.cpp +++ b/quicktex/s3tc/bc4/_bindings.cpp @@ -1,5 +1,5 @@ /* Quicktex Texture Compression Library - Copyright (C) 2021 Andrew Cassidy + Copyright (C) 2021-2022 Andrew Cassidy Partially derived from rgbcx.h written by Richard Geldreich and licenced under the public domain diff --git a/quicktex/s3tc/bc5/BC5Block.h b/quicktex/s3tc/bc5/BC5Block.h index ba5807a..f6a6e0b 100644 --- a/quicktex/s3tc/bc5/BC5Block.h +++ b/quicktex/s3tc/bc5/BC5Block.h @@ -1,5 +1,5 @@ /* Quicktex Texture Compression Library - Copyright (C) 2021 Andrew Cassidy + Copyright (C) 2021-2022 Andrew Cassidy Partially derived from rgbcx.h written by Richard Geldreich and licenced under the public domain diff --git a/quicktex/s3tc/bc5/BC5Decoder.cpp b/quicktex/s3tc/bc5/BC5Decoder.cpp index 3b86390..2086fc9 100644 --- a/quicktex/s3tc/bc5/BC5Decoder.cpp +++ b/quicktex/s3tc/bc5/BC5Decoder.cpp @@ -1,5 +1,5 @@ /* Quicktex Texture Compression Library - Copyright (C) 2021 Andrew Cassidy + Copyright (C) 2021-2022 Andrew Cassidy Partially derived from rgbcx.h written by Richard Geldreich and licenced under the public domain diff --git a/quicktex/s3tc/bc5/BC5Decoder.h b/quicktex/s3tc/bc5/BC5Decoder.h index 5ffded6..55ffd92 100644 --- a/quicktex/s3tc/bc5/BC5Decoder.h +++ b/quicktex/s3tc/bc5/BC5Decoder.h @@ -1,5 +1,5 @@ /* Quicktex Texture Compression Library - Copyright (C) 2021 Andrew Cassidy + Copyright (C) 2021-2022 Andrew Cassidy Partially derived from rgbcx.h written by Richard Geldreich and licenced under the public domain diff --git a/quicktex/s3tc/bc5/BC5Encoder.cpp b/quicktex/s3tc/bc5/BC5Encoder.cpp index 2852c56..5cdd5dd 100644 --- a/quicktex/s3tc/bc5/BC5Encoder.cpp +++ b/quicktex/s3tc/bc5/BC5Encoder.cpp @@ -1,5 +1,5 @@ /* Quicktex Texture Compression Library - Copyright (C) 2021 Andrew Cassidy + Copyright (C) 2021-2022 Andrew Cassidy Partially derived from rgbcx.h written by Richard Geldreich and licenced under the public domain diff --git a/quicktex/s3tc/bc5/BC5Encoder.h b/quicktex/s3tc/bc5/BC5Encoder.h index 71b07d1..e7896e2 100644 --- a/quicktex/s3tc/bc5/BC5Encoder.h +++ b/quicktex/s3tc/bc5/BC5Encoder.h @@ -1,5 +1,5 @@ /* Quicktex Texture Compression Library - Copyright (C) 2021 Andrew Cassidy + Copyright (C) 2021-2022 Andrew Cassidy Partially derived from rgbcx.h written by Richard Geldreich and licenced under the public domain diff --git a/quicktex/s3tc/bc5/_bindings.cpp b/quicktex/s3tc/bc5/_bindings.cpp index edcaaab..35a96c9 100644 --- a/quicktex/s3tc/bc5/_bindings.cpp +++ b/quicktex/s3tc/bc5/_bindings.cpp @@ -1,5 +1,5 @@ /* Quicktex Texture Compression Library - Copyright (C) 2021 Andrew Cassidy + Copyright (C) 2021-2022 Andrew Cassidy Partially derived from rgbcx.h written by Richard Geldreich and licenced under the public domain diff --git a/quicktex/s3tc/interpolator/Interpolator.cpp b/quicktex/s3tc/interpolator/Interpolator.cpp index f1d97eb..f126b3c 100644 --- a/quicktex/s3tc/interpolator/Interpolator.cpp +++ b/quicktex/s3tc/interpolator/Interpolator.cpp @@ -1,5 +1,5 @@ /* Quicktex Texture Compression Library - Copyright (C) 2021 Andrew Cassidy + Copyright (C) 2021-2022 Andrew Cassidy Partially derived from rgbcx.h written by Richard Geldreich and licenced under the public domain diff --git a/quicktex/s3tc/interpolator/Interpolator.h b/quicktex/s3tc/interpolator/Interpolator.h index 60242b3..7324dae 100644 --- a/quicktex/s3tc/interpolator/Interpolator.h +++ b/quicktex/s3tc/interpolator/Interpolator.h @@ -1,5 +1,5 @@ /* Quicktex Texture Compression Library - Copyright (C) 2021 Andrew Cassidy + Copyright (C) 2021-2022 Andrew Cassidy Partially derived from rgbcx.h written by Richard Geldreich and licenced under the public domain diff --git a/quicktex/s3tc/interpolator/_bindings.cpp b/quicktex/s3tc/interpolator/_bindings.cpp index a983d81..92ad277 100644 --- a/quicktex/s3tc/interpolator/_bindings.cpp +++ b/quicktex/s3tc/interpolator/_bindings.cpp @@ -1,5 +1,5 @@ /* Quicktex Texture Compression Library - Copyright (C) 2021 Andrew Cassidy + Copyright (C) 2021-2022 Andrew Cassidy Partially derived from rgbcx.h written by Richard Geldreich and licenced under the public domain This program is free software: you can redistribute it and/or modify diff --git a/quicktex/util.h b/quicktex/util.h index 5e94fe1..421b978 100644 --- a/quicktex/util.h +++ b/quicktex/util.h @@ -1,5 +1,5 @@ /* Quicktex Texture Compression Library - Copyright (C) 2021 Andrew Cassidy + Copyright (C) 2021-2022 Andrew Cassidy Partially derived from rgbcx.h written by Richard Geldreich and licenced under the public domain From 5c87c8270225618cfc0b434df86a83bdb160efe2 Mon Sep 17 00:00:00 2001 From: Andrew Cassidy Date: Wed, 11 May 2022 23:22:51 -0700 Subject: [PATCH 05/13] Add file documenting development environment setup --- DEVELOPMENT.md | 25 +++++++++++++++++++++++++ docs/development.md | 2 ++ docs/index.md | 1 + 3 files changed, 28 insertions(+) create mode 100644 DEVELOPMENT.md create mode 100644 docs/development.md diff --git a/DEVELOPMENT.md b/DEVELOPMENT.md new file mode 100644 index 0000000..341bbfa --- /dev/null +++ b/DEVELOPMENT.md @@ -0,0 +1,25 @@ +# Development + +This document outlines how to set up a development environment for Quicktex. Documentation on writing Python extension modules is sparse, so I hope this document is useful for other projects as well. The [Coding Patterns for Python Extensions](https://pythonextensionpatterns.readthedocs.io/en/latest/) site has some useful information and will be linked to often in this document. + +## Setting up Debug Python + +Many development tools require debug symbols to function, and since the front-end for accessing an extension module is Python, that usually means adding debug symbols to Python. [This Page](https://pythonextensionpatterns.readthedocs.io/en/latest/debugging/debug_python.html) has some instructions on building python with debug symbols. + +If you plan to use DTrace, enable the `--with-dtrace` flag when running `configure`. + +It's useful for this debug python to have SSL enabled so that packages can be installed using pip. Enable SSL with the `--with-openssl` flag when running `configure`. If you are on macOS and installed OpenSSL through Homebrew, you may need to use `--with-openssl=$(brew --prefix openssl)` to help the compiler find it. + +### Installing Debug Python + +You can keep the resulting binary in your local copy of the cpython repo and symlink to it, but I like to install it somewhere like `/opt/python-debug/`. The install location is set in the `configure` tool using the `--prefix` flag, and installation is done by running `make install` + +### Mixing Debug and Release Python + +The debug build of python is slow (It may be possible to build with debug symbols but full optimization, I have not looked into it). If you already have a venv setup for your project, you can just symlink the debug python binary into `env/bin` with a full name like `python3.9d`. Make sure that the debug build has the same minor version (e.g '3.9') as the version you made the virtual environment with to maintain ABI compatibility. + +## Profiling with Dtrace + +DTrace is the default program profiler on macOS and other Unix systems, but it's also available for use on Windows and Linux. Using DTrace requires building Python with DTrace hooks as seen above. + +Your extension module does not need a full debug build to profile, but it does need frame pointers to see the stack trace at each sample, as well as debug symbols to give functions names. The cmake build type `RelWithDebInfo` handles this automatically. \ No newline at end of file diff --git a/docs/development.md b/docs/development.md new file mode 100644 index 0000000..ab1aac3 --- /dev/null +++ b/docs/development.md @@ -0,0 +1,2 @@ +```{include} ../DEVELOPMENT.md +``` \ No newline at end of file diff --git a/docs/index.md b/docs/index.md index 3f0573a..9d15f90 100644 --- a/docs/index.md +++ b/docs/index.md @@ -23,6 +23,7 @@ reference/index maxdepth: 1 --- +development Changelog License ``` From daae86cf50e6c2a12cd4ddd3e38048009b676263 Mon Sep 17 00:00:00 2001 From: Andrew Cassidy Date: Sun, 22 May 2022 16:50:24 -0700 Subject: [PATCH 06/13] Switch to pytest --- pyproject.toml | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index c77446d..d93844f 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -36,7 +36,7 @@ dependencies = ["Pillow", "click"] dynamic = ["version"] [project.optional-dependencies] -tests = ["parameterized"] +tests = ["parameterized", "pytest"] docs = [ "Sphinx >= 3.5", "sphinx-click >= 2.7", @@ -64,7 +64,7 @@ package-dir = { '' = '.' } # without this line, C++ source files get included in [tool.cibuildwheel] build = "cp*" # only build wheels for cpython. build-frontend = "build" -test-command = "cd {project} && python -m unittest --verbose" +test-command = "pytest {project}/tests --verbose" test-extras = ["tests"] [tool.cibuildwheel.macos] @@ -73,7 +73,6 @@ skip = ["cp{38,39,31*}-macosx_x86_64"] # skip x86-only builds where fat binaries [tool.cibuildwheel.windows] archs = ["auto64"] # arm64 windows builds not yet supported -test-command = "cd /d {project} && python -m unittest --verbose" # windows why is this flag required [tool.cibuildwheel.linux] skip = ["cp37-musllinux*", "*musllinux_aarch64*"] # skip targets without available Pillow wheels From 920059bea13a8176d2b549655d209677dceae503 Mon Sep 17 00:00:00 2001 From: Andrew Cassidy Date: Sun, 22 May 2022 18:40:13 -0700 Subject: [PATCH 07/13] Migrate tests to pytest --- tests/test_bc1.py | 262 +++++++++++++++++++++--------------------- tests/test_bc4.py | 227 ++++++++++++++++++------------------ tests/test_install.py | 6 +- tests/test_texture.py | 66 +++++------ 4 files changed, 279 insertions(+), 282 deletions(-) diff --git a/tests/test_bc1.py b/tests/test_bc1.py index 1108c3a..4f9040f 100644 --- a/tests/test_bc1.py +++ b/tests/test_bc1.py @@ -1,208 +1,206 @@ -import unittest -from parameterized import parameterized, parameterized_class +import math + +import pytest +from PIL import Image, ImageChops + from quicktex.s3tc.bc1 import BC1Block, BC1Texture, BC1Encoder, BC1Decoder from .images import BC1Blocks -from PIL import Image, ImageChops -in_endpoints = ((253, 254, 255), (65, 70, 67)) # has some small changes that should encode the same +in_endpoints = ((253, 254, 255), (65, 70, 67)) # has some small changes that should encode the same in 5:6:5 out_endpoints = ((255, 255, 255, 255), (66, 69, 66, 255)) selectors = [[0, 2, 3, 1]] * 4 block_bytes = b'\xff\xff\x28\x42\x78\x78\x78\x78' -class TestBC1Block(unittest.TestCase): +class TestBC1Block: """Tests for the BC1Block class""" def test_size(self): """Test the size and dimensions of BC1Block""" - self.assertEqual(BC1Block.nbytes, 8, 'incorrect block size') - self.assertEqual(BC1Block.width, 4, 'incorrect block width') - self.assertEqual(BC1Block.height, 4, 'incorrect block width') - self.assertEqual(BC1Block.size, (4, 4), 'incorrect block dimensions') + assert BC1Block.nbytes == 8 + assert BC1Block.width == 4 + assert BC1Block.height == 4 + assert BC1Block.size == (4, 4) def test_buffer(self): """Test the buffer protocol of BC1Block""" block = BC1Block() mv = memoryview(block) - - self.assertFalse(mv.readonly, 'buffer is readonly') - self.assertTrue(mv.c_contiguous, 'buffer is not contiguous') - self.assertEqual(mv.ndim, 1, 'buffer is multidimensional') - self.assertEqual(mv.nbytes, BC1Block.nbytes, 'buffer is the wrong size') - self.assertEqual(mv.format, 'B', 'buffer has the wrong format') - mv[:] = block_bytes - self.assertEqual(mv.tobytes(), block_bytes, 'incorrect buffer data') + + assert not mv.readonly + assert mv.c_contiguous + assert mv.ndim == 1 + assert mv.nbytes == 8 + assert mv.format == 'B' + assert mv.tobytes() == block_bytes + assert mv.tobytes() == block.tobytes() def test_constructor(self): """Test constructing a block out of endpoints and selectors""" block = BC1Block(*in_endpoints, selectors) - self.assertEqual(block.tobytes(), block_bytes, 'incorrect block bytes') - self.assertEqual(block.selectors, selectors, 'incorrect selectors') - self.assertEqual(block.endpoints, out_endpoints, 'incorrect endpoints') - self.assertFalse(block.is_3color, 'incorrect color mode') + assert block.tobytes() == block_bytes + assert block.selectors == selectors + assert block.endpoints == out_endpoints + assert not block.is_3color def test_frombytes(self): """Test constructing a block out of raw data""" block = BC1Block.frombytes(block_bytes) - self.assertEqual(block.tobytes(), block_bytes, 'incorrect block bytes') - self.assertEqual(block.selectors, selectors, 'incorrect selectors') - self.assertEqual(block.endpoints, out_endpoints, 'incorrect endpoints') - self.assertFalse(block.is_3color, 'incorrect color mode') + assert block.tobytes() == block_bytes + assert block.selectors == selectors + assert block.endpoints == out_endpoints + assert not block.is_3color def test_eq(self): """Test equality between two identical blocks""" block1 = BC1Block.frombytes(block_bytes) block2 = BC1Block.frombytes(block_bytes) - self.assertEqual(block1, block2, 'identical blocks not equal') + assert block1 == block2 -@parameterized_class( - ("name", "w", "h", "wb", "hb"), [("8x8", 8, 8, 2, 2), ("9x9", 9, 9, 3, 3), ("7x7", 7, 7, 2, 2), ("7x9", 7, 9, 2, 3)] -) -class TestBC1Texture(unittest.TestCase): - def setUp(self): - self.tex = BC1Texture(self.w, self.h) - self.nbytes = self.wb * self.hb * BC1Block.nbytes +# noinspection PyMethodMayBeStatic +@pytest.mark.parametrize('w', [7, 8, 9]) +@pytest.mark.parametrize('h', [7, 8, 9]) +class TestBC1Texture: + def test_dimensions(self, w, h): + """Test dimensions of BC1Texture in pixels, blocks, and bytes""" + tex = BC1Texture(w, h) + wb = math.ceil(w / 4) + hb = math.ceil(h / 4) - def test_size(self): - """Test size of BC1Texture in bytes""" - self.assertEqual(self.tex.nbytes, self.nbytes, 'incorrect texture size') - self.assertEqual(len(self.tex.tobytes()), self.nbytes, 'incorrect texture size from tobytes') - - def test_dimensions(self): - """Test dimensions of BC1Texture in pixels""" - self.assertEqual(self.tex.width, self.w, 'incorrect texture width') - self.assertEqual(self.tex.height, self.h, 'incorrect texture height') - self.assertEqual(self.tex.size, (self.w, self.h), 'incorrect texture dimensions') - - def test_dimensions_blocks(self): - """Test dimensions of BC1Texture in blocks""" - self.assertEqual(self.tex.width_blocks, self.wb, 'incorrect texture width_blocks') - self.assertEqual(self.tex.height_blocks, self.hb, 'incorrect texture width_blocks') - self.assertEqual(self.tex.size_blocks, (self.wb, self.hb), 'incorrect texture dimensions_blocks') - - def test_blocks(self): + assert tex.nbytes == BC1Block.nbytes * wb * hb # block width x block height + assert len(tex.tobytes()) == tex.nbytes + + assert tex.width == w + assert tex.height == h + assert tex.size == (w, h) + + assert tex.width_blocks == wb + assert tex.height_blocks == hb + assert tex.size_blocks == (wb, hb) + + def test_blocks(self, w, h): """Test getting and setting blocks to BC1Texture""" - blocks = [[BC1Block.frombytes(bytes([x, y] + [0] * 6)) for x in range(self.wb)] for y in range(self.hb)] - for x in range(self.wb): - for y in range(self.hb): - self.tex[x, y] = blocks[y][x] - - b = self.tex.tobytes() - for x in range(self.wb): - for y in range(self.hb): - index = (x + (y * self.wb)) * BC1Block.nbytes - tb = self.tex[x, y] + tex = BC1Texture(w, h) + + # generate garbage blocks with the x and y index in the first 2 bytes + blocks = [ + [BC1Block.frombytes(bytes([x, y] + [0] * 6)) for x in range(tex.width_blocks)] + for y in range(tex.height_blocks) + ] + # assign those blocks to the texture + for x in range(tex.width_blocks): + for y in range(tex.height_blocks): + tex[x, y] = blocks[y][x] + + # get the blocks and analyze + b = tex.tobytes() + for x in range(tex.width_blocks): + for y in range(tex.height_blocks): + index = (x + (y * tex.width_blocks)) * BC1Block.nbytes + tb = tex[x, y] fb = BC1Block.frombytes(b[index : index + BC1Block.nbytes]) - self.assertEqual(tb, blocks[y][x], 'incorrect block read from texture') - self.assertEqual(fb, blocks[y][x], 'incorrect block read from texture bytes') + assert tb == blocks[y][x] + assert fb == blocks[y][x] - self.assertEqual(self.tex[-1, -1], self.tex[self.wb - 1, self.hb - 1], 'incorrect negative subscripting') + def text_subscript(self, w, h): + """Test BC1Texture subscripting for blocks""" + tex = BC1Texture(w, h) - with self.assertRaises(IndexError): - _ = self.tex[self.wb, self.hb] - with self.assertRaises(IndexError): - _ = self.tex[-1 - self.wb, -1 - self.hb] + # ensure negative wraparound works + assert tex[-1, -1] == tex[tex.width_blocks - 1, tex.height_blocks - 1] - def test_buffer(self): - """Test the buffer protocol of BC1Texture""" - mv = memoryview(self.tex) + with pytest.raises(IndexError): + _ = tex[tex.width_blocks, tex.height_blocks] + with pytest.raises(IndexError): + _ = tex[-1 - tex.width_blocks, -1 - tex.height_blocks] - self.assertFalse(mv.readonly, 'buffer is readonly') - self.assertTrue(mv.c_contiguous, 'buffer is not contiguous') - self.assertEqual(mv.nbytes, self.nbytes, 'buffer is the wrong size') - self.assertEqual(mv.format, 'B', 'buffer has the wrong format') + def test_buffer(self, w, h): + """Test the buffer protocol of BC1Texture""" + tex = BC1Texture(w, h) + mv = memoryview(tex) - data = block_bytes * self.wb * self.hb + data = block_bytes * tex.width_blocks * tex.height_blocks mv[:] = data - self.assertEqual(mv.tobytes(), data, 'incorrect buffer data') + assert not mv.readonly + assert mv.c_contiguous + assert mv.nbytes == tex.nbytes + assert mv.format == 'B' + assert mv.tobytes() == data -@parameterized_class( - ("name", "color_mode"), - [ - ("4Color", BC1Encoder.ColorMode.FourColor), - ("3Color", BC1Encoder.ColorMode.ThreeColor), - ("3Color_Black", BC1Encoder.ColorMode.ThreeColorBlack), - ], + +@pytest.mark.parametrize( + 'color_mode', + [BC1Encoder.ColorMode.FourColor, BC1Encoder.ColorMode.ThreeColor, BC1Encoder.ColorMode.ThreeColorBlack], ) -class TestBC1Encoder(unittest.TestCase): +class TestBC1Encoder: """Test BC1Encoder""" - @classmethod - def setUpClass(cls): - cls.bc1_encoder = BC1Encoder(5, cls.color_mode) - - def test_block_4color(self): + def test_block_4color(self, color_mode): """Test encoder output with 4 color greyscale test block""" - out_tex = self.bc1_encoder.encode(BC1Blocks.greyscale.texture) - - self.assertEqual(out_tex.size_blocks, (1, 1), 'encoded texture has multiple blocks') - + encoder = BC1Encoder(color_mode=color_mode) + out_tex = encoder.encode(BC1Blocks.greyscale.texture) out_block = out_tex[0, 0] - self.assertFalse(out_block.is_3color, 'returned 3color mode for greyscale test block') - self.assertEqual(out_block, BC1Blocks.greyscale.block, 'encoded block is incorrect') - - def test_block_3color(self): - """Test encoder output with 3 color test block""" - out_tex = self.bc1_encoder.encode(BC1Blocks.three_color.texture) + assert out_tex.size_blocks == (1, 1) - self.assertEqual(out_tex.size_blocks, (1, 1), 'encoded texture has multiple blocks') + assert not out_block.is_3color + assert out_block == BC1Blocks.greyscale.block + def test_block_3color(self, color_mode): + """Test encoder output with 3 color test block""" + encoder = BC1Encoder(color_mode=color_mode) + out_tex = encoder.encode(BC1Blocks.three_color.texture) out_block = out_tex[0, 0] - if self.color_mode != BC1Encoder.ColorMode.FourColor: + assert out_tex.size_blocks == (1, 1) + + if encoder.color_mode != BC1Encoder.ColorMode.FourColor: # we only care about the selectors if we are in 3 color mode - self.assertTrue(out_block.is_3color, 'returned 4-color block for 3 color test block') - self.assertEqual(out_block, BC1Blocks.three_color.block, 'encoded block is incorrect') + assert out_block.is_3color + assert out_block == BC1Blocks.three_color.block else: - self.assertFalse(out_block.is_3color, 'returned 3-color block in 4-color mode') + assert not out_block.is_3color - def test_block_3color_black(self): + def test_block_3color_black(self, color_mode): """Test encoder output with 3 color test block with black pixels""" - out_tex = self.bc1_encoder.encode(BC1Blocks.three_color_black.texture) + encoder = BC1Encoder(color_mode=color_mode) + out_tex = encoder.encode(BC1Blocks.three_color_black.texture) + out_block = out_tex[0, 0] - self.assertEqual(out_tex.size_blocks, (1, 1), 'encoded texture has multiple blocks') + assert out_tex.size_blocks == (1, 1) - out_block = out_tex[0, 0] has_black = 3 in [j for row in out_block.selectors for j in row] - if self.color_mode == BC1Encoder.ColorMode.ThreeColorBlack: + if color_mode == BC1Encoder.ColorMode.ThreeColorBlack: # we only care about the selectors if we are in 3 color black mode - self.assertTrue(out_block.is_3color, 'returned 4-color block for 3 color test block with black') - self.assertTrue(has_black, 'block does not have black pixels as expected') - self.assertEqual(out_block, BC1Blocks.three_color_black.block, "encoded block is incorrect") - elif self.color_mode == BC1Encoder.ColorMode.ThreeColor: - self.assertFalse(has_black and out_block.is_3color, 'returned 3color block with black pixels') + assert out_block.is_3color + assert has_black + assert out_block == BC1Blocks.three_color_black.block + elif color_mode == BC1Encoder.ColorMode.ThreeColor: + assert not (has_black and out_block.is_3color) else: - self.assertFalse(out_block.is_3color, 'returned 3-color block in 4-color mode') + assert not out_block.is_3color -class TestBC1Decoder(unittest.TestCase): +@pytest.mark.parametrize('texture', [BC1Blocks.greyscale, BC1Blocks.three_color, BC1Blocks.three_color_black]) +class TestBC1Decoder: """Test BC1Decoder""" - @classmethod - def setUpClass(cls): - cls.bc1_decoder = BC1Decoder() - - @parameterized.expand( - [ - ("4color", BC1Blocks.greyscale.block, BC1Blocks.greyscale.image), - ("3color", BC1Blocks.three_color.block, BC1Blocks.three_color.image), - ("3color_black", BC1Blocks.three_color_black.block, BC1Blocks.three_color_black.image), - ] - ) - def test_block(self, _, block, image): + def test_block(self, texture): """Test decoder output for a single block""" + block = texture.block + image = texture.image + decoder = BC1Decoder() in_tex = BC1Texture(4, 4) in_tex[0, 0] = block - out_tex = self.bc1_decoder.decode(in_tex) + out_tex = decoder.decode(in_tex) - self.assertEqual(out_tex.size, (4, 4), 'decoded texture has incorrect dimensions') + assert out_tex.size == (4, 4) out_img = Image.frombytes('RGBA', (4, 4), out_tex.tobytes()) img_diff = ImageChops.difference(out_img, image).convert('L') img_hist = img_diff.histogram() - self.assertEqual(16, img_hist[0], 'decoded block is incorrect') + assert img_hist[0] == 16 diff --git a/tests/test_bc4.py b/tests/test_bc4.py index e5a6ad5..a78bb38 100644 --- a/tests/test_bc4.py +++ b/tests/test_bc4.py @@ -1,178 +1,179 @@ -import unittest -from parameterized import parameterized, parameterized_class +import math + +import pytest +from PIL import Image, ImageChops + from quicktex.s3tc.bc4 import BC4Block, BC4Texture, BC4Encoder, BC4Decoder from .images import BC4Blocks -from PIL import Image, ImageChops +block_bytes = b'\xF0\x10\x88\x86\x68\xAC\xCF\xFA' +selectors = [[0, 1, 2, 3]] * 2 + [[4, 5, 6, 7]] * 2 +endpoints = (240, 16) -class TestBC4Block(unittest.TestCase): - """Tests for the BC1Block class""" - block_bytes = b'\xF0\x10\x88\x86\x68\xAC\xCF\xFA' - selectors = [[0, 1, 2, 3]] * 2 + [[4, 5, 6, 7]] * 2 - endpoints = (240, 16) +class TestBC4Block: + """Tests for the BC1Block class""" def test_size(self): """Test the size and dimensions of BC4Block""" - self.assertEqual(BC4Block.nbytes, 8, 'incorrect block size') - self.assertEqual(BC4Block.width, 4, 'incorrect block width') - self.assertEqual(BC4Block.height, 4, 'incorrect block width') - self.assertEqual(BC4Block.size, (4, 4), 'incorrect block dimensions') + assert BC4Block.nbytes == 8 + assert BC4Block.width == 4 + assert BC4Block.height == 4 + assert BC4Block.size == (4, 4) def test_buffer(self): """Test the buffer protocol of BC4Block""" block = BC4Block() mv = memoryview(block) + mv[:] = block_bytes - self.assertFalse(mv.readonly, 'buffer is readonly') - self.assertTrue(mv.c_contiguous, 'buffer is not contiguous') - self.assertEqual(mv.ndim, 1, 'buffer is multidimensional') - self.assertEqual(mv.nbytes, BC4Block.nbytes, 'buffer is the wrong size') - self.assertEqual(mv.format, 'B', 'buffer has the wrong format') - - mv[:] = self.block_bytes - self.assertEqual(mv.tobytes(), self.block_bytes, 'incorrect buffer data') + assert not mv.readonly + assert mv.c_contiguous + assert mv.ndim == 1 + assert mv.nbytes == 8 + assert mv.format == 'B' + assert mv.tobytes() == block_bytes + assert mv.tobytes() == block.tobytes() def test_constructor(self): """Test constructing a block out of endpoints and selectors""" - block = BC4Block(*self.endpoints, self.selectors) - self.assertEqual(block.tobytes(), self.block_bytes, 'incorrect block bytes') - self.assertEqual(block.selectors, self.selectors, 'incorrect selectors') - self.assertEqual(block.endpoints, self.endpoints, 'incorrect endpoints') + block = BC4Block(*endpoints, selectors) + assert block.tobytes() == block_bytes + assert block.selectors == selectors + assert block.endpoints == endpoints def test_frombytes(self): """Test constructing a block out of raw data""" - block = BC4Block.frombytes(self.block_bytes) - self.assertEqual(block.tobytes(), self.block_bytes, 'incorrect block bytes') - self.assertEqual(block.selectors, self.selectors, 'incorrect selectors') - self.assertEqual(block.endpoints, self.endpoints, 'incorrect endpoints') + block = BC4Block.frombytes(block_bytes) + assert block.tobytes() == block_bytes + assert block.selectors == selectors + assert block.endpoints == endpoints def test_eq(self): """Test equality between two identical blocks""" - block1 = BC4Block.frombytes(self.block_bytes) - block2 = BC4Block.frombytes(self.block_bytes) - self.assertEqual(block1, block2, 'identical blocks not equal') + block1 = BC4Block.frombytes(block_bytes) + block2 = BC4Block.frombytes(block_bytes) + assert block1 == block2 def test_values_6(self): """Test values of a 6-value block""" block = BC4Block(8, 248, [[0] * 4] * 4) - self.assertEqual(block.values, [8, 248, 56, 104, 152, 200, 0, 255], 'incorrect values') - self.assertTrue(block.is_6value, 'incorrect is_6value') + assert block.values == [8, 248, 56, 104, 152, 200, 0, 255] + assert block.is_6value def test_values_8(self): """Test values of an 8-value block""" block = BC4Block(240, 16, [[0] * 4] * 4) - self.assertEqual(block.values, [240, 16, 208, 176, 144, 112, 80, 48], 'incorrect values') - self.assertFalse(block.is_6value, 'incorrect is_6value') + assert block.values == [240, 16, 208, 176, 144, 112, 80, 48] + assert not block.is_6value -@parameterized_class( - ("name", "w", "h", "wb", "hb"), [("8x8", 8, 8, 2, 2), ("9x9", 9, 9, 3, 3), ("7x7", 7, 7, 2, 2), ("7x9", 7, 9, 2, 3)] -) -class TestBC4Texture(unittest.TestCase): - def setUp(self): - self.tex = BC4Texture(self.w, self.h) - self.nbytes = self.wb * self.hb * BC4Block.nbytes +# noinspection PyMethodMayBeStatic +@pytest.mark.parametrize('w', [7, 8, 9]) +@pytest.mark.parametrize('h', [7, 8, 9]) +class TestBC4Texture: + def test_dimensions(self, w, h): + """Test dimensions of BC4Texture in pixels, blocks, and bytes""" + tex = BC4Texture(w, h) + wb = math.ceil(w / 4) + hb = math.ceil(h / 4) - def test_size(self): - """Test size of BC4Texture in bytes""" - self.assertEqual(self.tex.nbytes, self.nbytes, 'incorrect texture size') - self.assertEqual(len(self.tex.tobytes()), self.nbytes, 'incorrect texture size from tobytes') - - def test_dimensions(self): - """Test dimensions of BC4Texture in pixels""" - self.assertEqual(self.tex.width, self.w, 'incorrect texture width') - self.assertEqual(self.tex.height, self.h, 'incorrect texture height') - self.assertEqual(self.tex.size, (self.w, self.h), 'incorrect texture dimensions') - - def test_dimensions_blocks(self): - """Test dimensions of BC4Texture in blocks""" - self.assertEqual(self.tex.width_blocks, self.wb, 'incorrect texture width_blocks') - self.assertEqual(self.tex.height_blocks, self.hb, 'incorrect texture width_blocks') - self.assertEqual(self.tex.size_blocks, (self.wb, self.hb), 'incorrect texture dimensions_blocks') - - def test_blocks(self): + assert tex.nbytes == BC4Block.nbytes * wb * hb # block width x block height + assert len(tex.tobytes()) == tex.nbytes + + assert tex.width == w + assert tex.height == h + assert tex.size == (w, h) + + assert tex.width_blocks == wb + assert tex.height_blocks == hb + assert tex.size_blocks == (wb, hb) + + def test_blocks(self, w, h): """Test getting and setting blocks to BC4Texture""" - blocks = [[BC4Block.frombytes(bytes([x, y] + [0] * 6)) for x in range(self.wb)] for y in range(self.hb)] - for x in range(self.wb): - for y in range(self.hb): - self.tex[x, y] = blocks[y][x] - - b = self.tex.tobytes() - for x in range(self.wb): - for y in range(self.hb): - index = (x + (y * self.wb)) * BC4Block.nbytes - tb = self.tex[x, y] + tex = BC4Texture(w, h) + + # generate garbage blocks with the x and y index in the first 2 bytes + blocks = [ + [BC4Block.frombytes(bytes([x, y] + [0] * 6)) for x in range(tex.width_blocks)] + for y in range(tex.height_blocks) + ] + # assign those blocks to the texture + for x in range(tex.width_blocks): + for y in range(tex.height_blocks): + tex[x, y] = blocks[y][x] + + # get the blocks and analyze + b = tex.tobytes() + for x in range(tex.width_blocks): + for y in range(tex.height_blocks): + index = (x + (y * tex.width_blocks)) * BC4Block.nbytes + tb = tex[x, y] fb = BC4Block.frombytes(b[index : index + BC4Block.nbytes]) - self.assertEqual(tb, blocks[y][x], 'incorrect block read from texture') - self.assertEqual(fb, blocks[y][x], 'incorrect block read from texture bytes') + assert tb == blocks[y][x] + assert fb == blocks[y][x] - self.assertEqual(self.tex[-1, -1], self.tex[self.wb - 1, self.hb - 1], 'incorrect negative subscripting') + def text_subscript(self, w, h): + """Test BC4Texture subscripting for blocks""" + tex = BC4Texture(w, h) - with self.assertRaises(IndexError): - _ = self.tex[self.wb, self.hb] - with self.assertRaises(IndexError): - _ = self.tex[-1 - self.wb, -1 - self.hb] + # ensure negative wraparound works + assert tex[-1, -1] == tex[tex.width_blocks - 1, tex.height_blocks - 1] - def test_buffer(self): - """Test the buffer protocol of BC4Texture""" - mv = memoryview(self.tex) + with pytest.raises(IndexError): + _ = tex[tex.width_blocks, tex.height_blocks] + with pytest.raises(IndexError): + _ = tex[-1 - tex.width_blocks, -1 - tex.height_blocks] - self.assertFalse(mv.readonly, 'buffer is readonly') - self.assertTrue(mv.c_contiguous, 'buffer is not contiguous') - self.assertEqual(mv.nbytes, self.nbytes, 'buffer is the wrong size') - self.assertEqual(mv.format, 'B', 'buffer has the wrong format') + def test_buffer(self, w, h): + """Test the buffer protocol of BC1Texture""" + tex = BC4Texture(w, h) + mv = memoryview(tex) - data = b'\xF0\x10\x88\x86\x68\xAC\xCF\xFA' * self.wb * self.hb + data = block_bytes * tex.width_blocks * tex.height_blocks mv[:] = data - self.assertEqual(mv.tobytes(), data, 'incorrect buffer data') + assert not mv.readonly + assert mv.c_contiguous + assert mv.nbytes == tex.nbytes + assert mv.format == 'B' + assert mv.tobytes() == data -class TestBC4Encoder(unittest.TestCase): - """Test BC4Encoder""" - # 6-value blocks are not yet supported by the encoder so we only run one test - @classmethod - def setUpClass(cls): - cls.bc4_encoder = BC4Encoder(0) +class TestBC4Encoder: + """Test BC4Encoder""" def test_block(self): """Test encoder output with 8 value test block""" - out_tex = self.bc4_encoder.encode(BC4Blocks.eight_value.texture) - - self.assertEqual(out_tex.size_blocks, (1, 1), 'encoded texture has multiple blocks') - + encoder = BC4Encoder(0) + out_tex = encoder.encode(BC4Blocks.eight_value.texture) out_block = out_tex[0, 0] - self.assertFalse(out_block.is_6value, 'returned 6value mode') - self.assertEqual(out_block, BC4Blocks.eight_value.block, 'encoded block is incorrect') + assert out_tex.size_blocks == (1, 1) + assert not out_block.is_6value + assert out_block == BC4Blocks.eight_value.block -class TestBC4Decoder(unittest.TestCase): - """Test BC4Decoder""" - @classmethod - def setUpClass(cls): - cls.bc4_decoder = BC4Decoder(0) +@pytest.mark.parametrize('texture', [BC4Blocks.eight_value, BC4Blocks.six_value]) +class TestBC4Decoder: + """Test BC4Decoder""" - @parameterized.expand( - [ - ("8value", BC4Blocks.eight_value.block, BC4Blocks.eight_value.image), - ("6value", BC4Blocks.six_value.block, BC4Blocks.six_value.image), - ] - ) - def test_block(self, _, block, image): + def test_block(self, texture): """Test decoder output for a single block""" + block = texture.block + image = texture.image + decoder = BC4Decoder(0) in_tex = BC4Texture(4, 4) in_tex[0, 0] = block - out_tex = self.bc4_decoder.decode(in_tex) + out_tex = decoder.decode(in_tex) - self.assertEqual(out_tex.size, (4, 4), 'decoded texture has incorrect dimensions') + assert out_tex.size == (4, 4) out_img = Image.frombytes('RGBA', (4, 4), out_tex.tobytes()) img_diff = ImageChops.difference(out_img, image).convert('L') img_hist = img_diff.histogram() - self.assertEqual(16, img_hist[0], 'decoded block is incorrect') + assert img_hist[0] == 16 diff --git a/tests/test_install.py b/tests/test_install.py index 106d0e8..c78e85c 100644 --- a/tests/test_install.py +++ b/tests/test_install.py @@ -1,13 +1,9 @@ """Test if everything is installed correctly""" -import unittest -import os.path import quicktex -tests_path = os.path.dirname(os.path.realpath(__file__)) - -class TestInstall(unittest.TestCase): +class TestInstall: def test_version(self): """Test if the extension module version matches what setuptools returns""" try: diff --git a/tests/test_texture.py b/tests/test_texture.py index df4750e..4b85b92 100644 --- a/tests/test_texture.py +++ b/tests/test_texture.py @@ -1,58 +1,60 @@ -import unittest import os.path -from .images import image_path -from quicktex import RawTexture + +import pytest from PIL import Image +from quicktex import RawTexture +from .images import image_path + -class TestRawTexture(unittest.TestCase): +class TestRawTexture: boilerplate = Image.open(os.path.join(image_path, 'Boilerplate.png')) boilerplate_bytes = boilerplate.tobytes('raw', 'RGBX') width, height = boilerplate.size - size = width * height * 4 - - def setUp(self): - self.tex = RawTexture(self.width, self.height) + nbytes = width * height * 4 def test_size(self): """Test byte size and image dimensions""" - self.assertEqual(self.tex.nbytes, self.size, "incorrect texture byte size") - self.assertEqual(self.tex.width, self.width, "incorrect texture width") - self.assertEqual(self.tex.height, self.height, "incorrect texture height") - self.assertEqual(self.tex.size, (self.width, self.height), "incorrect texture dimensions") + tex = RawTexture(self.width, self.height) + assert tex.nbytes == self.nbytes + assert tex.width == self.width + assert tex.height == self.height + assert tex.size == (self.width, self.height) def test_pixels(self): """Test getting and setting pixel values""" + tex = RawTexture(self.width, self.height) color1 = (69, 13, 12, 0) # totally random color color2 = (19, 142, 93, 44) - self.tex[0, 0] = color1 - self.tex[-1, -1] = color2 - data = self.tex.tobytes() + tex[0, 0] = color1 + tex[-1, -1] = color2 + data = tex.tobytes() - self.assertEqual(self.tex[0, 0], color1) - self.assertEqual(self.tex[-1, -1], color2) - self.assertEqual(tuple(data[0:4]), color1) - self.assertEqual(tuple(data[-4:]), color2) + assert tex[0, 0] == color1 + assert tex[-1, -1] == color2 + assert tuple(data[0:4]) == color1 + assert tuple(data[-4:]) == color2 - with self.assertRaises(IndexError): - thing = self.tex[self.width, self.height] - with self.assertRaises(IndexError): - thing = self.tex[-1 - self.width, -1 - self.height] + with pytest.raises(IndexError): + _ = tex[self.width, self.height] + with pytest.raises(IndexError): + _ = tex[-1 - self.width, -1 - self.height] def test_buffer(self): """Test the Buffer protocol implementation for RawTexture""" - mv = memoryview(self.tex) - - self.assertFalse(mv.readonly, 'buffer is readonly') - self.assertTrue(mv.c_contiguous, 'buffer is not contiguous') - self.assertEqual(mv.nbytes, self.size, 'buffer is the wrong size') - self.assertEqual(mv.format, 'B', 'buffer has the wrong format') - + tex = RawTexture(self.width, self.height) + mv = memoryview(tex) mv[:] = self.boilerplate_bytes - self.assertEqual(mv.tobytes(), self.boilerplate_bytes, 'incorrect buffer data') + + assert not mv.readonly + assert mv.c_contiguous + assert mv.nbytes == self.nbytes + assert mv.format == 'B' + assert mv.tobytes() == self.boilerplate_bytes + assert mv.tobytes() == tex.tobytes() def test_frombytes(self): """Test the frombytes factory function""" bytetex = RawTexture.frombytes(self.boilerplate_bytes, *self.boilerplate.size) - self.assertEqual(self.boilerplate_bytes, bytetex.tobytes(), 'Incorrect bytes after writing to buffer') + assert self.boilerplate_bytes == bytetex.tobytes() From 661536e6f63e4be9363031d0bbd47ef4769c5130 Mon Sep 17 00:00:00 2001 From: Andrew Cassidy Date: Sun, 22 May 2022 20:59:37 -0700 Subject: [PATCH 08/13] use scoped lock --- quicktex/s3tc/bc1/OrderTable.h | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/quicktex/s3tc/bc1/OrderTable.h b/quicktex/s3tc/bc1/OrderTable.h index 6d4b564..d24cf10 100644 --- a/quicktex/s3tc/bc1/OrderTable.h +++ b/quicktex/s3tc/bc1/OrderTable.h @@ -58,7 +58,7 @@ template class OrderTable { static bool Generate() { static_assert(N == 4 || N == 3); - table_mutex.lock(); + std::scoped_lock{table_mutex}; if (!generated) { hashes = new std::array(); factors = new std::array(); @@ -85,8 +85,6 @@ template class OrderTable { generated = true; } - table_mutex.unlock(); - assert(generated); return true; } From 71c069d30cd3002526ffbf8241f37411b1e81faf Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Thu, 9 Jun 2022 11:32:38 +0000 Subject: [PATCH 09/13] Bump actions/setup-python from 3.1.2 to 4.0.0 Bumps [actions/setup-python](https://github.com/actions/setup-python) from 3.1.2 to 4.0.0. - [Release notes](https://github.com/actions/setup-python/releases) - [Commits](https://github.com/actions/setup-python/compare/v3.1.2...v4.0.0) --- updated-dependencies: - dependency-name: actions/setup-python dependency-type: direct:production update-type: version-update:semver-major ... Signed-off-by: dependabot[bot] --- .github/workflows/python-package.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/python-package.yml b/.github/workflows/python-package.yml index 2a12acc..0303ff0 100644 --- a/.github/workflows/python-package.yml +++ b/.github/workflows/python-package.yml @@ -16,7 +16,7 @@ jobs: fetch-depth: 0 - name: Set up Python - uses: actions/setup-python@v3.1.2 + uses: actions/setup-python@v4.0.0 - name: Install dependencies run: | @@ -96,7 +96,7 @@ jobs: - uses: actions/checkout@v3 # just need the changelog - name: Set up Python - uses: actions/setup-python@v3.1.2 + uses: actions/setup-python@v4.0.0 - name: Install dependencies run: | From 9f543495567aca34026c8e413c8497cd7e1e3093 Mon Sep 17 00:00:00 2001 From: Andrew Cassidy Date: Sun, 12 Jun 2022 17:16:18 -0700 Subject: [PATCH 10/13] Specify python versions --- .github/workflows/python-package.yml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/.github/workflows/python-package.yml b/.github/workflows/python-package.yml index 2a12acc..d0de14f 100644 --- a/.github/workflows/python-package.yml +++ b/.github/workflows/python-package.yml @@ -17,6 +17,8 @@ jobs: - name: Set up Python uses: actions/setup-python@v3.1.2 + with: + python-version: '3.x' - name: Install dependencies run: | @@ -97,6 +99,8 @@ jobs: - name: Set up Python uses: actions/setup-python@v3.1.2 + with: + python-version: '3.x' - name: Install dependencies run: | From 7ea104f71271903c1d20ad5ac96ee5a6afc46a5d Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 10 Oct 2022 12:46:28 +0000 Subject: [PATCH 11/13] Bump actions/setup-python from 4.0.0 to 4.3.0 Bumps [actions/setup-python](https://github.com/actions/setup-python) from 4.0.0 to 4.3.0. - [Release notes](https://github.com/actions/setup-python/releases) - [Commits](https://github.com/actions/setup-python/compare/v4.0.0...v4.3.0) --- updated-dependencies: - dependency-name: actions/setup-python dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] --- .github/workflows/python-package.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/python-package.yml b/.github/workflows/python-package.yml index ca81383..7187c82 100644 --- a/.github/workflows/python-package.yml +++ b/.github/workflows/python-package.yml @@ -16,7 +16,7 @@ jobs: fetch-depth: 0 - name: Set up Python - uses: actions/setup-python@v4.0.0 + uses: actions/setup-python@v4.3.0 with: python-version: '3.x' @@ -98,7 +98,7 @@ jobs: - uses: actions/checkout@v3 # just need the changelog - name: Set up Python - uses: actions/setup-python@v4.0.0 + uses: actions/setup-python@v4.3.0 with: python-version: '3.x' From 0dccd1cd07898b75956d30e5c36520d75a0cb481 Mon Sep 17 00:00:00 2001 From: Andrew Cassidy Date: Sat, 29 Oct 2022 21:03:12 -0700 Subject: [PATCH 12/13] Update pybind to 3.10 to allow Python 3.11 support --- CHANGELOG.md | 7 +++++++ pyproject.toml | 4 ++-- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 6a5c23d..276e944 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,13 @@ All notable changes to this project will be documented in this file +## Unreleased + +### Changed + +- Updated Pybind11 to version 3.10, adding Python 3.11 support + + ## 0.1.3 - 2022-04-13 ### Fixed diff --git a/pyproject.toml b/pyproject.toml index d93844f..d7d9c23 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -4,7 +4,7 @@ requires = [ "setuptools_scm>=6.2", "wheel", "cmake>=3.18", - "pybind11~=2.6.1", + "pybind11~=2.10", "ninja; sys_platform != 'win32'", ] build-backend = "setuptools.build_meta" @@ -81,5 +81,5 @@ manylinux-aarch64-image = "manylinux2014" [tool.black] line-length = 120 # 80-column is stupid -target-version = ['py37', 'py38', 'py39', 'py310'] +target-version = ['py37', 'py38', 'py39', 'py310', 'py310'] skip-string-normalization = true \ No newline at end of file From 38beffef059301b1a01b92f1df4075c78b8231d8 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Fri, 28 Oct 2022 11:58:15 +0000 Subject: [PATCH 13/13] Bump pypa/cibuildwheel from 2.5.0 to 2.11.2 Bumps [pypa/cibuildwheel](https://github.com/pypa/cibuildwheel) from 2.5.0 to 2.11.2. - [Release notes](https://github.com/pypa/cibuildwheel/releases) - [Changelog](https://github.com/pypa/cibuildwheel/blob/main/docs/changelog.md) - [Commits](https://github.com/pypa/cibuildwheel/compare/2.5.0...v2.11.2) --- updated-dependencies: - dependency-name: pypa/cibuildwheel dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] --- .github/workflows/python-package.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/python-package.yml b/.github/workflows/python-package.yml index ca81383..baa62f9 100644 --- a/.github/workflows/python-package.yml +++ b/.github/workflows/python-package.yml @@ -78,7 +78,7 @@ jobs: platforms: arm64 - name: Build wheels - uses: pypa/cibuildwheel@2.5.0 + uses: pypa/cibuildwheel@v2.11.2 env: MACOSX_DEPLOYMENT_TARGET: "10.15" CIBW_ARCHS_LINUX: ${{ matrix.arch[3] }}