Skip to content

Commit

Permalink
Use Ruff format.
Browse files Browse the repository at this point in the history
  • Loading branch information
KelSolaar committed Jan 30, 2024
1 parent 515df55 commit 951a175
Show file tree
Hide file tree
Showing 10 changed files with 22 additions and 56 deletions.
10 changes: 3 additions & 7 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -25,18 +25,14 @@ repos:
- id: flynt
args: [--verbose]
- repo: https://github.com/PyCQA/isort
rev: "5.12.0"
rev: "5.13.2"
hooks:
- id: isort
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: "v0.1.6"
rev: "v0.1.14"
hooks:
- id: ruff-format
- id: ruff
- repo: https://github.com/psf/black-pre-commit-mirror
rev: 23.11.0
hooks:
- id: black
language_version: python3.9
- repo: https://github.com/adamchainz/blacken-docs
rev: 1.16.0
hooks:
Expand Down
8 changes: 2 additions & 6 deletions colour_demosaicing/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,7 @@
__major_version__ = "0"
__minor_version__ = "2"
__change_version__ = "5"
__version__ = ".".join(
(__major_version__, __minor_version__, __change_version__)
)
__version__ = ".".join((__major_version__, __minor_version__, __change_version__))

try:
_version: str = (
Expand All @@ -73,9 +71,7 @@
except Exception:
_version: str = __version__

colour.utilities.ANCILLARY_COLOUR_SCIENCE_PACKAGES[ # pyright: ignore
"colour-demosaicing"
] = _version
colour.utilities.ANCILLARY_COLOUR_SCIENCE_PACKAGES["colour-demosaicing"] = _version # pyright: ignore

del _version

Expand Down
8 changes: 2 additions & 6 deletions colour_demosaicing/bayer/demosaicing/tests/test_bilinear.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,17 +46,13 @@ def test_demosaicing_CFA_Bayer_bilinear(self):
"""

for pattern in ("RGGB", "BGGR", "GRBG", "GBRG"):
CFA = os.path.join(
ROOT_RESOURCES_BAYER, f"Lighthouse_CFA_{pattern}.exr"
)
CFA = os.path.join(ROOT_RESOURCES_BAYER, f"Lighthouse_CFA_{pattern}.exr")
RGB = os.path.join(
ROOT_RESOURCES_BAYER, f"Lighthouse_Bilinear_{pattern}.exr"
)

np.testing.assert_allclose(
demosaicing_CFA_Bayer_bilinear(
read_image(str(CFA))[..., 0], pattern
),
demosaicing_CFA_Bayer_bilinear(read_image(str(CFA))[..., 0], pattern),
read_image(str(RGB)),
atol=TOLERANCE_ABSOLUTE_TESTS,
)
Expand Down
8 changes: 2 additions & 6 deletions colour_demosaicing/bayer/demosaicing/tests/test_malvar2004.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,17 +46,13 @@ def test_demosaicing_CFA_Bayer_Malvar2004(self):
"""

for pattern in ("RGGB", "BGGR", "GRBG", "GBRG"):
CFA = os.path.join(
ROOT_RESOURCES_BAYER, f"Lighthouse_CFA_{pattern}.exr"
)
CFA = os.path.join(ROOT_RESOURCES_BAYER, f"Lighthouse_CFA_{pattern}.exr")
RGB = os.path.join(
ROOT_RESOURCES_BAYER, f"Lighthouse_Malvar2004_{pattern}.exr"
)

np.testing.assert_allclose(
demosaicing_CFA_Bayer_Malvar2004(
read_image(str(CFA))[..., 0], pattern
),
demosaicing_CFA_Bayer_Malvar2004(read_image(str(CFA))[..., 0], pattern),
read_image(str(RGB)),
atol=TOLERANCE_ABSOLUTE_TESTS,
)
Expand Down
8 changes: 2 additions & 6 deletions colour_demosaicing/bayer/demosaicing/tests/test_menon2007.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,17 +46,13 @@ def test_demosaicing_CFA_Bayer_Menon2007(self):
"""

for pattern in ("RGGB", "BGGR", "GRBG", "GBRG"):
CFA = os.path.join(
ROOT_RESOURCES_BAYER, f"Lighthouse_CFA_{pattern}.exr"
)
CFA = os.path.join(ROOT_RESOURCES_BAYER, f"Lighthouse_CFA_{pattern}.exr")
RGB = os.path.join(
ROOT_RESOURCES_BAYER, f"Lighthouse_Menon2007_{pattern}.exr"
)

np.testing.assert_allclose(
demosaicing_CFA_Bayer_Menon2007(
read_image(str(CFA))[..., 0], pattern
),
demosaicing_CFA_Bayer_Menon2007(read_image(str(CFA))[..., 0], pattern),
read_image(str(RGB)),
atol=TOLERANCE_ABSOLUTE_TESTS,
)
Expand Down
8 changes: 2 additions & 6 deletions colour_demosaicing/bayer/tests/test_mosaicing.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,14 +45,10 @@ def test_mosaicing_CFA_Bayer(self):
definition.
"""

image = read_image(
str(os.path.join(ROOT_RESOURCES_BAYER, "Lighthouse.exr"))
)
image = read_image(str(os.path.join(ROOT_RESOURCES_BAYER, "Lighthouse.exr")))

for pattern in ("RGGB", "BGGR", "GRBG", "GBRG"):
CFA = os.path.join(
ROOT_RESOURCES_BAYER, f"Lighthouse_CFA_{pattern}.exr"
)
CFA = os.path.join(ROOT_RESOURCES_BAYER, f"Lighthouse_CFA_{pattern}.exr")
np.testing.assert_allclose(
mosaicing_CFA_Bayer(image, pattern),
read_image(str(CFA))[..., 0],
Expand Down
4 changes: 1 addition & 3 deletions docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,7 @@

import colour_demosaicing as package # noqa: E402

basename = re.sub(
"_(\\w)", lambda x: x.group(1).upper(), package.__name__.title()
)
basename = re.sub("_(\\w)", lambda x: x.group(1).upper(), package.__name__.title())

# -- General configuration ------------------------------------------------
extensions = [
Expand Down
3 changes: 3 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,9 @@ convention = "numpy"
"utilities/*" = ["EXE001", "INP"]
"utilities/unicode_to_ascii.py" = ["RUF001"]

[tool.ruff.format]
docstring-code-format = true

[build-system]
requires = [ "poetry_core>=1.0.0" ]
build-backend = "poetry.core.masonry.api"
17 changes: 4 additions & 13 deletions tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,9 +135,7 @@ def formatting(
message_box('Cleaning up "BibTeX" file...')
bibtex_path = BIBLIOGRAPHY_NAME
with open(bibtex_path) as bibtex_file:
entries = (
biblib.bib.Parser().parse(bibtex_file.read()).get_entries()
)
entries = biblib.bib.Parser().parse(bibtex_file.read()).get_entries()

for entry in sorted(entries.values(), key=lambda x: x.key):
with contextlib.suppress(KeyError):
Expand Down Expand Up @@ -267,9 +265,7 @@ def docs(ctx: Context, html: bool = True, pdf: bool = True):
Whether to build the *PDF* documentation.
"""

with ctx.prefix("export COLOUR_SCIENCE__DOCUMENTATION_BUILD=True"), ctx.cd(
"docs"
):
with ctx.prefix("export COLOUR_SCIENCE__DOCUMENTATION_BUILD=True"), ctx.cd("docs"):
if html:
message_box('Building "HTML" documentation...')
ctx.run("make html")
Expand Down Expand Up @@ -368,10 +364,7 @@ def virtualise(ctx: Context, tests: bool = True):
with ctx.cd(unique_name):
ctx.run("poetry install")
ctx.run("source $(poetry env info -p)/bin/activate")
ctx.run(
'python -c "import imageio;'
'imageio.plugins.freeimage.download()"'
)
ctx.run('python -c "import imageio;imageio.plugins.freeimage.download()"')
if tests:
ctx.run(
"poetry run pytest "
Expand Down Expand Up @@ -422,9 +415,7 @@ def tag(ctx: Context):
remote_tags = result.stdout.strip().split("\n") # pyright: ignore
tags = set()
for remote_tag in remote_tags:
tags.add(
remote_tag.split("refs/tags/")[1].replace("refs/tags/", "^{}")
)
tags.add(remote_tag.split("refs/tags/")[1].replace("refs/tags/", "^{}"))
version_tags = sorted(tags)
if f"v{version}" in version_tags:
raise RuntimeError(
Expand Down
4 changes: 1 addition & 3 deletions utilities/export_todo.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,7 @@
https://opensource.org/licenses/BSD-3-Clause
| `https://github.com/colour-science/colour-demosaicing \
<https://github.com/colour-science/colour-demosaicing>`__
"""[
1:
]
"""[1:]


def extract_todo_items(root_directory: str) -> dict:
Expand Down

0 comments on commit 951a175

Please sign in to comment.