Skip to content

Commit

Permalink
Fix symlinks and make doc optional
Browse files Browse the repository at this point in the history
  • Loading branch information
remia committed Jul 9, 2023
1 parent 1dbce4f commit a481e2e
Show file tree
Hide file tree
Showing 5 changed files with 56 additions and 59 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/wheel_workflow.yml
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ jobs:
platforms: all

- name: Build wheels
uses: pypa/cibuildwheel@v2.12.0
uses: pypa/cibuildwheel@v2.13.1
env:
CIBW_BUILD: ${{ matrix.python }}
CIBW_ARCHS: ${{ matrix.arch }}
Expand Down Expand Up @@ -194,7 +194,7 @@ jobs:
python-version: '3.8'

- name: Build wheels
uses: pypa/cibuildwheel@v2.12.0
uses: pypa/cibuildwheel@v2.13.1
env:
CIBW_BUILD: ${{ matrix.python }}
CIBW_ARCHS: ${{ matrix.arch }}
Expand Down Expand Up @@ -245,7 +245,7 @@ jobs:
python-version: '3.8'

- name: Build wheels
uses: pypa/cibuildwheel@v2.12.0
uses: pypa/cibuildwheel@v2.13.1
env:
CIBW_BUILD: ${{ matrix.python }}
CIBW_ARCHS: ${{ matrix.arch }}
Expand Down
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,7 @@ endif()
# Other preferences

option(OCIO_VERBOSE "Display more information when searching or installing dependencies" OFF)
option(OCIO_USE_SOVERSION "Enable versioning in OCIO shared library name" ON)

###############################################################################
# Warnings / debugging settings
Expand Down
97 changes: 44 additions & 53 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@

import os
import re
import shutil
import subprocess
import sys
import tempfile
Expand All @@ -16,60 +15,49 @@


# Extract the project version from CMake generated ABI header.
# NOTE: When droping support for Python2 we can use
# tempfile.TemporaryDirectory() context manager instead of try...finally.
def get_version():
VERSION_REGEX = re.compile(
r"^\s*#\s*define\s+OCIO_VERSION_FULL_STR\s+\"(.*)\"\s*$", re.MULTILINE)

here = os.path.abspath(os.path.dirname(__file__))
dirpath = tempfile.mkdtemp()

try:
stdout = subprocess.check_output(["cmake", here], cwd=dirpath)
path = os.path.join(dirpath, "include", "OpenColorIO", "OpenColorABI.h")
with open(path) as f:
match = VERSION_REGEX.search(f.read())
return match.group(1)
except Exception as e:
raise RuntimeError(
"Unable to find OpenColorIO version: {}".format(str(e))
)
finally:
shutil.rmtree(dirpath)


# Remove symlinks as Python wheels do not support them at the moment.
# Rename the remaining dylib to the expected install name (major.minor).
def patch_symlink(folder):
if sys.platform.startswith("darwin"):
VERSION_REGEX = re.compile(
r"^libOpenColorIO.(?P<major>\d+).(?P<minor>\d+).\d+.dylib$")
NAME_PATTERN = "libOpenColorIO.{major}.{minor}.dylib"
elif sys.platform.startswith("linux"):
VERSION_REGEX = re.compile(
r"^libOpenColorIO.so.(?P<major>\d+).(?P<minor>\d+).\d+$")
NAME_PATTERN = "libOpenColorIO.so.{major}.{minor}"
else:
return

# First remove all symlinks in the folder
for f in os.listdir(folder):
filepath = os.path.join(folder, f)
if os.path.islink(filepath):
os.remove(filepath)

# Then match the remaining OCIO dynamic lib and rename it
for f in os.listdir(folder):
filepath = os.path.join(folder, f)
match = VERSION_REGEX.search(f)
if match:
res = match.groupdict()
new_filename = NAME_PATTERN.format(
major=res["major"], minor=res["minor"])
new_filepath = os.path.join(folder, new_filename)
os.rename(filepath, new_filepath)
break

