Skip to content

Commit 215a0bf

Browse files
KelSolaarmichdolan
andauthored
Made "jsonpickle" an optional dependency. (#29)
Closes #28. Signed-off-by: Thomas Mansencal <[email protected]> Co-authored-by: Michael Dolan <[email protected]>
1 parent 8b84503 commit 215a0bf

File tree

6 files changed

+56
-17
lines changed

6 files changed

+56
-17
lines changed

.github/workflows/continuous-integration.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ jobs:
3535
shell: bash
3636
- name: Install Package Dependencies
3737
run: |
38-
poetry install --extras "graph"
38+
poetry install --extras "optional"
3939
shell: bash
4040
- name: Lint with flake8
4141
run: |

docs/opencolorio_config_aces.utilities.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ Common
2525
vivified_to_dict
2626
message_box
2727
is_colour_installed
28+
is_jsonpickle_installed
2829
is_networkx_installed
2930
is_opencolorio_installed
3031
REQUIREMENTS_TO_CALLABLE

opencolorio_config_aces/config/generation/common.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919
- :func:`opencolorio_config_aces.generate_config`
2020
"""
2121

22-
import jsonpickle
2322
import logging
2423
import re
2524
from collections import OrderedDict
@@ -498,6 +497,7 @@ class ConfigData:
498497
default_view_transform: str = field(default_factory=str)
499498

500499

500+
@required('jsonpickle')
501501
def deserialize_config_data(path):
502502
"""
503503
Deserializes the *JSON* *OpenColorIO* config data container at given path.
@@ -513,11 +513,14 @@ def deserialize_config_data(path):
513513
Deserialized *JSON* *OpenColorIO* config data container.
514514
"""
515515

516+
import jsonpickle
517+
516518
with open(path) as config_json:
517519
return ConfigData(**jsonpickle.decode(config_json.read()))
518520

519521

520522
# TODO: Implement schema verification support for serialized data.
523+
@required('jsonpickle')
521524
def serialize_config_data(data, path):
522525
"""
523526
Serializes the *OpenColorIO* config data container as a *JSON* file.
@@ -530,6 +533,8 @@ def serialize_config_data(data, path):
530533
*JSON* file path.
531534
"""
532535

536+
import jsonpickle
537+
533538
with open(path, 'w') as config_json:
534539
config_json.write(jsonpickle.encode(asdict(data), indent=2))
535540

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
11
# SPDX-License-Identifier: BSD-3-Clause
22
# Copyright Contributors to the OpenColorIO Project.
33

4-
from .common import (DocstringDict, first_item, common_ancestor,
5-
paths_common_ancestor, vivification, vivified_to_dict,
6-
message_box, is_colour_installed, is_networkx_installed,
7-
is_opencolorio_installed, REQUIREMENTS_TO_CALLABLE,
8-
required, is_string, is_iterable, git_describe)
4+
from .common import (
5+
DocstringDict, first_item, common_ancestor, paths_common_ancestor,
6+
vivification, vivified_to_dict, message_box, is_colour_installed,
7+
is_jsonpickle_installed, is_networkx_installed, is_opencolorio_installed,
8+
REQUIREMENTS_TO_CALLABLE, required, is_string, is_iterable, git_describe)
99

1010
__all__ = [
1111
'DocstringDict', 'first_item', 'common_ancestor', 'paths_common_ancestor',
1212
'vivification', 'vivified_to_dict', 'message_box', 'is_colour_installed',
13-
'is_networkx_installed', 'is_opencolorio_installed',
14-
'REQUIREMENTS_TO_CALLABLE', 'required', 'is_string', 'is_iterable',
15-
'git_describe'
13+
'is_jsonpickle_installed', 'is_networkx_installed',
14+
'is_opencolorio_installed', 'REQUIREMENTS_TO_CALLABLE', 'required',
15+
'is_string', 'is_iterable', 'git_describe'
1616
]

opencolorio_config_aces/utilities/common.py

Lines changed: 38 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,9 @@
2424
__all__ = [
2525
'DocstringDict', 'first_item', 'common_ancestor', 'paths_common_ancestor',
2626
'vivification', 'vivified_to_dict', 'message_box', 'is_colour_installed',
27-
'is_networkx_installed', 'is_opencolorio_installed',
28-
'REQUIREMENTS_TO_CALLABLE', 'required', 'is_string', 'is_iterable',
29-
'git_describe'
27+
'is_jsonpickle_installed', 'is_networkx_installed',
28+
'is_opencolorio_installed', 'REQUIREMENTS_TO_CALLABLE', 'required',
29+
'is_string', 'is_iterable', 'git_describe'
3030
]
3131

3232

@@ -285,6 +285,38 @@ def is_colour_installed(raise_exception=False):
285285
return False
286286

287287

288+
def is_jsonpickle_installed(raise_exception=False):
289+
"""
290+
Returns if *jsonpickle* is installed and available.
291+
292+
Parameters
293+
----------
294+
raise_exception : bool
295+
Raise exception if *jsonpickle* is unavailable.
296+
297+
Returns
298+
-------
299+
bool
300+
Is *jsonpickle* installed.
301+
302+
Raises
303+
------
304+
ImportError
305+
If *jsonpickle* is not installed.
306+
"""
307+
308+
try: # pragma: no cover
309+
import jsonpickle # noqa
310+
311+
return True
312+
except ImportError as error: # pragma: no cover
313+
if raise_exception:
314+
raise ImportError(
315+
('"jsonpickle" related API features, e.g. serialization, '
316+
'are not available: "{0}".').format(error))
317+
return False
318+
319+
288320
def is_networkx_installed(raise_exception=False):
289321
"""
290322
Returns if *NetworkX* is installed and available.
@@ -351,6 +383,8 @@ def is_opencolorio_installed(raise_exception=False):
351383
REQUIREMENTS_TO_CALLABLE = DocstringDict({
352384
'Colour':
353385
is_colour_installed,
386+
'jsonpickle':
387+
is_jsonpickle_installed,
354388
'NetworkX':
355389
is_networkx_installed,
356390
'OpenColorIO':
@@ -360,7 +394,7 @@ def is_opencolorio_installed(raise_exception=False):
360394
Mapping of requirements to their respective callables.
361395
362396
_REQUIREMENTS_TO_CALLABLE : CaseInsensitiveMapping
363-
**{'Colour', 'NetworkX', 'OpenImageIO'}**
397+
**{'Colour', 'jsonpickle', 'NetworkX', 'OpenImageIO'}**
364398
"""
365399

366400

pyproject.toml

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,13 @@ keywords = [
1919

2020
[tool.poetry.dependencies]
2121
python = "^3.7"
22-
jsonpickle = "^2.0.0"
2322

2423
colour-science = { version = "^0.3.16", optional = true }
2524
coverage = { version = "*", optional = true } # Development dependency.
2625
coveralls = { version = "*", optional = true } # Development dependency.
2726
flake8 = { version = "*", optional = true } # Development dependency.
2827
invoke = { version = "*", optional = true } # Development dependency.
28+
jsonpickle = { version = "^2.0.0", optional = true }
2929
networkx = { version = "*", optional = true }
3030
nose = { version = "*", optional = true } # Development dependency.
3131
pre-commit = { version = "*", optional = true } # Development dependency.
@@ -66,8 +66,7 @@ development = [
6666
"twine",
6767
"yapf"
6868
]
69-
colour = [ "colour-science" ]
70-
graph = [ "networkx" ]
69+
optional = [ "colour-science", "jsonpickle", "networkx" ]
7170
graphviz = [ "pygraphviz" ]
7271

7372
[build-system]

0 commit comments

Comments
 (0)