-
Notifications
You must be signed in to change notification settings - Fork 0
/
tasks.py
715 lines (549 loc) · 15.4 KB
/
tasks.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
# SPDX-License-Identifier: BSD-3-Clause
# Copyright Contributors to the OpenColorIO Project.
"""
Invoke - Tasks
==============
"""
from __future__ import annotations
import contextlib
import inspect
import os
from pathlib import Path
import requests
from invoke.exceptions import Failure
import opencolorio_config_aces
from opencolorio_config_aces.config.cg.generate.config import (
URL_EXPORT_TRANSFORMS_MAPPING_FILE_CG,
)
from opencolorio_config_aces.config.reference.generate.config import (
URL_EXPORT_TRANSFORMS_MAPPING_FILE_REFERENCE,
)
from opencolorio_config_aces.config.studio.generate.config import (
URL_EXPORT_TRANSFORMS_MAPPING_FILE_STUDIO,
)
from opencolorio_config_aces.utilities import google_sheet_title, message_box
if not hasattr(inspect, "getargspec"):
inspect.getargspec = inspect.getfullargspec # pyright: ignore
from invoke.context import Context
from invoke.tasks import task
__author__ = "OpenColorIO Contributors"
__copyright__ = "Copyright Contributors to the OpenColorIO Project."
__license__ = "New BSD License - https://opensource.org/licenses/BSD-3-Clause"
__maintainer__ = "OpenColorIO Contributors"
__email__ = "[email protected]"
__status__ = "Production"
__all__ = [
"APPLICATION_NAME",
"APPLICATION_VERSION",
"PYTHON_PACKAGE_NAME",
"GITHUB_REPOSITORY_NAME",
"PYPI_PACKAGE_NAME",
"ORG",
"CONTAINER",
"clean",
"quality",
"precommit",
"tests",
"preflight",
"docs",
"build_clf_transforms",
"build_aces_conversion_graph",
"build_config_common_tests",
"build_config_reference_analytical",
"update_mapping_file_reference",
"build_config_reference",
"update_mapping_file_cg",
"build_config_cg",
"build_config_studio",
"requirements",
"docker_build",
"docker_remove",
"run_in_container",
"docker_run_docs",
"docker_run_build_clf_transforms",
"docker_run_build_aces_conversion_graph",
"docker_run_build_config_common_tests",
"docker_run_build_config_reference_analytical",
"docker_run_update_mapping_file_reference",
"docker_run_build_config_reference",
"docker_run_update_mapping_file_cg",
"docker_run_build_config_cg",
"docker_run_update_mapping_file_studio",
"docker_run_build_config_studio",
]
APPLICATION_NAME = opencolorio_config_aces.__application_name__
APPLICATION_VERSION = opencolorio_config_aces.__version__
PYTHON_PACKAGE_NAME = opencolorio_config_aces.__name__
GITHUB_REPOSITORY_NAME = "OpenColorIO-Config-ACES"
PYPI_PACKAGE_NAME = "opencolorio-config-aces"
ORG = "aswf"
CONTAINER = PYPI_PACKAGE_NAME
@task
def clean(
ctx: Context,
docs: bool = True,
bytecode: bool = False,
mypy: bool = True,
pytest: bool = True,
):
"""
Clean the project.
Parameters
----------
ctx
Context.
docs
Whether to clean the *docs* directory.
bytecode
Whether to clean the bytecode files, e.g., *.pyc* files.
mypy
Whether to clean the *Mypy* cache directory.
pytest
Whether to clean the *Pytest* cache directory.
"""
message_box("Cleaning project...")
patterns = ["build", "*.egg-info", "dist"]
if docs:
patterns.append("docs/_build")
patterns.append("docs/generated")
if bytecode:
patterns.append("**/__pycache__")
patterns.append("**/*.pyc")
if mypy:
patterns.append(".mypy_cache")
if pytest:
patterns.append(".pytest_cache")
for pattern in patterns:
ctx.run(f"rm -rf {pattern}")
@task
def quality(
ctx: Context,
pyright: bool = True,
):
"""
Check the codebase with *Pyright* and lints various *restructuredText*
files with *rst-lint*.
Parameters
----------
ctx
Context.
pyright
Whether to check the codebase with *Pyright*.
"""
if pyright:
message_box('Checking codebase with "Pyright"...')
ctx.run("pyright --skipunannotated --level warning")
@task
def precommit(ctx: Context):
"""
Run the "pre-commit" hooks on the codebase.
Parameters
----------
ctx
Context.
"""
message_box('Running "pre-commit" hooks on the codebase...')
ctx.run("pre-commit run --all-files")
@task
def tests(ctx: Context):
"""
Run the unit tests with *Pytest*.
Parameters
----------
ctx
Context.
"""
message_box('Running "Pytest"...')
ctx.run(
"py.test "
"--disable-warnings "
"--doctest-modules "
f"--ignore={PYTHON_PACKAGE_NAME}/config/reference/aces-dev "
f"{PYTHON_PACKAGE_NAME}",
)
@task(quality, precommit, tests)
def preflight(ctx: Context): # noqa: ARG001
"""
Perform the preflight tasks, i.e., *formatting* and *quality*.
Parameters
----------
ctx
Context.
"""
message_box('Finishing "Preflight"...')
@task
def docs(ctx: Context, html: bool = True, pdf: bool = True):
"""
Build the documentation.
Parameters
----------
ctx
Context.
html
Whether to build the *HTML* documentation.
pdf
Whether to build the *PDF* documentation.
"""
with ctx.cd("docs"):
if html:
message_box('Building "HTML" documentation...')
ctx.run("make html")
if pdf:
message_box('Building "PDF" documentation...')
ctx.run("make latexpdf")
@task
def build_clf_transforms(ctx: Context):
"""
Build the *CLF* transforms.
Parameters
----------
ctx
Context.
"""
message_box('Building the "CLF" transform files...')
for family in [
"apple",
"arri",
"blackmagic",
"canon",
"itu",
"ocio",
"panasonic",
"red",
"sony",
]:
with ctx.cd(f"opencolorio_config_aces/clf/transforms/{family}"):
ctx.run("python generate.py")
@task
def build_aces_conversion_graph(ctx: Context):
"""
Build the *aces-dev* conversion graph.
Parameters
----------
ctx
Context.
"""
message_box('Building the ""aces-dev" conversion graph...')
with ctx.cd("opencolorio_config_aces/config/reference/discover"):
ctx.run("python graph.py")
@task
def build_config_common_tests(ctx: Context):
"""
Build the common tests *OpenColorIO* config(s).
Parameters
----------
ctx
Context.
"""
message_box('Building the common tests "OpenColorIO" config(s)...')
with ctx.cd("opencolorio_config_aces/config/generation"):
ctx.run("python common.py")
@task
def build_config_reference_analytical(ctx: Context):
"""
Build the *aces-dev* reference analytical *OpenColorIO* config.
Parameters
----------
ctx
Context.
"""
message_box('Building the "aces-dev" reference analytical "OpenColorIO" config...')
with ctx.cd("opencolorio_config_aces/config/reference/generate"):
ctx.run("python analytical.py")
@task
def update_mapping_file_reference(ctx: Context): # noqa: ARG001
"""
Update the *aces-dev* reference *OpenColorIO* config mapping file.
Parameters
----------
ctx
Context.
"""
message_box(
'Updating the "aces-dev" reference "OpenColorIO" config mapping file...'
)
title = google_sheet_title(URL_EXPORT_TRANSFORMS_MAPPING_FILE_REFERENCE)
directory = Path(
"opencolorio_config_aces/config/reference/generate/resources/"
).absolute()
for csv_file in directory.glob("*Mapping.csv"):
os.remove(csv_file)
filename = str(directory / f"{title} - Reference Config - Mapping.csv").replace(
'"', ""
)
with open(filename, "w") as csv_file:
csv_file.write(
requests.get(URL_EXPORT_TRANSFORMS_MAPPING_FILE_REFERENCE, timeout=60).text
)
@task
def build_config_reference(ctx: Context):
"""
Build the *aces-dev* reference *OpenColorIO* config.
Parameters
----------
ctx
Context.
"""
message_box('Building the "aces-dev" reference "OpenColorIO" config...')
with ctx.cd("opencolorio_config_aces/config/reference/generate"):
ctx.run("python config.py")
@task
def update_mapping_file_cg(ctx: Context): # noqa: ARG001
"""
Update the *ACES* Computer Graphics (CG) *OpenColorIO* mapping file.
Parameters
----------
ctx
Context.
"""
message_box(
'Updating the "ACES" Computer Graphics (CG) "OpenColorIO" config '
"mapping file..."
)
title = google_sheet_title(URL_EXPORT_TRANSFORMS_MAPPING_FILE_CG)
directory = Path("opencolorio_config_aces/config/cg/generate/resources/").absolute()
for csv_file in directory.glob("*Mapping.csv"):
os.remove(csv_file)
filename = str(directory / f"{title} - CG Config - Mapping.csv").replace('"', "")
with open(filename, "w") as csv_file:
csv_file.write(
requests.get(URL_EXPORT_TRANSFORMS_MAPPING_FILE_CG, timeout=60).text
)
@task
def build_config_cg(ctx: Context):
"""
Build the *ACES* Computer Graphics (CG) *OpenColorIO* config.
Parameters
----------
ctx
Context.
"""
message_box('Building the "ACES" Computer Graphics (CG) "OpenColorIO" config...')
with ctx.cd("opencolorio_config_aces/config/cg/generate"):
ctx.run("python config.py")
@task
def update_mapping_file_studio(ctx: Context): # noqa: ARG001
"""
Update the *ACES* Studio *OpenColorIO* mapping file.
Parameters
----------
ctx
Context.
"""
message_box('Updating the "ACES" Studio "OpenColorIO" config mapping file...')
title = google_sheet_title(URL_EXPORT_TRANSFORMS_MAPPING_FILE_STUDIO)
directory = Path(
"opencolorio_config_aces/config/studio/generate/resources/"
).absolute()
for csv_file in directory.glob("*Mapping.csv"):
os.remove(csv_file)
filename = str(directory / f"{title} - Studio Config - Mapping.csv").replace(
'"', ""
)
with open(filename, "w") as csv_file:
csv_file.write(
requests.get(URL_EXPORT_TRANSFORMS_MAPPING_FILE_STUDIO, timeout=60).text
)
@task
def build_config_studio(ctx: Context):
"""
Build the *ACES* Studio *OpenColorIO* config.
Parameters
----------
ctx
Context.
"""
message_box('Building the "ACES" Studio (CG) "OpenColorIO" config...')
with ctx.cd("opencolorio_config_aces/config/studio/generate"):
ctx.run("python config.py")
@task
def requirements(ctx: Context):
"""
Export the *requirements.txt* file.
Parameters
----------
ctx
Context.
"""
message_box('Exporting "requirements.txt" file...')
ctx.run(
"poetry export -f requirements.txt "
"--without-hashes "
# TODO: Reinstate "graphviz".
"--with dev,docs,optional "
"--output requirements.txt"
)
message_box('Exporting "docs/requirements.txt" file...')
ctx.run(
"poetry export -f requirements.txt "
"--without-hashes "
# TODO: Reinstate "graphviz".
"--with docs,optional "
"--output docs/requirements.txt"
)
@task(requirements)
def docker_build(ctx: Context):
"""
Build the *docker* image.
Parameters
----------
ctx
Context.
"""
message_box('Building "docker" image...')
ctx.run(
f"docker build -t {ORG}/{CONTAINER}:latest "
f"-t {ORG}/{CONTAINER}:v{APPLICATION_VERSION} ."
)
@task
def docker_remove(ctx: Context):
"""
Stop and remove the *docker* container.
Parameters
----------
ctx
Context.
"""
message_box('Stopping "docker" container...')
with contextlib.suppress(Failure):
ctx.run(f"docker stop {CONTAINER}")
message_box('Removing "docker" container...')
with contextlib.suppress(Failure):
ctx.run(f"docker rm {CONTAINER}")
def run_in_container(ctx: Context, command: str):
"""
Run given command in *docker* container.
Parameters
----------
ctx
Context.
command
Command to run in the *docker* container.
"""
message_box(f'Running "docker" container with "{command}" command...')
ctx.run(
f"docker run -v ${{PWD}}:/home/{ORG}/{GITHUB_REPOSITORY_NAME} "
f"{ORG}/{CONTAINER}:latest {command}"
)
@task
def docker_run_docs(ctx, html: bool = True, pdf: bool = True):
"""
Build the documentation in the *docker* container.
Parameters
----------
ctx
Context.
html
Whether to build the *HTML* documentation.
pdf
Whether to build the *PDF* documentation.
"""
command = "invoke docs"
if html is False:
command += " --no-html"
if pdf is False:
command += " --no-pdf"
run_in_container(ctx, command)
@task
def docker_run_build_clf_transforms(ctx: Context):
"""
Build the *CLF* transforms in the *docker* container.
Parameters
----------
ctx
Context.
"""
run_in_container(ctx, "invoke build-clfs")
@task
def docker_run_build_aces_conversion_graph(ctx: Context):
"""
Build the *aces-dev* conversion graph in the *docker* container.
Parameters
----------
ctx
Context.
"""
run_in_container(ctx, "invoke build-aces-conversion-graph")
@task
def docker_run_build_config_common_tests(ctx: Context):
"""
Build the common tests *OpenColorIO* config(s) in the *docker* container.
Parameters
----------
ctx
Context.
"""
run_in_container(ctx, "invoke build-config-common")
@task
def docker_run_build_config_reference_analytical(ctx: Context):
"""
Build the *aces-dev* reference analytical *OpenColorIO* config in the
*docker* container.
Parameters
----------
ctx
Context.
"""
run_in_container(ctx, "invoke build-config-reference-analytical")
def docker_run_update_mapping_file_reference(ctx: Context):
"""
Update the *aces-dev* reference *OpenColorIO* config mapping file in the
*docker* container.
Parameters
----------
ctx
Context.
"""
run_in_container(ctx, "invoke update-mapping-file-reference")
@task
def docker_run_build_config_reference(ctx: Context):
"""
Build the *aces-dev* reference *OpenColorIO* config in the *docker*
container.
Parameters
----------
ctx
Context.
"""
run_in_container(ctx, "invoke build-config-reference")
def docker_run_update_mapping_file_cg(ctx: Context):
"""
Update the *ACES* Computer Graphics (CG) *OpenColorIO* config mapping file
in the *docker* container.
Parameters
----------
ctx
Context.
"""
run_in_container(ctx, "invoke update-mapping-file-cg")
@task
def docker_run_build_config_cg(ctx: Context):
"""
Build the *ACES* Computer Graphics (CG) *OpenColorIO* config in the
*docker* container.
Parameters
----------
ctx
Context.
"""
run_in_container(ctx, "invoke build-config-cg")
def docker_run_update_mapping_file_studio(ctx: Context):
"""
Update the *ACES* Studio *OpenColorIO* config mapping file in the *docker*
container.
Parameters
----------
ctx
Context.
"""
run_in_container(ctx, "invoke update-mapping-file-studio")
@task
def docker_run_build_config_studio(ctx: Context):
"""
Build the *ACES* Studio *OpenColorIO* config in the *docker* container.
Parameters
----------
ctx
Context.
"""
run_in_container(ctx, "invoke build-config-studio")