Skip to content
This repository has been archived by the owner on Sep 13, 2021. It is now read-only.

Commit

Permalink
Merge pull request #25 from fredrikaverpil/tests
Browse files Browse the repository at this point in the history
Add simple test
  • Loading branch information
fredrikaverpil authored Feb 1, 2019
2 parents c14e0ba + b3aebd4 commit 764d25a
Show file tree
Hide file tree
Showing 27 changed files with 303 additions and 27 deletions.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,12 @@ When browsing an Azure Pipelines build, click the "Summary" link, and you will s
- Install the wheel: `pip install ...`
- From within Python, import OpenImageIO: `from oiio import OpenImageIO as oiio`

See the `tests` folder for code examples used to test the built wheels' functionality.

## Notes

- Official OpenImageIO repository at [OpenImageIO/oiio](https://github.com/OpenImageIO/oiio), note the `.travis.yml` and `appveyor.yml`
- The python3 files for oiio at [vcpkg/ports/python3](https://github.com/Microsoft/vcpkg/tree/master/ports/python3)
- The vcpkg files for oiio at [vcpkg/ports/openimageio](https://github.com/Microsoft/vcpkg/tree/master/ports/openimageio)
- Get SHA512 of file:
- macOS: `openssl dgst -sha512 [FILE]`
22 changes: 18 additions & 4 deletions macOS-10.13-azure-pipelines.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# https://aka.ms/yaml
# https://aka.ms/hosted-agent-software
# https://docs.microsoft.com/en-us/azure/devops/pipelines/scripts/cross-platform-scripting
# https://docs.microsoft.com/en-us/azure/devops/pipelines/agents/hosted?view=azdevops&tabs=yaml
# https://github.com/OpenImageIO/oiio/blob/master/INSTALL.md
Expand All @@ -22,6 +23,7 @@ jobs:
azure.vm_image: 'macOS-10.13'
src.python: '$(Agent.BuildDirectory)/s/src/python'
src.vcpkg: '$(Agent.BuildDirectory)/s/src/vcpkg'
tests: '$(Agent.BuildDirectory)/s/tests'
install.vcpkg: $(Agent.BuildDirectory)/s/vcpkg
pypackage.version: '2.0.4+$(Build.BuildNumber)'
pypackage.os_name: 'Microsoft :: MacOS'
Expand Down Expand Up @@ -65,18 +67,19 @@ jobs:
# Copy customized port(s) into place
- bash: |
cp -r -v $(src.vcpkg)/ports/python3-py$(python.version)/* $(install.vcpkg)/ports/python3
cp -r -v $(src.vcpkg)/ports/python3-py$(python.version).$(python.version_patch)/* $(install.vcpkg)/ports/python3
cp -r -v $(src.vcpkg)/ports/openimageio-py$(python.version)/* $(install.vcpkg)/ports/openimageio
cp -r -v $(src.vcpkg)/ports/pybind11-py$(python.version)/* $(install.vcpkg)/ports/pybind11
displayName: Override vcpkg port files
# Install pybind11 via vcpkg
# Install python3 and pybind11 via vcpkg
- bash: |
cd $(install.vcpkg)
./vcpkg list
./vcpkg install python3:x64-osx
./vcpkg install pybind11:x64-osx
./vcpkg list
displayName: Install pybind11
displayName: Install python3 and pybind11
# Install oiio prerequisites via vcpkg
- bash: |
Expand Down Expand Up @@ -124,4 +127,15 @@ jobs:
- task: PublishBuildArtifacts@1
inputs:
pathtoPublish: '$(Build.ArtifactStagingDirectory)'
artifactName: drop-$(python.version)
artifactName: drop-$(python.version)

# Tests
- bash: |
cd $(tests)
python --version
pip list
pip install $(Build.ArtifactStagingDirectory)/*.whl
pip install pytest
pip list
pytest --verbose
displayName: Run rudimental test(s)
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
diff --git a/Modules/_io/_iomodule.c b/Modules/_io/_iomodule.c
--- a/Modules/_io/_iomodule.c
+++ b/Modules/_io/_iomodule.c
@@ -21,7 +21,7 @@
#endif /* HAVE_SYS_STAT_H */

#ifdef MS_WINDOWS
-#include <consoleapi.h>
+#include <windows.h>
#endif

/* Various interned strings */
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
diff --git a/PCbuild/python.props b/PCbuild/python.props
--- a/PCbuild/python.props
+++ b/PCbuild/python.props
@@ -76,7 +76,7 @@
-->
<_RegistryVersion>$(Registry:HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Microsoft SDKs\Windows\v10.0@ProductVersion)</_RegistryVersion>
<_RegistryVersion Condition="$(_RegistryVersion) == ''">$(Registry:HKEY_LOCAL_MACHINE\WOW6432Node\SOFTWARE\Microsoft\Microsoft SDKs\Windows\v10.0@ProductVersion)</_RegistryVersion>
- <DefaultWindowsSDKVersion>10.0.15063.0</DefaultWindowsSDKVersion>
+ <DefaultWindowsSDKVersion Condition="$(_RegistryVersion) == '10.0.15063'">10.0.15063.0</DefaultWindowsSDKVersion>
<DefaultWindowsSDKVersion Condition="$(_RegistryVersion) == '10.0.14393'">10.0.14393.0</DefaultWindowsSDKVersion>
<DefaultWindowsSDKVersion Condition="$(_RegistryVersion) == '10.0.10586'">10.0.10586.0</DefaultWindowsSDKVersion>
<DefaultWindowsSDKVersion Condition="$(_RegistryVersion) == '10.0.10240'">10.0.10240.0</DefaultWindowsSDKVersion>
3 changes: 3 additions & 0 deletions src/vcpkg/ports/python3-py3.6.5/CONTROL
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Source: python3
Version: 3.6.4-2
Description: The Python programming language as an embeddable library
115 changes: 115 additions & 0 deletions src/vcpkg/ports/python3-py3.6.5/portfile.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
if (VCPKG_LIBRARY_LINKAGE STREQUAL dynamic AND VCPKG_CRT_LINKAGE STREQUAL static)
message(STATUS "Warning: Dynamic library with static CRT is not supported. Building static library.")
set(VCPKG_LIBRARY_LINKAGE static)
endif()

set(PYTHON_VERSION_MAJOR 3)
set(PYTHON_VERSION_MINOR 6)
set(PYTHON_VERSION_PATCH 5)
set(PYTHON_VERSION ${PYTHON_VERSION_MAJOR}.${PYTHON_VERSION_MINOR}.${PYTHON_VERSION_PATCH})

include(vcpkg_common_functions)

vcpkg_from_github(
OUT_SOURCE_PATH TEMP_SOURCE_PATH
REPO python/cpython
REF v${PYTHON_VERSION}
SHA512 1fa9188e80d9766c7c13ff292f1f86e31a4ae4979b11cf4c0152ef97c906b4a045627af1c450ef3a46e024b0a79af6ece289d3b83711c9c7a9041c95083b3b16
HEAD_REF master
)

if(WIN32)
vcpkg_apply_patches(
SOURCE_PATH ${TEMP_SOURCE_PATH}
PATCHES
${CMAKE_CURRENT_LIST_DIR}/0004-Fix-iomodule-for-RS4-SDK.patch
${CMAKE_CURRENT_LIST_DIR}/0005-Fix-DefaultWindowsSDKVersion.patch
)
endif()

# We need per-triplet directories because we need to patch the project files differently based on the linkage
# Because the patches patch the same file, they have to be applied in the correct order
set(SOURCE_PATH "${TEMP_SOURCE_PATH}-Lib-${VCPKG_LIBRARY_LINKAGE}-crt-${VCPKG_CRT_LINKAGE}")
file(REMOVE_RECURSE ${SOURCE_PATH})
file(RENAME "${TEMP_SOURCE_PATH}" ${SOURCE_PATH})

if(WIN32)
if (VCPKG_LIBRARY_LINKAGE STREQUAL static)
vcpkg_apply_patches(
SOURCE_PATH ${SOURCE_PATH}
PATCHES
${CMAKE_CURRENT_LIST_DIR}/0001-Static-library.patch
)
endif()
if (VCPKG_CRT_LINKAGE STREQUAL static)
vcpkg_apply_patches(
SOURCE_PATH ${SOURCE_PATH}
PATCHES
${CMAKE_CURRENT_LIST_DIR}/0002-Static-CRT.patch
)
endif()
endif()

if (VCPKG_TARGET_ARCHITECTURE MATCHES "x86")
set(BUILD_ARCH "Win32")
set(OUT_DIR "win32")
elseif (VCPKG_TARGET_ARCHITECTURE MATCHES "x64")
set(BUILD_ARCH "x64")
set(OUT_DIR "amd64")
else()
message(FATAL_ERROR "Unsupported architecture: ${VCPKG_TARGET_ARCHITECTURE}")
endif()

if(WIN32)
vcpkg_build_msbuild(
PROJECT_PATH ${SOURCE_PATH}/PCBuild/pythoncore.vcxproj
PLATFORM ${BUILD_ARCH})
else()
message(STATUS "Configure ${TARGET_TRIPLET}-dbg")
vcpkg_execute_required_process(
COMMAND ./configure --enable-shared
WORKING_DIRECTORY ${SOURCE_PATH}
)
message(STATUS "Configure ${TARGET_TRIPLET}-dbg done")

message(STATUS "Build ${TARGET_TRIPLET}-dbg")
vcpkg_execute_required_process(
COMMAND make libpython3.6m.a
WORKING_DIRECTORY ${SOURCE_PATH}
)
message(STATUS "Build ${TARGET_TRIPLET}-dbg done")
endif()

if (VCPKG_LIBRARY_LINKAGE STREQUAL static)
vcpkg_apply_patches(
SOURCE_PATH ${SOURCE_PATH}
PATCHES
${CMAKE_CURRENT_LIST_DIR}/0003-Fix-header-for-static-linkage.patch
)
endif()

file(GLOB HEADERS ${SOURCE_PATH}/Include/*.h)
if(WIN32)
file(COPY ${HEADERS} ${SOURCE_PATH}/PC/pyconfig.h DESTINATION ${CURRENT_PACKAGES_DIR}/include/python${PYTHON_VERSION_MAJOR}.${PYTHON_VERSION_MINOR})
else()
file(COPY ${HEADERS} ${SOURCE_PATH}/pyconfig.h DESTINATION ${CURRENT_PACKAGES_DIR}/include/python${PYTHON_VERSION_MAJOR}.${PYTHON_VERSION_MINOR})
endif()

file(COPY ${SOURCE_PATH}/Lib DESTINATION ${CURRENT_PACKAGES_DIR}/share/python${PYTHON_VERSION_MAJOR})

if(WIN32)
file(COPY ${SOURCE_PATH}/PCBuild/${OUT_DIR}/python${PYTHON_VERSION_MAJOR}${PYTHON_VERSION_MINOR}.lib DESTINATION ${CURRENT_PACKAGES_DIR}/lib)
file(COPY ${SOURCE_PATH}/PCBuild/${OUT_DIR}/python${PYTHON_VERSION_MAJOR}${PYTHON_VERSION_MINOR}_d.lib DESTINATION ${CURRENT_PACKAGES_DIR}/debug/lib)
if (VCPKG_LIBRARY_LINKAGE STREQUAL dynamic)
file(COPY ${SOURCE_PATH}/PCBuild/${OUT_DIR}/python${PYTHON_VERSION_MAJOR}${PYTHON_VERSION_MINOR}.dll DESTINATION ${CURRENT_PACKAGES_DIR}/bin)
file(COPY ${SOURCE_PATH}/PCBuild/${OUT_DIR}/python${PYTHON_VERSION_MAJOR}${PYTHON_VERSION_MINOR}_d.dll DESTINATION ${CURRENT_PACKAGES_DIR}/debug/bin)
endif()
else()
file(COPY ${SOURCE_PATH}/libpython${PYTHON_VERSION_MAJOR}.${PYTHON_VERSION_MINOR}m.a DESTINATION ${CURRENT_PACKAGES_DIR}/lib)
endif()

# Handle copyright
file(COPY ${SOURCE_PATH}/LICENSE DESTINATION ${CURRENT_PACKAGES_DIR}/share/python${PYTHON_VERSION_MAJOR})
file(RENAME ${CURRENT_PACKAGES_DIR}/share/python${PYTHON_VERSION_MAJOR}/LICENSE ${CURRENT_PACKAGES_DIR}/share/python${PYTHON_VERSION_MAJOR}/copyright)

vcpkg_copy_pdbs()
39 changes: 39 additions & 0 deletions src/vcpkg/ports/python3-py3.7.0/0001-Static-library.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
--- a/PCbuild/pythoncore.vcxproj
+++ b/PCbuild/pythoncore.vcxproj
@@ -41,7 +41,7 @@
<Import Project="python.props" />
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
<PropertyGroup Label="Configuration">
- <ConfigurationType>DynamicLibrary</ConfigurationType>
+ <ConfigurationType>StaticLibrary</ConfigurationType>
<UseOfMfc>false</UseOfMfc>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
@@ -67,13 +67,25 @@
<ClCompile>
<AdditionalOptions>/Zm200 %(AdditionalOptions)</AdditionalOptions>
<AdditionalIncludeDirectories>$(PySourcePath)Python;$(PySourcePath)Modules\zlib;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
- <PreprocessorDefinitions>_USRDLL;Py_BUILD_CORE;Py_ENABLE_SHARED;MS_DLL_ID="$(SysWinVer)";%(PreprocessorDefinitions)</PreprocessorDefinitions>
+ <PreprocessorDefinitions>_USRDLL;Py_BUILD_CORE;Py_NO_ENABLE_SHARED;MS_DLL_ID="$(SysWinVer)";%(PreprocessorDefinitions)</PreprocessorDefinitions>
</ClCompile>
<Link>
<AdditionalDependencies>version.lib;shlwapi.lib;ws2_32.lib;%(AdditionalDependencies)</AdditionalDependencies>
<AdditionalLibraryDirectories>%(AdditionalLibraryDirectories);$(PySourcePath)PC\external\$(PlatformToolset)\$(ArchName)</AdditionalLibraryDirectories>
<BaseAddress>0x1e000000</BaseAddress>
</Link>
+ <Lib>
+ <TargetMachine Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">MachineX86</TargetMachine>
+ </Lib>
+ <Lib>
+ <TargetMachine Condition="'$(Configuration)|$(Platform)'=='PGInstrument|Win32'">MachineX86</TargetMachine>
+ </Lib>
+ <Lib>
+ <TargetMachine Condition="'$(Configuration)|$(Platform)'=='PGUpdate|Win32'">MachineX86</TargetMachine>
+ </Lib>
+ <Lib>
+ <TargetMachine Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">MachineX86</TargetMachine>
+ </Lib>
</ItemDefinitionGroup>
<ItemGroup>
<ClInclude Include="..\Include\abstract.h" />
--
15 changes: 15 additions & 0 deletions src/vcpkg/ports/python3-py3.7.0/0002-Static-CRT.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
--- a/PCbuild/pythoncore.vcxproj
+++ b/PCbuild/pythoncore.vcxproj
@@ -68,6 +68,10 @@
<AdditionalOptions>/Zm200 %(AdditionalOptions)</AdditionalOptions>
<AdditionalIncludeDirectories>$(PySourcePath)Python;$(PySourcePath)Modules\zlib;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<PreprocessorDefinitions>_USRDLL;Py_BUILD_CORE;Py_NO_ENABLE_SHARED;MS_DLL_ID="$(SysWinVer)";%(PreprocessorDefinitions)</PreprocessorDefinitions>
+ <RuntimeLibrary Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">MultiThreadedDebug</RuntimeLibrary>
+ <RuntimeLibrary Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">MultiThreadedDebug</RuntimeLibrary>
+ <RuntimeLibrary Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">MultiThreaded</RuntimeLibrary>
+ <RuntimeLibrary Condition="'$(Configuration)|$(Platform)'=='Release|x64'">MultiThreaded</RuntimeLibrary>
</ClCompile>
<Link>
<AdditionalDependencies>version.lib;shlwapi.lib;ws2_32.lib;%(AdditionalDependencies)</AdditionalDependencies>
--

Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
diff --git a/PC/pyconfig.h b/PC/pyconfig.h
index 64e7aec..aa36745 100644
--- a/PC/pyconfig.h
+++ b/PC/pyconfig.h
@@ -274,6 +274,7 @@ typedef int pid_t;

/* For Windows the Python core is in a DLL by default. Test
Py_NO_ENABLE_SHARED to find out. Also support MS_NO_COREDLL for b/w compat */
+#define Py_NO_ENABLE_SHARED
#if !defined(MS_NO_COREDLL) && !defined(Py_NO_ENABLE_SHARED)
# define Py_ENABLE_SHARED 1 /* standard symbol for shared library */
# define MS_COREDLL /* deprecated old symbol */
--

12 changes: 0 additions & 12 deletions tests/test_01.py

This file was deleted.

35 changes: 35 additions & 0 deletions tests/test_imagedimensions.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
"""Get width and height of EXR image."""

import os

from oiio import OpenImageIO as oiio


def image_dimensions(image_filepath):
"""Get image dimensions.
params:
image_filepath: str
returns
int, int: width, height
"""
img_src = oiio.ImageBuf(image_filepath)
rgb_img_src = oiio.ImageBuf()
oiio.ImageBufAlgo.channels(rgb_img_src, img_src, (0, 1, 2))

img_width = rgb_img_src.spec().full_width
img_height = rgb_img_src.spec().full_height

return img_width, img_height


def test_answer():
"""Verify image dimensions."""
image_filepath = os.path.join(
os.path.dirname(__file__), "img", "test_image_01.exr"
)
img_width, img_height = image_dimensions(image_filepath)
assert img_width == 1024
assert img_height == 1024
Loading

0 comments on commit 764d25a

Please sign in to comment.