### Install Inflate64 Source: https://github.com/miurahr/inflate64/blob/main/docs/getting_started.md Install the inflate64 package using pip. This is the standard way to add the library to your Python environment. ```bash pip install inflate64 ``` -------------------------------- ### Python Extension Module Setup Source: https://github.com/miurahr/inflate64/blob/main/CMakeLists.txt Defines variables related to the Python package name, extension file name, and build directories. ```cmake set(PY_PACKAGE inflate64) set(PY_EXT_FILE _inflate64) ``` -------------------------------- ### Create and Populate Virtual Environment Source: https://github.com/miurahr/inflate64/blob/main/CMakeLists.txt Defines a custom CMake target to create a Python virtual environment and install project dependencies. It writes the requirements to a file and uses the appropriate pip command based on the operating system. ```cmake file( WRITE ${CMAKE_CURRENT_BINARY_DIR}/requirements.txt "\ncoverage[toml]>=5.2\nhypothesis\npytest>=6.0\npytest-benchmark\npytest-cov\npytest-timeout\ncffi\n") if (WIN32) set(PIP_COMMAND ${VENV_PATH}/Scripts/pip.exe) else() set(PIP_COMMAND ${VENV_PATH}/bin/pip) endif() add_custom_target( venv.stamp BYPRODUCTS venv.stamp COMMAND ${Python_EXECUTABLE} -m venv ${VENV_PATH} COMMAND ${PIP_COMMAND} install -r ${CMAKE_BINARY_DIR}/requirements.txt COMMAND ${CMAKE_COMMAND} -E touch venv.stamp) ``` -------------------------------- ### Determine Python Version Source: https://github.com/miurahr/inflate64/blob/main/CMakeLists.txt Executes a Python command to get the current Python version string. ```cmake execute_process( COMMAND ${Python_EXECUTABLE} -c "import sysconfig\nprint(sysconfig.get_python_version())\n" OUTPUT_VARIABLE PY_VERSION OUTPUT_STRIP_TRAILING_WHITESPACE) ``` -------------------------------- ### Determine Python Extension Suffix Source: https://github.com/miurahr/inflate64/blob/main/CMakeLists.txt Executes a Python command to get the system-specific extension suffix (e.g., .so, .pyd). ```cmake execute_process( COMMAND ${Python_EXECUTABLE} -c "import sysconfig\nprint(sysconfig.get_config_var('EXT_SUFFIX'))\n" OUTPUT_VARIABLE PY_EXT_EXT OUTPUT_STRIP_TRAILING_WHITESPACE) ``` -------------------------------- ### Build Python Extension using setup.py Source: https://github.com/miurahr/inflate64/blob/main/CMakeLists.txt Configures a custom CMake target to build Python extensions using the project's `setup.py` script. It dynamically selects the Python executable based on the operating system and build configuration (debug/release). ```cmake if (WIN32) if(DEBUG_BUILD) set(BUILD_EXT_PYTHON ${VENV_PATH}/Scripts/python_d.exe) else() set(BUILD_EXT_PYTHON ${VENV_PATH}/Scripts/python.exe) endif() set(BUILD_EXT_OPTION) else() set(BUILD_EXT_PYTHON ${VENV_PATH}/bin/python) set(BUILD_EXT_OPTION --warning-as-error) endif() add_custom_target( build_ext_by_setup BYPRODUCTS ${PY_EXT} COMMAND ${BUILD_EXT_PYTHON} setup.py build_ext ${BUILD_EXT_OPTION} WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} DEPENDS venv.stamp SOURCES ${_sources}) ``` -------------------------------- ### Build C Extension Library Source: https://github.com/miurahr/inflate64/blob/main/docs/contribution.md Generate the C extension for CPython using the 'generate_ext' CMake target. ```console cd cmake-build make generate_ext ``` -------------------------------- ### Source Files List Source: https://github.com/miurahr/inflate64/blob/main/CMakeLists.txt Lists all source files required for the project, including C and C++ files for the core library and extension module. ```cmake set(_sources src/ext/_inflate64module.c src/lib/deflate.c src/lib/inflate.c src/lib/inflate_tree.c src/lib/deflate_tree.c src/lib/util.c src/lib/static_tables.c ) ``` -------------------------------- ### Compress Data with Deflater Source: https://github.com/miurahr/inflate64/blob/main/docs/getting_started.md Instantiate the Deflater class and use its deflate and flush methods to compress data. The 'inflate64' library must be imported. ```python import inflate64 compressor = inflate64.Deflater() compressed = compressor.deflate(data) compressed += compressor.flush() ``` -------------------------------- ### Decompress Data with Inflater Source: https://github.com/miurahr/inflate64/blob/main/docs/getting_started.md Instantiate the Inflater class and use its inflate method to decompress data. Ensure you have the 'inflate64' library imported. ```python import inflate64 decompressor = inflate64.Inflater() extracted = decompressor.inflate(data) ``` -------------------------------- ### Python Version and Virtual Environment Configuration Source: https://github.com/miurahr/inflate64/blob/main/CMakeLists.txt Sets the target Python version, preferred Python implementations, and the path for the virtual environment. ```cmake set(PY_VERSION 3.13) set(Python_FIND_IMPLEMENTATIONS CPython) #set(Python_FIND_IMPLEMENTATIONS PyPy) set(VENV_PATH "${CMAKE_BINARY_DIR}/venv") ``` -------------------------------- ### Set Build Paths Source: https://github.com/miurahr/inflate64/blob/main/CMakeLists.txt Defines various paths used during the build process, including source directories, binary output directories, and the final Python extension path. ```cmake message(STATUS "Python SOABI is ${Python_SOABI}") set(PY_SRC_DIR src/${PY_PACKAGE}) set(EXT_DIR ${CMAKE_BINARY_DIR}) set(PY_EXT_DIR build/lib.${PY_PLATFORM}-${PY_VERSION}/${PY_PACKAGE}) set(PY_EXT ${PY_EXT_DIR}/${PY_EXT_FILE}${PY_EXT_EXT}) set(EXT ${EXT_DIR}/${PY_EXT_FILE}.${PY_EXT_EXT}) set(PY_EXT_INLINE ${CMAKE_SOURCE_DIR}/src/${PY_PACKAGE}/${PY_EXT_FILE}${PY_EXT_EXT}) ``` -------------------------------- ### Manual Build and Run with GDB Source: https://github.com/miurahr/inflate64/blob/main/docs/contribution.md Steps to build the pytest_runner executable using CMake and then run it under GDB for C/C++ debugging of Python tests. ```console mkdir cmake-build cd cmake-build cmake .. make pytest_runner gdb ./pytest_runner ../tests ``` -------------------------------- ### Run Pytest with Tox Source: https://github.com/miurahr/inflate64/blob/main/docs/contribution.md Execute the test suite using tox for a specific Python version (e.g., py313). ```console tox -e py313 ``` -------------------------------- ### Set Python Version and Implementation in CMake Source: https://github.com/miurahr/inflate64/blob/main/docs/contribution.md Modify these lines in CMakeLists.txt to specify the target Python version and implementation for building C extensions. ```cmake set(PY_VERSION 3.13) set(Python_FIND_IMPLEMENTATIONS PyPy) ``` -------------------------------- ### Set Minimum CMake Version and Project Name Source: https://github.com/miurahr/inflate64/blob/main/CMakeLists.txt Specifies the minimum required CMake version and defines the project name with supported languages. ```cmake cmake_minimum_required(VERSION 3.19) project(inflate64 C CXX) ``` -------------------------------- ### Debug Build and Log Level Configuration Source: https://github.com/miurahr/inflate64/blob/main/CMakeLists.txt Defines cache variables for enabling debug builds and setting the debug log level. ```cmake set(DEBUG_BUILD OFF CACHE BOOL "Enable debug build?") set(DEBUG_LOG_LEVEL "1" CACHE STRING "Debug log level?") ``` -------------------------------- ### Set C and C++ Standards Source: https://github.com/miurahr/inflate64/blob/main/CMakeLists.txt Configures the C and C++ language standards to be used during compilation. ```cmake set(CMAKE_C_STANDARD 11) set(CMAKE_CXX_STANDARD 17) ``` -------------------------------- ### Determine Python Platform Tag Source: https://github.com/miurahr/inflate64/blob/main/CMakeLists.txt Executes a Python command to retrieve the platform tag (e.g., 'linux', 'win32'). ```cmake execute_process( COMMAND ${Python_EXECUTABLE} -c "import sysconfig\nprint(sysconfig.get_platform())\n" OUTPUT_VARIABLE PY_PLATFORM OUTPUT_STRIP_TRAILING_WHITESPACE) ``` -------------------------------- ### Build Python Extension using CMake Source: https://github.com/miurahr/inflate64/blob/main/CMakeLists.txt Configures a custom CMake target to build a Python extension library directly using CMake. It includes options for MSVC specific warnings and debug definitions. ```cmake include_directories(src/lib) Python_add_library(_inflate64 MODULE WITH_SOABI ${_sources}) if(MSVC) target_compile_options(_inflate64 PRIVATE "/wd4996") endif() if(DEBUG_BUILD) target_compile_definitions(_inflate64 PRIVATE -DZLIB_DEBUG=${DEBUG_LOG_LEVEL}) endif() add_custom_target(build_ext BYPRODUCTS ${PY_EXT_INLINE} COMMAND ${CMAKE_COMMAND} -E copy_if_different $ "${PY_SRC_DIR}" DEPENDS _inflate64 venv.stamp ) ``` -------------------------------- ### Find Python Package Source: https://github.com/miurahr/inflate64/blob/main/CMakeLists.txt Locates the Python interpreter and development components using a specific version strategy. ```cmake set(Python_FIND_STRATEGY VERSION) find_package(Python ${PY_VERSION}.0...${PY_VERSION}.99 COMPONENTS Interpreter Development) ``` -------------------------------- ### Pytest Runner C++ Code Source: https://github.com/miurahr/inflate64/blob/main/CMakeLists.txt Generates a C++ source file that constructs and executes a Python script for running pytest. This runner dynamically appends necessary Python paths and passes command-line arguments to pytest. ```cmake file( WRITE ${CMAKE_CURRENT_BINARY_DIR}/pytest_runner.cpp " #include #include #include int main(int argc, char **argv) { std::string args; if ( argc > 1) { args.append(\"[\"); for (int i = 1; i < argc; i++) { if (i > 2) args.append(\",\"); args.append(\"\\\""); args.append(argv[i]); args.append(\"\\\""); } args.append(\"]\"); } std::filesystem::path src_path = \"${SRC_PATH}\"; std::filesystem::path vsite_path_a = \"${VPKG_PATH_A}\"; std::filesystem::path vsite_path_b = \"${VPKG_PATH_B}\"; std::filesystem::path vsite_path_c = \"${VPKG_PATH_C}\"; std::string pycode = \"import sys\\n\" \"sys.path.append('\" + src_path.string() + \"')\n\" \"sys.path.append('\" + vsite_path_a.string() + \"')\n\" \"sys.path.append('\" + vsite_path_b.string() + \"')\n\" \"import pytest\n\" \"pytest.main(\" + args + \")\n\"; execl(\"${Python_EXECUTABLE}\", \"${Python_EXECUTABLE}\", \"-c\", pycode.c_str(), (char*)0); return 0; }" ) add_executable(pytest_runner ${CMAKE_CURRENT_BINARY_DIR}/pytest_runner.cpp) target_include_directories(pytest_runner PRIVATE ${Python_INCLUDE_DIRS}) target_link_libraries(pytest_runner PRIVATE ${Python_LIBRARIES}) add_dependencies(pytest_runner venv.stamp build_ext) ``` -------------------------------- ### Conditional Compilation Warnings Source: https://github.com/miurahr/inflate64/blob/main/CMakeLists.txt Sets compilation warnings to be treated as errors, conditionally based on the DEBUG_BUILD variable. ```cmake if (DEBUG_BUILD) else() set(COMPILE_WARNING_AS_ERROR ON) endif() ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.