Skip to content

Commit 03cb778

Browse files
hodoulpremia
andauthored
Python copy support (#1575) (#1589)
* Add deepcopy support for object with createEditableCopy method Signed-off-by: Rémi Achard <[email protected]> * Minor fixes Signed-off-by: Rémi Achard <[email protected]> * Removing python shallow copy method Signed-off-by: Rémi Achard <[email protected]> * Update comment and formating Signed-off-by: Rémi Achard <[email protected]> * Testing COnfig FileRules deepCopy Signed-off-by: Rémi Achard <[email protected]> * Add comment for ConfigTest Signed-off-by: Rémi Achard <[email protected]> Co-authored-by: Patrick Hodoul <[email protected]> Co-authored-by: Rémi Achard <[email protected]>
1 parent bb28982 commit 03cb778

23 files changed

+349
-16
lines changed

include/OpenColorIO/OpenColorIO.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1331,7 +1331,7 @@ extern OCIOEXPORT std::ostream & operator<< (std::ostream &, const FileRules &);
13311331
* ViewingRules
13321332
*
13331333
* Viewing Rules allow config authors to filter the list of views an application should offer
1334-
* based on the color space of an image. For example, a config may define a large number of
1334+
* based on the color space of an image. For example, a config may define a large number of
13351335
* views but not all of them may be appropriate for use with all color spaces. E.g., some views
13361336
* may be intended for use with scene-linear color space encodings and others with video color
13371337
* space encodings.

src/bindings/python/PyBaker.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,12 @@ Each item is a tuple containing format name and format extension.
7272
"shaperSize"_a = DEFAULT->getShaperSize(),
7373
DOC(Baker, Create))
7474

75+
.def("__deepcopy__", [](const ConstBakerRcPtr & self, py::dict)
76+
{
77+
return self->createEditableCopy();
78+
},
79+
"memo"_a)
80+
7581
.def_static("getFormats", []()
7682
{
7783
return FormatIterator(nullptr);

src/bindings/python/PyColorSpace.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,12 @@ void bindPyColorSpace(py::module & m)
152152
"categories"_a = getCategoriesStdVec(DEFAULT),
153153
DOC(ColorSpace, Create, 2))
154154

155+
.def("__deepcopy__", [](const ConstColorSpaceRcPtr & self, py::dict)
156+
{
157+
return self->createEditableCopy();
158+
},
159+
"memo"_a)
160+
155161
.def("getName", &ColorSpace::getName,
156162
DOC(ColorSpace, getName))
157163
.def("setName", &ColorSpace::setName, "name"_a.none(false),

src/bindings/python/PyColorSpaceSet.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,12 @@ void bindPyColorSpaceSet(py::module & m)
4040
.def(py::init(&ColorSpaceSet::Create),
4141
DOC(ColorSpaceSet, Create))
4242

43+
.def("__deepcopy__", [](const ConstColorSpaceSetRcPtr & self, py::dict)
44+
{
45+
return self->createEditableCopy();
46+
},
47+
"memo"_a)
48+
4349
.def("__eq__", &ColorSpaceSet::operator==, py::is_operator(),
4450
DOC(ColorSpaceSet, operator, eq))
4551
.def("__ne__", &ColorSpaceSet::operator!=, py::is_operator(),

src/bindings/python/PyConfig.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,12 @@ void bindPyConfig(py::module & m)
178178
.def(py::init(&Config::Create),
179179
DOC(Config, Create))
180180

181+
.def("__deepcopy__", [](const ConstConfigRcPtr & self, py::dict)
182+
{
183+
return self->createEditableCopy();
184+
},
185+
"memo"_a)
186+
181187
.def_static("CreateRaw", &Config::CreateRaw,
182188
DOC(Config, CreateRaw))
183189
.def_static("CreateFromEnv", &Config::CreateFromEnv,

src/bindings/python/PyContext.cpp

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,13 @@ void bindPyContext(py::module & m)
9999
"searchPaths"_a = getSearchPathsStdVec(DEFAULT),
100100
"stringVars"_a = getStringVarsStdMap(DEFAULT),
101101
"environmentMode"_a = DEFAULT->getEnvironmentMode(),
102-
DOC(Context, Create))
102+
DOC(Context, Create))
103+
104+
.def("__deepcopy__", [](const ConstContextRcPtr & self, py::dict)
105+
{
106+
return self->createEditableCopy();
107+
},
108+
"memo"_a)
103109

104110
.def("__iter__", [](ContextRcPtr & self)
105111
{

src/bindings/python/PyFileRules.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,12 @@ void bindPyFileRules(py::module & m)
1616
.def(py::init(&FileRules::Create),
1717
DOC(FileRules, Create))
1818

19+
.def("__deepcopy__", [](const ConstFileRulesRcPtr & self, py::dict)
20+
{
21+
return self->createEditableCopy();
22+
},
23+
"memo"_a)
24+
1925
.def("getNumEntries", &FileRules::getNumEntries,
2026
DOC(FileRules, getNumEntries))
2127
.def("getIndexForRule", &FileRules::getIndexForRule, "ruleName"_a,

src/bindings/python/PyLook.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,12 @@ void bindPyLook(py::module & m)
3838
"description"_a = DEFAULT->getDescription(),
3939
DOC(Look, Create))
4040

41+
.def("__deepcopy__", [](const ConstLookRcPtr & self, py::dict)
42+
{
43+
return self->createEditableCopy();
44+
},
45+
"memo"_a)
46+
4147
.def("getName", &Look::getName,
4248
DOC(Look, getName))
4349
.def("setName", &Look::setName, "name"_a.none(false),

src/bindings/python/PyNamedTransform.cpp

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,12 @@ void bindPyNamedTransform(py::module & m)
118118
"categories"_a = getCategoriesStdVec(DEFAULT),
119119
DOC(NamedTransform, Create))
120120

121+
.def("__deepcopy__", [](const ConstNamedTransformRcPtr & self, py::dict)
122+
{
123+
return self->createEditableCopy();
124+
},
125+
"memo"_a)
126+
121127
.def("getName", &NamedTransform::getName,
122128
DOC(NamedTransform, getName))
123129
.def("setName", &NamedTransform::setName, "name"_a.none(false),
@@ -145,7 +151,7 @@ void bindPyNamedTransform(py::module & m)
145151
DOC(NamedTransform, setDescription))
146152
.def("getEncoding", &NamedTransform::getEncoding,
147153
DOC(NamedTransform, getEncoding))
148-
.def("setEncoding", &NamedTransform::setEncoding, "encodig"_a.none(false),
154+
.def("setEncoding", &NamedTransform::setEncoding, "encoding"_a.none(false),
149155
DOC(NamedTransform, setEncoding))
150156

151157
// Transform

src/bindings/python/PyTransform.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,12 @@ void bindPyTransform(py::module & m)
1313
py::class_<Transform, TransformRcPtr>(
1414
m.attr("Transform"))
1515

16+
.def("__deepcopy__", [](const ConstTransformRcPtr & self, py::dict)
17+
{
18+
return self->createEditableCopy();
19+
},
20+
"memo"_a)
21+
1622
.def("validate", &Transform::validate,
1723
DOC(Transform, validate))
1824
.def("getTransformType", &Transform::getTransformType,

0 commit comments

Comments
 (0)