-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #66 from elliotcmorris/work/1088-dist-info
[Build] CMake install Python dist-info
- Loading branch information
Showing
11 changed files
with
222 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
# Metadata files to be bundled with the installed package | ||
|
||
This directory contains files used for package discovery in the install | ||
tree. | ||
|
||
This includes the CMake config files, as well as a Python "dist-info" | ||
bundle. | ||
|
||
The CMake config files are used to allow CMake's `find_package` to | ||
discover an installed OpenAssetIO-MediaCreation CMake package (see [CMake docs](https://cmake.org/cmake/help/latest/manual/cmake-packages.7.html) | ||
for more info). | ||
|
||
The Python dist-info allows Python package managers (such as pip) to | ||
detect the presence of an `openassetio-mediacreation` package, and is | ||
configured such that a well-behaved package manager will error when | ||
trying to overwrite it. Specifically, the dist-info deliberately | ||
excludes a `RECORD` file (see [Python | ||
docs](https://packaging.python.org/en/latest/specifications/recording-installed-packages/#intentionally-preventing-changes-to-installed-packages) | ||
for more info). | ||
|
||
Some of the config files are templates (as evidenced by the `.in` | ||
suffix), and will be rendered to their final form as part of a CMake | ||
build/install. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
cmake |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
Metadata-Version: 2.1 | ||
Name: openassetio-mediacreation | ||
Version: @OPENASSETIO_MEDIACREATION_PYTHON_PACKAGE_VERSION@ |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
openassetio_mediacreation |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
# | ||
# Copyright 2013-2023 The Foundry Visionmongers Ltd | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
# | ||
""" | ||
Test CMake installed package. | ||
Python script invoked from Ctest, in order to test structure | ||
and contents of cmake installed package. Particularly with a focus | ||
on the .dist_info metadata required to make this package play well | ||
with pip. | ||
""" | ||
# pylint: disable=missing-function-docstring | ||
import os | ||
|
||
import pytest | ||
|
||
try: | ||
from importlib import metadata | ||
except: | ||
import importlib_metadata as metadata | ||
|
||
|
||
@pytest.mark.skipif( | ||
os.environ.get("OPENASSETIO_MEDIACREATION_CMAKE_PACKAGE_VERSION") is None, | ||
reason="CMake package only", | ||
) | ||
def test_cmake_dist_info(): | ||
dist = metadata.distribution("openassetio-mediacreation") | ||
|
||
# Check METADATA file exists with required keys. | ||
assert {"Name", "Metadata-Version", "Version"}.issubset(dist.metadata.keys()) | ||
assert dist.metadata["Name"] == "openassetio-mediacreation" | ||
assert dist.metadata["Version"].startswith( | ||
os.environ["OPENASSETIO_MEDIACREATION_CMAKE_PACKAGE_VERSION"] | ||
) | ||
|
||
# The lack of a RECORD means that `pip` is unable to accidentally | ||
# uninstall the package | ||
assert dist.read_text("RECORD") is None | ||
|
||
# The INSTALLER is used by `pip` to provide a hint when reporting | ||
# that it is unable to install a package due to no RECORD. | ||
installer = dist.read_text("INSTALLER") | ||
assert installer is not None | ||
assert installer.strip() == "cmake" | ||
|
||
# The above uses files in the dist-info directory, whereas pip uses | ||
# the directory name itself. So check that they match. | ||
# However, names use hyphen and paths use underscores, so switch. | ||
underscore_name = dist.metadata["Name"].replace("-", "_") | ||
dist_info_path = os.path.join( | ||
dist.locate_file(""), f"{underscore_name}-{dist.metadata['Version']}.dist-info" | ||
) | ||
assert os.path.isdir(dist_info_path) | ||
dist_from_dir = metadata.Distribution.at(dist_info_path) | ||
assert dict(dist.metadata) == dict(dist_from_dir.metadata) |