with tempfile.TemporaryDirectory() as tmpdir:
try:
subprocess.check_call(["cmake", here], cwd=tmpdir)
path = os.path.join(tmpdir, "include", "OpenColorIO", "OpenColorABI.h")
with open(path) as f:
match = VERSION_REGEX.search(f.read())
return match.group(1)
except Exception as e:
raise RuntimeError(
"Unable to find OpenColorIO version: {}".format(str(e))
)


# Call CMake find_package from a dummy script and return whether the package
# has been found or not.
def cmake_find_package(package_name):
with tempfile.TemporaryDirectory() as tmpdir:
try:
cmakelist_path = os.path.join(tmpdir, "CMakeLists.txt")
with open(cmakelist_path, "w") as f:
f.write("""
cmake_minimum_required(VERSION 3.13)
project(test LANGUAGES CXX)
find_package({} REQUIRED)
""".format(package_name)
)

subprocess.check_call(
["cmake", tmpdir],
cwd=tmpdir,
stdout=subprocess.DEVNULL,
stderr=subprocess.DEVNULL
)
return True
except Exception as e:
return False


# Convert distutils Windows platform specifiers to CMake -A arguments
Expand Down Expand Up @@ -112,7 +100,7 @@ def build_extension(self, ext):
# Not used on MSVC, but no harm
"-DCMAKE_BUILD_TYPE={}".format(cfg),
"-DBUILD_SHARED_LIBS=ON",
"-DOCIO_BUILD_DOCS=ON",
"-DOCIO_USE_SOVERSION=OFF",
"-DOCIO_BUILD_APPS=ON",
"-DOCIO_BUILD_TESTS=OFF",
"-DOCIO_BUILD_GPU_TESTS=OFF",
Expand Down Expand Up @@ -175,6 +163,11 @@ def build_extension(self, ext):
if sys.platform.startswith("darwin"):
cmake_args += ["-DCMAKE_INSTALL_RPATH={}".format("@loader_path;@loader_path/..")]

# Documentation is used for Python docstrings but we allow to build
# the wheel without docs to remove a hard dependency on doxygen.
if cmake_find_package("Doxygen"):
cmake_args += ["-DOCIO_BUILD_DOCS=ON"]

# Set CMAKE_BUILD_PARALLEL_LEVEL to control the parallel build level
# across all generators.
if "CMAKE_BUILD_PARALLEL_LEVEL" not in os.environ:
Expand All @@ -194,8 +187,6 @@ def build_extension(self, ext):
["cmake", "--build", "."] + build_args, cwd=self.build_temp
)

patch_symlink(extdir)


# For historical reason, we use PyOpenColorIO as the import name
setup(
Expand Down
11 changes: 8 additions & 3 deletions src/OpenColorIO/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -390,15 +390,20 @@ elseif(APPLE)
if (_OCIO_LINK_FLAGS_LIST_)
list(JOIN _OCIO_LINK_FLAGS_LIST_ ";" _OCIO_LINK_FLAGS_LIST_)
set(CUSTOM_LINK_FLAGS "${CUSTOM_LINK_FLAGS};${_OCIO_LINK_FLAGS_LIST_}")
endif()
endif()
endif()

if (OCIO_USE_SOVERSION)
set_target_properties(OpenColorIO PROPERTIES
VERSION ${OpenColorIO_VERSION}
SOVERSION ${SOVERSION}
)
endif()

set_target_properties(OpenColorIO PROPERTIES
OUTPUT_NAME ${PROJECT_NAME}${OCIO_LIBNAME_SUFFIX}
COMPILE_OPTIONS "${PLATFORM_COMPILE_OPTIONS}"
LINK_OPTIONS "${CUSTOM_LINK_FLAGS}"
VERSION ${OpenColorIO_VERSION}
SOVERSION ${SOVERSION}
PUBLIC_HEADER "${INSTALL_HEADERS}"
)

Expand Down
Empty file removed tests/data/__init__.py
Empty file.

0 comments on commit a481e2e

Please sign in to comment.