Skip to content

Commit 484a658

Browse files
committed
Use colour checks configuration.
1 parent 0636781 commit 484a658

7 files changed

+126
-149
lines changed

app.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
__major_version__ = "0"
2121
__minor_version__ = "2"
2222
__change_version__ = "7"
23-
__version__ = ".".join((__major_version__, __minor_version__, __change_version__))
23+
__version__ = f"{__major_version__}.{__minor_version__}.{__change_version__}"
2424

2525
__all__ = ["SERVER", "SERVER_URL", "APP"]
2626

@@ -36,9 +36,9 @@
3636

3737
APP: dash.Dash = dash.Dash(
3838
__application_name__,
39-
external_scripts=os.environ.get("COLOUR_DASH_JS", "").split(","),
40-
external_stylesheets=os.environ.get("COLOUR_DASH_CSS", "").split(","),
41-
server=SERVER, # pyright: ignore
39+
external_scripts=os.environ.get("COLOUR_DASH_JS", "").split(","), # pyright: ignore
40+
external_stylesheets=os.environ.get("COLOUR_DASH_CSS", "").split(","), # pyright: ignore
41+
server=SERVER,
4242
)
4343
"""
4444
*Dash* app.

apps/common.py

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,17 @@
33
======
44
"""
55

6+
from __future__ import annotations
7+
8+
import typing
69
from io import StringIO
710

811
from colour.adaptation import CHROMATIC_ADAPTATION_TRANSFORMS
912
from colour.colorimetry import CCS_ILLUMINANTS
10-
from colour.hints import ArrayLike, Dict, Iterable, List
13+
14+
if typing.TYPE_CHECKING:
15+
from colour.hints import ArrayLike, Dict, Iterable, List, NDArrayFloat
16+
1117
from colour.io import LUTOperatorMatrix, write_LUT_SonySPImtx
1218
from colour.models import RGB_COLOURSPACES
1319
from colour.utilities import as_float_array
@@ -126,8 +132,8 @@ def spimtx_format_matrix(M: ArrayLike, decimals: int = 10) -> str:
126132

127133
write_LUT_SonySPImtx(
128134
LUTOperatorMatrix(M),
129-
string,
130-
decimals, # pyright: ignore
135+
string, # pyright: ignore
136+
decimals,
131137
)
132138

133139
return string.getvalue()
@@ -155,7 +161,7 @@ def spimtx_format_matrix(M: ArrayLike, decimals: int = 10) -> str:
155161
"""
156162

157163

158-
def matrix_3x3_to_4x4(M):
164+
def matrix_3x3_to_4x4(M: ArrayLike) -> NDArrayFloat:
159165
"""
160166
Convert given 3x3 matrix :math:`M` to a raveled 4x4 matrix.
161167

apps/rgb_colourspace_chromatically_adapted_primaries.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
===========================================================
44
"""
55

6+
from __future__ import annotations
7+
68
import sys
79
import urllib.parse
810
from contextlib import suppress
@@ -67,7 +69,7 @@
6769
"""
6870

6971

70-
def _uid(id_):
72+
def _uid(id_: str) -> str:
7173
"""
7274
Generate a unique id for given id by appending the application *UID*.
7375
"""
@@ -313,16 +315,14 @@ def value_from_query(value: str) -> str:
313315

314316
return STATE_DEFAULT[value.replace("-", "_")]
315317

