Skip to content

Commit 0ad5032

Browse files
Merge branch 'main' into simplify_cxx_example
2 parents 387031f + edffd5d commit 0ad5032

File tree

7 files changed

+62
-22
lines changed

7 files changed

+62
-22
lines changed

CMakeLists.txt

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ option(OTIO_INSTALL_COMMANDLINE_TOOLS "Install the OTIO command line tools" ON)
3434
option(OTIO_INSTALL_CONTRIB "Install the opentimelineio_contrib Python package" ON)
3535
set(OTIO_IMATH_LIBS "" CACHE STRING "Imath library overrides to use instead of src/deps or find_package")
3636
option(OTIO_FIND_IMATH "Find Imath using find_package, ignored if OTIO_IMATH_LIBS is set" OFF)
37+
option(OTIO_FIND_RAPIDJSON "Find RapidJSON using find_package" OFF)
3738
set(OTIO_PYTHON_INSTALL_DIR "" CACHE STRING "Python installation dir (such as the site-packages dir)")
3839

3940
# Build options
@@ -223,13 +224,10 @@ if (NOT "${OTIO_IMATH_LIBS}" STREQUAL "")
223224
set(OTIO_RESOLVED_IMATH_LIBRARIES "${OTIO_IMATH_LIBS}")
224225
set(USE_DEPS_IMATH OFF)
225226
elseif(OTIO_FIND_IMATH)
226-
find_package(Imath QUIET)
227+
set(USE_DEPS_IMATH OFF)
228+
find_package(Imath REQUIRED)
227229
if (Imath_FOUND)
228230
message(STATUS "Found Imath 3 at ${Imath_CONFIG}")
229-
set(USE_DEPS_IMATH OFF)
230-
else()
231-
message(STATUS "Imath 3 was not found, using src/deps/Imath")
232-
set(USE_DEPS_IMATH ON)
233231
endif()
234232
else()
235233
message(STATUS "Using src/deps/Imath by default")
@@ -240,6 +238,17 @@ if(USE_DEPS_IMATH)
240238
include_directories("${PROJECT_SOURCE_DIR}/src/deps/Imath/src")
241239
endif()
242240

241+
#----- RapidJSON
242+
243+
if(OTIO_FIND_RAPIDJSON)
244+
find_package(RapidJSON CONFIG REQUIRED)
245+
if (RapidJSON_FOUND)
246+
message(STATUS "Found RapidJSON at ${RapidJSON_CONFIG}")
247+
endif()
248+
else()
249+
message(STATUS "Using src/deps/rapidjson by default")
250+
endif()
251+
243252
# set up the internally hosted dependencies
244253
add_subdirectory(src/deps)
245254

src/deps/CMakeLists.txt

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,12 @@
44
#----- Other dependencies
55

66
# detect if the submodules haven't been updated
7-
set(DEPS_SUBMODULES pybind11 rapidjson)
7+
set(DEPS_SUBMODULES pybind11)
8+
9+
if(NOT OTIO_FIND_RAPIDJSON)
10+
set(DEPS_SUBMODULES ${DEPS_SUBMODULES} rapidjson)
11+
endif()
12+
813
foreach(submodule IN LISTS DEPS_SUBMODULES)
914
file(GLOB SUBMOD_CONTENTS ${submodule})
1015
list(LENGTH SUBMOD_CONTENTS SUBMOD_CONTENT_LEN)

src/opentimelineio/CMakeLists.txt

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -78,9 +78,15 @@ add_library(opentimelineio ${OTIO_SHARED_OR_STATIC_LIB}
7878
add_library(OTIO::opentimelineio ALIAS opentimelineio)
7979

8080
target_include_directories(opentimelineio
81-
PRIVATE "${PROJECT_SOURCE_DIR}/src"
82-
"${PROJECT_SOURCE_DIR}/src/deps"
83-
"${PROJECT_SOURCE_DIR}/src/deps/rapidjson/include")
81+
PRIVATE "${PROJECT_SOURCE_DIR}/src")
82+
83+
if(OTIO_FIND_RAPIDJSON)
84+
target_include_directories(opentimelineio
85+
PRIVATE "${RapidJSON_INCLUDE_DIRS}")
86+
else()
87+
target_include_directories(opentimelineio
88+
PRIVATE "${PROJECT_SOURCE_DIR}/src/deps/rapidjson/include")
89+
endif()
8490

8591

