From b0899faab091ae8b214956c55073e199a040c3e8 Mon Sep 17 00:00:00 2001 From: David Feltell Date: Wed, 7 Jan 2026 13:26:36 +0000 Subject: [PATCH] [Build] Fix incorrect Version metadata in dist-info Closes #123. The CMake script has the ability to simulate a Python package installation, such that a `dist-info` metadata directory is installed alongside the package, effectively preventing accidental overwrite by other package managers (e.g. pip) when the project is installed via CMake - see #58. However, the `Version` field in the `METADATA` file that forms part of the Python package `dist-info` was not being properly filled in. This was not caught by CI because the test for it is only enabled if generation of Python traits via CMake is enabled (i.e. `OPENASSETIO_MEDIACREATION_GENERATE_PYTHON`), which was not the case for the "test" CMake preset used by the "Test Cpp" CI job. There was another problem with running the test, in that the PYTHONPATH was not properly set in the CMake test target, and so the test would not necessarily be able to locate the `openassetio-mediacreation` package installed by CMake. Signed-off-by: David Feltell --- .github/workflows/test.yml | 3 +++ CMakePresets.json | 3 ++- cmake/packaging/python.dist-info/METADATA.in | 2 +- tests/cpp/CMakeLists.txt | 8 ++------ 4 files changed, 8 insertions(+), 8 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 0053031..f4311a6 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -46,6 +46,9 @@ jobs: - name: Install Traitgen run: python -m pip install openassetio-traitgen + - name: Install Python test dependencies + run: python -m pip install -r tests/python/requirements.txt + - name: Configure CMake build run: | cmake -S . -DCMAKE_PREFIX_PATH=$(pwd)/openassetio -B build -G Ninja --preset test diff --git a/CMakePresets.json b/CMakePresets.json index 5e2d490..0533df6 100644 --- a/CMakePresets.json +++ b/CMakePresets.json @@ -7,7 +7,8 @@ "dev": true }, "cacheVariables": { - "OPENASSETIO_MEDIACREATION_ENABLE_TEST": "ON" + "OPENASSETIO_MEDIACREATION_ENABLE_TEST": "ON", + "OPENASSETIO_MEDIACREATION_GENERATE_PYTHON": "ON" } } ] diff --git a/cmake/packaging/python.dist-info/METADATA.in b/cmake/packaging/python.dist-info/METADATA.in index 21103d3..e540ce1 100644 --- a/cmake/packaging/python.dist-info/METADATA.in +++ b/cmake/packaging/python.dist-info/METADATA.in @@ -1,3 +1,3 @@ Metadata-Version: 2.1 Name: openassetio-mediacreation -Version: @OPENASSETIO_MEDIACREATION_PYTHON_PACKAGE_VERSION@ \ No newline at end of file +Version: @OPENASSETIO_MEDIACREATION_PYTHON_PKG_VERSION@ \ No newline at end of file diff --git a/tests/cpp/CMakeLists.txt b/tests/cpp/CMakeLists.txt index 5369d12..a90be98 100644 --- a/tests/cpp/CMakeLists.txt +++ b/tests/cpp/CMakeLists.txt @@ -17,17 +17,13 @@ target_compile_features(test.cpp PRIVATE cxx_std_17) if (OPENASSETIO_MEDIACREATION_ENABLE_PYTHON_INSTALL_DIST_INFO) - # Build the command to extend the PYTHONPATH such that the - # site-packages directory in the install tree is included correctly. - set(_set_pythonpath_command - PYTHONPATH=${CMAKE_INSTALL_PREFIX}/${OPENASSETIO_MEDIACREATION_PYTHON_SITEDIR}) - # Add pytest target to run the packaging tests. These are concerned # with python metadata information so run in a python context. add_custom_target( openassetio-mediacreation.tests.packaging COMMAND cmake -E echo -- "Running pytest check for CMake dist-info packaging" - COMMAND ${_set_pythonpath_command} && + COMMAND ${CMAKE_COMMAND} -E env + PYTHONPATH=${CMAKE_INSTALL_PREFIX}/${OPENASSETIO_MEDIACREATION_PYTHON_SITEDIR} pytest -v --capture=tee-sys "${CMAKE_CURRENT_LIST_DIR}/test_cmake.py" WORKING_DIRECTORY "${PROJECT_SOURCE_DIR}"