316-
state = (
318+
return (
317319
value_from_query("colourspace"),
318320
value_from_query("illuminant"),
319321
value_from_query("chromatic-adaptation-transform"),
320322
value_from_query("formatter"),
321323
int(value_from_query("decimals")),
322324
)
323325

324-
return state
325-
326326

327327
@APP.callback(
328328
Output(_uid("url"), "search"),

apps/rgb_colourspace_transformation_matrix.py

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
=================================================
44
"""
55

6+
from __future__ import annotations
7+
68
import re
79
import sys
810
import urllib.parse
@@ -71,7 +73,7 @@
7173
"""
7274

7375

74-
def _uid(id_):
76+
def _uid(id_: str) -> str:
7577
"""
7678
Generate a unique id for given id by appending the application *UID*.
7779
"""
@@ -301,8 +303,7 @@ def slugify(string: str) -> str:
301303
pattern = r"\(|\)"
302304
string = re.sub(pattern, "", string)
303305
pattern = r"\s-\s|\s|-|\.|/"
304-
string = re.sub(pattern, "_", string)
305-
return string
306+
return re.sub(pattern, "_", string)
306307

307308
M_f = TEMPLATE_NUKE_NODE_COLORMATRIX.format(
308309
name=(
@@ -373,16 +374,14 @@ def value_from_query(value: str) -> str:
373374

374375
return STATE_DEFAULT[value.replace("-", "_")]
375376

376-
state = (
377+
return (
377378
value_from_query("input-colourspace"),
378379
value_from_query("output-colourspace"),
379380
value_from_query("chromatic-adaptation-transform"),
380381
value_from_query("formatter"),
381382
int(value_from_query("decimals")),
382383
)
383384

384-
return state
385-
386385

387386
@APP.callback(
388387
Output(_uid("url"), "search"),

index.py

Lines changed: 52 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,13 @@
33
=====
44
"""
55

6-
import dash
6+
from __future__ import annotations
7+
8+
import typing
9+
10+
if typing.TYPE_CHECKING:
11+
import dash
12+
713
from dash.dcc import Link, Location, Markdown
814
from dash.dependencies import Input, Output
915
from dash.html import H3, A, Div, P
@@ -25,7 +31,7 @@
2531

2632

2733
@APP.callback(Output("apps", "children"), [Input("url", "pathname")])
28-
def load_app(app: dash.Dash):
34+
def load_app(app: dash.Dash) -> Div:
2935
"""
3036
Load given app into the appropriate :class:`Div` class instance.
3137
@@ -42,50 +48,51 @@ def load_app(app: dash.Dash):
4248

4349
if app == app_1.APP_PATH:
4450
return app_1.LAYOUT
45-
elif app == app_2.APP_PATH:
51+
52+
if app == app_2.APP_PATH:
4653
return app_2.LAYOUT
47-
else:
48-
return Div(
49-
[
50-
P(
51-
[
52-
"Various colour science ",
53-
A(
54-
"Dash",
55-
href="https://dash.plot.ly/",
56-
target="_blank",
57-
),
58-
" apps built on top of \n",
59-
A(
60-
"Colour",
61-
href="https://github.com/colour-science/colour",
62-
target="_blank",
63-
),
64-
".",
65-
]
66-
),
67-
H3(
68-
[
69-
Link(
70-
app_1.APP_NAME,
71-
href=app_1.APP_PATH,
72-
className="app-link",
73-
)
74-
]
75-
),
76-
Markdown(app_1.APP_DESCRIPTION.replace("This app c", "C")),
77-
H3(
78-
[
79-
Link(
80-
app_2.APP_NAME,
81-
href=app_2.APP_PATH,
82-
className="app-link",
83-
)
84-
]
85-
),
86-
Markdown(app_2.APP_DESCRIPTION.replace("This app c", "C")),
87-
]
88-
)
54+
55+
return Div(
56+
[
57+
P(
58+
[
59+
"Various colour science ",
60+
A(
61+
"Dash",
62+
href="https://dash.plot.ly/",
63+
target="_blank",
64+
),
65+
" apps built on top of \n",
66+
A(
67+
"Colour",
68+
href="https://github.com/colour-science/colour",
69+
target="_blank",
70+
),
71+
".",
72+
]
73+
),
74+
H3(
75+
[
76+
Link(
77+
app_1.APP_NAME,
78+
href=app_1.APP_PATH,
79+
className="app-link",
80+
)
81+
]
82+
),
83+
Markdown(app_1.APP_DESCRIPTION.replace("This app c", "C")),
84+
H3(
85+
[
86+
Link(
87+
app_2.APP_NAME,
88+
href=app_2.APP_PATH,
89+
className="app-link",
90+
)
91+
]
92+
),
93+
Markdown(app_2.APP_DESCRIPTION.replace("This app c", "C")),
94+
]
95+
)
8996

9097

9198
if __name__ == "__main__":

pyproject.toml

Lines changed: 37 additions & 77 deletions
Original file line numberDiff line numberDiff line change
@@ -94,91 +94,51 @@ reportUnusedExpression = false
9494
[tool.ruff]
9595
target-version = "py310"
9696
line-length = 88
97-
select = [
98-
"A", # flake8-builtins
99-
"ARG", # flake8-unused-arguments
100-
# "ANN", # flake8-annotations
101-
"B", # flake8-bugbear
102-
# "BLE", # flake8-blind-except
103-
"C4", # flake8-comprehensions
104-
# "C90", # mccabe
105-
# "COM", # flake8-commas
106-
"DTZ", # flake8-datetimez
107-
"D", # pydocstyle
108-
"E", # pydocstyle
109-
# "ERA", # eradicate
110-
# "EM", # flake8-errmsg
111-
"EXE", # flake8-executable
112-
"F", # flake8
113-
# "FBT", # flake8-boolean-trap
114-
"G", # flake8-logging-format
115-
"I", # isort
116-
"ICN", # flake8-import-conventions
117-
"INP", # flake8-no-pep420
118-
"ISC", # flake8-implicit-str-concat
119-
"N", # pep8-naming
120-
# "PD", # pandas-vet
121-
"PIE", # flake8-pie
122-
"PGH", # pygrep-hooks
123-
"PL", # pylint
124-
# "PT", # flake8-pytest-style
125-
# "PTH", # flake8-use-pathlib [Enable]
126-
"Q", # flake8-quotes
127-
"RET", # flake8-return
128-
"RUF", # Ruff
129-
"S", # flake8-bandit
130-
"SIM", # flake8-simplify
131-
"T10", # flake8-debugger
132-
"T20", # flake8-print
133-
# "TCH", # flake8-type-checking
134-
"TID", # flake8-tidy-imports
135-
"TRY", # tryceratops
136-
"UP", # pyupgrade
137-
"W", # pydocstyle
138-
"YTT" # flake8-2020
139-
]
97+
select = ["ALL"]
14098
ignore = [
141-
"B008",
142-
"B905",
143-
"D104",
144-
"D200",
145-
"D202",
146-
"D205",
147-
"D301",
148-
"D400",
149-
"I001",
150-
"N801",
151-
"N802",
152-
"N803",
153-
"N806",
154-
"N813",
155-
"N815",
156-
"N816",
157-
"PGH003",
158-
"PIE804",
159-
"PLE0605",
160-
"PLR0911",
161-
"PLR0912",
162-
"PLR0913",
163-
"PLR0915",
164-
"PLR2004",
165-
"RET504",
166-
"RET505",
167-
"RET506",
168-
"RET507",
169-
"RET508",
170-
"RUF022",
171-
"TRY003",
172-
"TRY300",
173-
"UP038",
99+
"C", # Pylint - Convention
100+
"C90", # mccabe
101+
"COM", # flake8-commas
102+
"ERA", # eradicate
103+
"FBT", # flake8-boolean-trap
104+
"FIX", # flake8-fixme
105+
"PT", # flake8-pytest-style
106+
"PTH", # flake8-use-pathlib [Enable]
107+
"TD", # flake8-todos
108+
"ANN401", # Dynamically typed expressions (typing.Any) are disallowed in `**kwargs`
109+
"D200", # One-line docstring should fit on one line
110+
"D202", # No blank lines allowed after function docstring
111+
"D205", # 1 blank line required between summary line and description
112+
"D301", # Use `r"""` if any backslashes in a docstring
113+
"D400", # First line should end with a period
114+
"I001", # Import block is un-sorted or un-formatted
115+
"N801", # Class name `.*` should use CapWords convention
116+
"N802", # Function name `.*` should be lowercase
117+
"N803", # Argument name `.*` should be lowercase
118+
"N806", # Variable `.*` in function should be lowercase
119+
"N813", # Camelcase `.*` imported as lowercase `.*`
120+
"N815", # Variable `.*` in class scope should not be mixedCase
121+
"N816", # Variable `.*` in global scope should not be mixedCase
122+
"NPY002", # Replace legacy `np.random.random` call with `np.random.Generator`
123+
"PGH003", # Use specific rule codes when ignoring type issues
124+
"PLR0912", # Too many branches
125+
"PLR0913", # Too many arguments in function definition
126+
"PLR0915", # Too many statements
127+
"PLR2004", # Magic value used in comparison, consider replacing `.*` with a constant variable
128+
"PYI036", # Star-args in `.*` should be annotated with `object`
129+
"PYI051", # `Literal[".*"]` is redundant in a union with `str`
130+
"PYI056", # Calling `.append()` on `__all__` may not be supported by all type checkers (use `+=` instead)
131+
"RUF022", # [*] `__all__` is not sorted
132+
"TRY003", # Avoid specifying long messages outside the exception class
133+
"UP038", # Use `X | Y` in `isinstance` call instead of `(X, Y)`
174134
]
175135
typing-modules = ["colour.hints"]
176-
fixable = ["B", "C", "E", "F", "PIE", "RUF", "SIM", "UP", "W"]
177136

178137
[tool.ruff.pydocstyle]
179138
convention = "numpy"
180139

181140
[tool.ruff.per-file-ignores]
141+
"__init__.py" = ["D104"]
182142
"docs/*" = ["INP"]
183143
"app.py" = ["INP"]
184144
"index.py" = ["INP"]

0 commit comments

Comments
 (0)