8692
target_link_libraries(opentimelineio

src/opentimelineio/serialization.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ class Encoder
7777
virtual void write_value(class TimeTransform const& value) = 0;
7878
virtual void write_value(struct SerializableObject::ReferenceId) = 0;
7979
virtual void write_value(IMATH_NAMESPACE::Box2d const&) = 0;
80+
virtual void write_value(IMATH_NAMESPACE::V2d const&) = 0;
8081

8182
protected:
8283
void _error(ErrorStatus const& error_status)
@@ -269,7 +270,7 @@ class CloningEncoder : public Encoder
269270
_store(std::any(value));
270271
}
271272

272-
void write_value(IMATH_NAMESPACE::V2d const& value)
273+
void write_value(IMATH_NAMESPACE::V2d const& value) override
273274
{
274275

275276
if (_result_object_policy == ResultObjectPolicy::OnlyAnyDictionary)

src/py-opentimelineio/opentimelineio/url_utils.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,11 @@ def filepath_from_url(urlstr):
7777
filepath = pathlib.PurePosixPath(filepath.drive, *filepath.parts[1:])
7878

7979
# If the specified index is a windows drive, then offset the path
80-
elif pathlib.PureWindowsPath(filepath.parts[1]).drive:
80+
elif (
81+
# relative paths may not have a parts[1]
82+
len(filepath.parts) > 1
83+
and pathlib.PureWindowsPath(filepath.parts[1]).drive
84+
):
8185
# Remove leading "/" if/when `request.url2pathname` yields
8286
# "/S:/path/file.ext"
8387
filepath = pathlib.PurePosixPath(*filepath.parts[1:])

tests/test_url_conversions.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,14 @@ def test_posix_urls(self):
7979
processed_url = otio.url_utils.filepath_from_url(url)
8080
self.assertEqual(processed_url, POSIX_PATH)
8181

82+
def test_relative_url(self):
83+
# see github issue #1817 - when a relative URL has only one name after
84+
# the "." (ie ./blah but not ./blah/blah)
85+
self.assertEqual(
86+
otio.url_utils.filepath_from_url(os.path.join(".", "docs")),
87+
"docs",
88+
)
89+
8290

8391
if __name__ == "__main__":
8492
unittest.main()

tests/test_v2d.py

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
11
# SPDX-License-Identifier: Apache-2.0
22
# Copyright Contributors to the OpenTimelineIO project
33

4-
import unittest
4+
import json
55
import sys
6+
import unittest
67

7-
import opentimelineio as otio
88
import opentimelineio.test_utils as otio_test_utils
99

10+
import opentimelineio as otio
11+
1012

1113
class V2dTests(unittest.TestCase, otio_test_utils.OTIOAssertions):
1214
def test_cons(self):
@@ -21,15 +23,9 @@ def test_cons(self):
2123
def test_str(self):
2224
v = otio.schema.V2d(1.0, 2.0)
2325

24-
self.assertMultiLineEqual(
25-
str(v),
26-
'V2d(1.0, 2.0)'
27-
)
26+
self.assertMultiLineEqual(str(v), "V2d(1.0, 2.0)")
2827

29-
self.assertMultiLineEqual(
30-
repr(v),
31-
'otio.schema.V2d(x=1.0, y=2.0)'
32-
)
28+
self.assertMultiLineEqual(repr(v), "otio.schema.V2d(x=1.0, y=2.0)")
3329

3430
def test_equality(self):
3531
v1 = otio.schema.V2d(1.0, 2.0)
@@ -104,6 +100,17 @@ def test_limits(self):
104100
self.assertEqual(otio.schema.V2d.baseTypeSmallest(), sys.float_info.min)
105101
self.assertEqual(otio.schema.V2d.baseTypeEpsilon(), sys.float_info.epsilon)
106102

103+
def test_json_serialization(self):
104+
serialized = otio.adapters.otio_json.write_to_string(otio.schema.V2d())
105+
json_v2d = json.loads(serialized)
106+
self.assertEqual(json_v2d["OTIO_SCHEMA"], "V2d.1")
107+
108+
def test_serialization_round_trip(self):
109+
v2d = otio.schema.V2d()
110+
serialized = otio.adapters.otio_json.write_to_string(v2d)
111+
deserialized = otio.adapters.otio_json.read_from_string(serialized)
112+
self.assertEqual(v2d, deserialized)
113+
107114

108-
if __name__ == '__main__':
115+
if __name__ == "__main__":
109116
unittest.main()

0 commit comments

Comments
 (0)