Skip to content

Commit e3fc8a4

Browse files
authored
PR: Minor Improvements (#32)
* Update naming of various private attributes for better introspection. Signed-off-by: Thomas Mansencal <[email protected]> * Move "opencolorio_config_aces.clf.matrix_3x3_to_4x4" definition to "opencolorio_config_aces.utilities" sub-package. Signed-off-by: Thomas Mansencal <[email protected]> * Add "opencolorio_config_aces.utilities.multi_replace" definition. Signed-off-by: Thomas Mansencal <[email protected]>
1 parent 79e0706 commit e3fc8a4

File tree

14 files changed

+287
-239
lines changed

14 files changed

+287
-239
lines changed

docs/opencolorio_config_aces.utilities.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,3 +33,5 @@ Common
3333
is_string
3434
is_iterable
3535
git_describe
36+
matrix_3x3_to_4x4
37+
multi_replace

opencolorio_config_aces/clf/__init__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,10 @@
55
unclassify_clf_transforms, filter_clf_transforms,
66
print_clf_taxonomy)
77

8-
from .transforms import matrix_3x3_to_4x4, generate_clf
8+
from .transforms import generate_clf
99

1010
__all__ = [
1111
'discover_clf_transforms', 'classify_clf_transforms',
1212
'unclassify_clf_transforms', 'filter_clf_transforms', 'print_clf_taxonomy'
1313
]
14-
__all__ += ['matrix_3x3_to_4x4', 'generate_clf']
14+
__all__ += ['generate_clf']

opencolorio_config_aces/clf/discover/classify.py

Lines changed: 49 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -33,104 +33,104 @@
3333
__status__ = 'Production'
3434

3535
__all__ = [
36-
'CLF_URN', 'CLF_URN_SEPARATOR', 'CLF_ID_SEPARATOR', 'CLF_NAMESPACE',
37-
'CLF_TYPES', 'CLF_TRANSFORMS_ROOT', 'CLF_TRANSFORM_FAMILIES',
38-
'DEFAULT_CLF_TRANSFORM_GENUS', 'DEFAULT_CLF_TRANSFORM_FILTERERS',
39-
'DESCRIPTION_SUBSTITUTION_PATTERNS', 'clf_transform_relative_path',
40-
'CLFTransformID', 'CLFTransform', 'CLFTransformPair',
41-
'find_clf_transform_pairs', 'discover_clf_transforms',
36+
'URN_CLF', 'SEPARATOR_URN_CLF', 'SEPARATOR_ID_CLF', 'NAMESPACE_CLF',
37+
'TRANSFORM_TYPES_CLF', 'TRANSFORM_FAMILIES_CLF',
38+
'TRANSFORM_GENUS_DEFAULT_CLF', 'TRANSFORM_FILTERERS_DEFAULT_CLF',
39+
'PATTERNS_DESCRIPTION_CLF', 'ROOT_TRANSFORMS_CLF',
40+
'clf_transform_relative_path', 'CLFTransformID', 'CLFTransform',
41+
'CLFTransformPair', 'find_clf_transform_pairs', 'discover_clf_transforms',
4242
'classify_clf_transforms', 'unclassify_clf_transforms',
4343
'filter_clf_transforms', 'print_clf_taxonomy'
4444
]
4545

46-
CLF_URN = 'urn:aswf:ocio:transformId:v1.0'
46+
URN_CLF = 'urn:aswf:ocio:transformId:v1.0'
4747
"""
4848
*CLF* Uniform Resource Name (*URN*).
4949
50-
CLF_URN : unicode
50+
URN_CLF : unicode
5151
"""
5252

53-
CLF_URN_SEPARATOR = ':'
53+
SEPARATOR_URN_CLF = ':'
5454
"""
5555
*CLFtransformID* separator used to separate the *URN* and *ID* part of the
5656
*CLFtransformID*.
5757
58-
CLF_URN_SEPARATOR : unicode
58+
SEPARATOR_URN_CLF : unicode
5959
"""
6060

61-
CLF_ID_SEPARATOR = '.'
61+
SEPARATOR_ID_CLF = '.'
6262
"""
6363
*CLFtransformID* separator used to tokenize the *ID* part of the
6464
*CLFtransformID*.
6565
6666
urn:aswf:ocio:transformId:v1.0:ACES.OCIO.AP0_to_AP1-Gamma2pnt2.c1.v1
6767
|-------------URN------------|:|-----------------ID----------------|
6868
69-
CLF_ID_SEPARATOR : unicode
69+
SEPARATOR_ID_CLF : unicode
7070
"""
7171

72-
CLF_NAMESPACE = 'OCIO'
72+
NAMESPACE_CLF = 'OCIO'
7373
"""
7474
*ACES* namespace for the *OCIO* *CLF* transforms.
7575
76-
CLF_NAMESPACE : unicode
76+
NAMESPACE_CLF : unicode
7777
"""
7878

79-
CLF_TYPES = [
79+
TRANSFORM_TYPES_CLF = [
8080
'ACES',
8181
'Common',
8282
]
8383
"""
8484
*CLF* transform types.
8585
86-
CLF_TYPES : list
86+
TRANSFORM_TYPES_CLF : list
8787
"""
8888

89-
CLF_TRANSFORMS_ROOT = os.path.normpath(
90-
os.environ.get(
91-
'OPENCOLORIO_CONFIG_ACES__CLF_TRANSFORMS_ROOT',
92-
os.path.join(
93-
os.path.dirname(__file__), '..', 'transforms', 'builtins')))
89+
TRANSFORM_FAMILIES_CLF = {'aces': 'aces'}
9490
"""
95-
*CLF* transforms root directory, default to the version controlled
96-
sub-module repository. It can be defined by setting the
97-
`OPENCOLORIO_CONFIG_ACES__CLF_TRANSFORMS_ROOT` environment variable with
98-
the local 'transforms/clf' directory.
91+
*CLF* transform families mapping the *CLF* transform directories to family
92+
names.
9993
100-
CLF_TRANSFORMS_ROOT : unicode
94+
TRANSFORM_FAMILIES_CLF : dict
10195
"""
10296

103-
CLF_TRANSFORM_FAMILIES = {'aces': 'aces'}
97+
TRANSFORM_GENUS_DEFAULT_CLF = 'undefined'
10498
"""
105-
*CLF* transform families mapping the *CLF* transform directories to family
106-
names.
99+
*CLF* transform default genus, i.e. *undefined*.
107100
108-
CLF_TRANSFORM_FAMILIES : dict
101+
TRANSFORM_GENUS_DEFAULT_CLF : unicode
109102
"""
110103

111-
DEFAULT_CLF_TRANSFORM_GENUS = 'undefined'
104+
TRANSFORM_FILTERERS_DEFAULT_CLF = []
112105
"""
113-
*CLF* transform default genus, i.e. *undefined*.
106+
Default list of *CLF* transform filterers.
114107
115-
DEFAULT_CLF_TRANSFORM_GENUS : unicode
108+
TRANSFORM_FILTERERS_DEFAULT_CLF : list
116109
"""
117110

118-
DESCRIPTION_SUBSTITUTION_PATTERNS = {}
111+
PATTERNS_DESCRIPTION_CLF = {}
119112
"""
120113
*CLF* transform description substitution patterns.
121114
122-
DESCRIPTION_SUBSTITUTION_PATTERNS : dict
115+
PATTERNS_DESCRIPTION_CLF : dict
123116
"""
124117

125-
DEFAULT_CLF_TRANSFORM_FILTERERS = []
118+
ROOT_TRANSFORMS_CLF = os.path.normpath(
119+
os.environ.get(
120+
'OPENCOLORIO_CONFIG_ACES__CLF_TRANSFORMS_ROOT',
121+
os.path.join(
122+
os.path.dirname(__file__), '..', 'transforms', 'builtins')))
126123
"""
127-
Default list of *CLF* transform filterers.
124+
*CLF* transforms root directory, default to the version controlled
125+
sub-module repository. It can be defined by setting the
126+
`OPENCOLORIO_CONFIG_ACES__CLF_TRANSFORMS_ROOT` environment variable with
127+
the local 'transforms/clf' directory.
128128
129-
DEFAULT_CLF_TRANSFORM_FILTERERS : list
129+
ROOT_TRANSFORMS_CLF : unicode
130130
"""
131131

132132

133-
def clf_transform_relative_path(path, root_directory=CLF_TRANSFORMS_ROOT):
133+
def clf_transform_relative_path(path, root_directory=ROOT_TRANSFORMS_CLF):
134134
"""
135135
Helper definition returning the relative path from given *CLF* transform to
136136
*CLF* transforms root directory.
@@ -457,11 +457,11 @@ def _parse(self):
457457

458458
clf_transform_id = self._clf_transform_id
459459

460-
self._urn, components = clf_transform_id.rsplit(CLF_URN_SEPARATOR, 1)
461-
components = components.split(CLF_ID_SEPARATOR)
460+
self._urn, components = clf_transform_id.rsplit(SEPARATOR_URN_CLF, 1)
461+
components = components.split(SEPARATOR_ID_CLF)
462462
self._type, components = components[0], components[1:]
463463

464-
assert self._urn == CLF_URN, (
464+
assert self._urn == URN_CLF, (
465465
f'{self._clf_transform_id} URN {self._urn} is invalid!')
466466

467467
assert len(components) in (4, 5), (
@@ -475,7 +475,7 @@ def _parse(self):
475475
self._minor_version_number,
476476
self._patch_version_number) = components
477477

478-
assert self._type in CLF_TYPES, (
478+
assert self._type in TRANSFORM_TYPES_CLF, (
479479
f'{self._clf_transform_id} type {self._type} is invalid!')
480480

481481
if self._name is not None:
@@ -647,7 +647,7 @@ def family(self):
647647
Getter and setter property for the *CLF* transform family, e.g.
648648
*aces*, a value in
649649
:attr:`opencolorio_config_aces.clf.reference.\
650-
CLF_TRANSFORM_FAMILIES` attribute dictionary.
650+
TRANSFORM_FAMILIES_CLF` attribute dictionary.
651651
652652
Parameters
653653
----------
@@ -986,7 +986,7 @@ def stem(path):
986986
return clf_transform_pairs
987987

988988

989-
def discover_clf_transforms(root_directory=CLF_TRANSFORMS_ROOT):
989+
def discover_clf_transforms(root_directory=ROOT_TRANSFORMS_CLF):
990990
"""
991991
Discovers the *CLF* transform paths in given root directory: The given
992992
directory is traversed and the `*.clf` files are collected.
@@ -1090,11 +1090,11 @@ def classify_clf_transforms(unclassified_clf_transforms):
10901090
for directory, clf_transforms in unclassified_clf_transforms.items():
10911091
sub_directory = directory.replace(f'{root_directory}{os.sep}', '')
10921092
family, *genus = [
1093-
CLF_TRANSFORM_FAMILIES.get(part, part)
1093+
TRANSFORM_FAMILIES_CLF.get(part, part)
10941094
for part in sub_directory.split(os.sep)
10951095
]
10961096

1097-
genus = DEFAULT_CLF_TRANSFORM_GENUS if not genus else '/'.join(genus)
1097+
genus = TRANSFORM_GENUS_DEFAULT_CLF if not genus else '/'.join(genus)
10981098

10991099
for basename, pairs in find_clf_transform_pairs(
11001100
clf_transforms).items():
@@ -1208,7 +1208,7 @@ def filter_clf_transforms(clf_transforms, filterers=None):
12081208
"""
12091209

12101210
if filterers is None:
1211-
filterers = DEFAULT_CLF_TRANSFORM_FILTERERS
1211+
filterers = TRANSFORM_FILTERERS_DEFAULT_CLF
12121212

12131213
if isinstance(clf_transforms, Mapping):
12141214
clf_transforms = unclassify_clf_transforms(clf_transforms)
@@ -1231,7 +1231,7 @@ def print_clf_taxonomy():
12311231
12321232
- The *CLF* transforms are discovered by traversing the directory defined
12331233
by the :attr:`opencolorio_config_aces.clf.\
1234-
reference.CLF_TRANSFORMS_ROOT` attribute using the
1234+
reference.ROOT_TRANSFORMS_CLF` attribute using the
12351235
:func:`opencolorio_config_aces.discover_clf_transforms` definition.
12361236
- The *CLF* transforms are classified by *family* e.g. *aces*, and
12371237
*genus* e.g. *undefined* using the
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# SPDX-License-Identifier: BSD-3-Clause
22
# Copyright Contributors to the OpenColorIO Project.
33

4-
from .common import matrix_3x3_to_4x4, generate_clf
4+
from .common import generate_clf
55

6-
__all__ = ['matrix_3x3_to_4x4', 'generate_clf']
6+
__all__ = ['generate_clf']

opencolorio_config_aces/clf/transforms/aces.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,9 @@
1111
import logging
1212
from pathlib import Path
1313

14-
from opencolorio_config_aces.clf import generate_clf, matrix_3x3_to_4x4
14+
from opencolorio_config_aces.clf import generate_clf
1515
from opencolorio_config_aces.config.generation import transform_factory
16-
from opencolorio_config_aces.utilities import required
16+
from opencolorio_config_aces.utilities import matrix_3x3_to_4x4, required
1717

1818
__author__ = 'OpenColorIO Contributors'
1919
__copyright__ = 'Copyright Contributors to the OpenColorIO Project.'
@@ -159,7 +159,7 @@ def generate_clf_aces(directory):
159159
logging.getLogger().setLevel(logging.INFO)
160160

161161
build_directory = os.path.join(
162-
opencolorio_config_aces.clf.discover.classify.CLF_TRANSFORMS_ROOT,
162+
opencolorio_config_aces.clf.discover.classify.ROOT_TRANSFORMS_CLF,
163163
'aces')
164164

165165
if os.path.exists(build_directory):

opencolorio_config_aces/clf/transforms/common.py

Lines changed: 2 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -25,20 +25,7 @@
2525
__email__ = '[email protected]'
2626
__status__ = 'Production'
2727

28-
__all__ = ['matrix_3x3_to_4x4', 'generate_clf', 'generate_clf_common']
29-
30-
31-
def matrix_3x3_to_4x4(M):
32-
"""
33-
Converts given 3x3 matrix :math:`M` to a raveled 4x4 matrix.
34-
"""
35-
36-
import numpy as np
37-
38-
M_I = np.identity(4)
39-
M_I[:3, :3] = M
40-
41-
return np.ravel(M_I).tolist()
28+
__all__ = ['generate_clf', 'generate_clf_common']
4229

4330

4431
@required('OpenColorIO')
@@ -176,7 +163,7 @@ def generate_clf_common(directory):
176163
description='Conversion from sRGB gamut to ACES2065-1 gamut.')
177164

178165
build_directory = os.path.join(
179-
opencolorio_config_aces.clf.discover.classify.CLF_TRANSFORMS_ROOT,
166+
opencolorio_config_aces.clf.discover.classify.ROOT_TRANSFORMS_CLF,
180167
'common')
181168

182169
if os.path.exists(build_directory):

opencolorio_config_aces/config/cg/generate/config.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,11 +34,11 @@
3434
__status__ = 'Production'
3535

3636
__all__ = [
37-
'ACES_CONFIG_CG_MAPPING_FILE_PATH', 'clf_transform_to_description',
37+
'PATH_TRANSFORMS_MAPPING_FILE_CG', 'clf_transform_to_description',
3838
'clf_transform_to_colorspace', 'generate_config_cg'
3939
]
4040

41-
ACES_CONFIG_CG_MAPPING_FILE_PATH = (
41+
PATH_TRANSFORMS_MAPPING_FILE_CG = (
4242
Path(__file__).parents[0] / 'resources' /
4343
'OpenColorIO-Config-ACES _CG_ Transforms - CG Config - Mapping.csv')
4444
"""
@@ -146,7 +146,7 @@ def generate_config_cg(
146146
config_name=None,
147147
validate=True,
148148
describe=ColorspaceDescriptionStyle.SHORT_UNION,
149-
config_mapping_file_path=ACES_CONFIG_CG_MAPPING_FILE_PATH,
149+
config_mapping_file_path=PATH_TRANSFORMS_MAPPING_FILE_CG,
150150
additional_data=False):
151151
"""
152152
Generates the *ACES* Computer Graphics (CG) *OpenColorIO* config.

opencolorio_config_aces/config/generation/common.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,18 +37,18 @@
3737
__status__ = 'Production'
3838

3939
__all__ = [
40-
'LOG_ALLOCATION_VARS', 'produce_transform', 'transform_factory',
40+
'ALLOCATION_VARS_LOG', 'produce_transform', 'transform_factory',
4141
'group_transform_factory', 'colorspace_factory', 'named_transform_factory',
4242
'view_transform_factory', 'look_factory', 'ConfigData',
4343
'deserialize_config_data', 'serialize_config_data', 'validate_config',
4444
'generate_config'
4545
]
4646

47-
LOG_ALLOCATION_VARS = (-8, 5, 2**-8)
47+
ALLOCATION_VARS_LOG = (-8, 5, 2**-8)
4848
"""
4949
Allocation variables for logarithmic data representation.
5050
51-
LOG_ALLOCATION_VARS : tuple
51+
ALLOCATION_VARS_LOG : tuple
5252
"""
5353

5454

0 commit comments

Comments
 (0)