Skip to content

Commit

Permalink
[pre-commit.ci] pre-commit autoupdate (#125)
Browse files Browse the repository at this point in the history
* [pre-commit.ci] pre-commit autoupdate

updates:
- [github.com/pre-commit/pre-commit-hooks: v4.5.0 → v4.6.0](pre-commit/pre-commit-hooks@v4.5.0...v4.6.0)
- [github.com/astral-sh/ruff-pre-commit: v0.3.5 → v0.5.0](astral-sh/ruff-pre-commit@v0.3.5...v0.5.0)

* use ruff.toml and lint

---------

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Co-authored-by: Çağtay Fabry <[email protected]>
  • Loading branch information
pre-commit-ci[bot] and CagtayFabry authored Jul 4, 2024
1 parent c8c343f commit 3cc86be
Show file tree
Hide file tree
Showing 9 changed files with 101 additions and 101 deletions.
7 changes: 5 additions & 2 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ ci:
submodules: false
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.5.0
rev: v4.6.0
hooks:
- id: trailing-whitespace
args: [--markdown-linebreak-ext=md]
Expand All @@ -19,9 +19,12 @@ repos:

- repo: https://github.com/astral-sh/ruff-pre-commit
# Ruff version.
rev: v0.3.5
rev: v0.5.0
hooks:
# Run the linter.
- id: ruff
args:
- --quiet
- --fix
# Run the formatter.
- id: ruff-format
62 changes: 62 additions & 0 deletions .ruff.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
# Exclude a variety of commonly ignored directories.
extend-exclude = [
"__init__.py",
]

# Same as Black.
line-length = 88
indent-width = 4

# Assume Python 3.9
target-version = "py39"


[lint]
# TODO: should be the following list, but Ruff does not yet impl all of them.
# W503,W504
# E203
# C408
ignore = [
"C408",
#"E203",
"E402",
#"W503",
#"W504",
"D203",
"D211",
"D213",
"UP006",
"UP007", # see ruff GH#4427
]
select = [
"B", # flake8-bugbear
"C", # flake8-comprehensions
#"D", # note: all relevant D's will be set by setting pydocstyle.convention=numpy!
"E", # pycodestyles
"F", # pyflakes
"W", # pycodestyle warnings
"UP", # pyupgrade
"T2", # flake8-print
"I001", # isort
"ICN", # import conventions, e.g. import numpy as np
#"B950", # not yet implemented by Ruff.
"RUF100", # ensure 'noqa' declarations are still valid.
]

[lint.pydocstyle]
convention = "numpy"

[lint.mccabe]
max-complexity = 15 # max branches inside a function.

[lint.isort]
known-first-party = [
"weldx",
"weldx_widgets",
]
required-imports = [
"from __future__ import annotations",
]

[flake8-import-conventions]
extend-aliases = { xarray = "xr" }
62 changes: 0 additions & 62 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -89,65 +89,3 @@ exclude_lines = [
# Have to re-enable the standard pragma
"pragma: no cover",
]

[tool.ruff]
target-version = "py38" # designated Python version
exclude = [
"__init__.py",
"doc/src/conf.py",
]
# TODO: should be the following list, but Ruff does not yet impl all of them.
# W503,W504
# E203
# C408
ignore = [
"C408",
#"E203",
"E402",
#"W503",
#"W504",
"D203", "D211", "D213"
]
line-length = 88
select = [
"B", # flake8-bugbear
"C", # flake8-comprehensions
#"D", # note: all relevant D's will be set by setting pydocstyle.convention=numpy!
"E", # pycodestyles
"F", # pyflakes
"W", # pycodestyle warnings
"UP", # pyupgrade
"T2", # flake8-print
"I001", # isort
"ICN", # import conventions, e.g. import numpy as np
#"B950", # not yet implemented by Ruff.
"RUF100", # ensure 'noqa' declarations are still valid.
]

# Allow pydocstyle violations in certain areas.
per-file-ignores."**/{tests,tags,asdf,devtools}/**" = ["D"]
per-file-ignores."conftest.py" = ["D"]
per-file-ignores."doc/src/tutorials/*" = ["D"]
per-file-ignores."doc/src/conf.py" = ["E501", # ignore long lines.
"RUF100", # do no check if 'noqa' is needed (circular import workaround)
]
# Allow prints in certain areas.
per-file-ignores."**/{cli,tests,tutorials,devtools}/**/*{.py,ipynb}" = ["T2"]

external = ["B950"]
pydocstyle = {convention = "numpy"}
pyupgrade = {keep-runtime-typing = true}

mccabe = {max-complexity = 15} # max branches inside a function.

[tool.ruff.isort]
known-first-party = ["weldx"]
required-imports = ["from __future__ import annotations"]

[tool.ruff.flake8-import-conventions]
extend-aliases = {xarray = "xr"}

[tool.nbqa.addopts]
ruff = [
"--extend-ignore=B018"
]
49 changes: 25 additions & 24 deletions weldx_widgets/visualization/colors.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""Color related tools."""

from typing import Dict, Generator, List, Sized, Tuple, Union
from collections.abc import Generator, Sized
from typing import Union

import matplotlib.pyplot as plt
import numpy as np
Expand All @@ -15,12 +16,12 @@
RGB_GREY = 0x999999


def _color_rgb_to_int(rgb_color_tuple: Tuple[int, int, int]) -> int:
def _color_rgb_to_int(rgb_color_tuple: tuple[int, int, int]) -> int:
"""Convert an RGB color tuple to an 24 bit integer.
Parameters
----------
rgb_color_tuple : Tuple[int, int, int]
rgb_color_tuple : tuple[int, int, int]
The color as RGB tuple. Values must be in the range 0-255.
Returns
Expand All @@ -32,7 +33,7 @@ def _color_rgb_to_int(rgb_color_tuple: Tuple[int, int, int]) -> int:
return int("0x{:02x}{:02x}{:02x}".format(*rgb_color_tuple), 0)


def _color_int_to_rgb(integer: int) -> Tuple[int, int, int]:
def _color_int_to_rgb(integer: int) -> tuple[int, int, int]:
"""Convert an 24 bit integer into a RGB color tuple with the value range (0-255).
Parameters
Expand All @@ -42,45 +43,45 @@ def _color_int_to_rgb(integer: int) -> Tuple[int, int, int]:
Returns
-------
Tuple[int, int, int]:
tuple[int, int, int]:
The resulting RGB tuple.
"""
return (integer >> 16) & 255, (integer >> 8) & 255, integer & 255


def _color_rgb_to_rgb_normalized(
rgb: Tuple[int, int, int],
) -> Tuple[float, float, float]:
rgb: tuple[int, int, int],
) -> tuple[float, float, float]:
"""Normalize an RGB color tuple with the range (0-255) to the range (0.0-1.0).
Parameters
----------
rgb : Tuple[int, int, int]
rgb : tuple[int, int, int]
Color tuple with values in the range (0-255)
Returns
-------
Tuple[float, float, float] :
tuple[float, float, float] :
Color tuple with values in the range (0.0-1.0)
"""
return tuple(val / 255 for val in rgb) # type: ignore[return-value]


def _color_rgb_normalized_to_rgb(
rgb: Tuple[float, float, float],
) -> Tuple[int, int, int]:
rgb: tuple[float, float, float],
) -> tuple[int, int, int]:
"""Normalize an RGB color tuple with the range (0.0-1.0) to the range (0-255).
Parameters
----------
rgb : Tuple[float, float, float]
rgb : tuple[float, float, float]
Color tuple with values in the range (0.0-1.0)
Returns
-------
Tuple[int, int, int] :
tuple[int, int, int] :
Color tuple with values in the range (0-255)
"""
Expand All @@ -97,20 +98,20 @@ def color_int_to_rgb_normalized(integer):
Returns
-------
Tuple[float, float, float]:
tuple[float, float, float]:
The resulting RGB tuple.
"""
rgb = _color_int_to_rgb(integer)
return _color_rgb_to_rgb_normalized(rgb)


def _color_rgb_normalized_to_int(rgb: Tuple[float, float, float]) -> int:
def _color_rgb_normalized_to_int(rgb: tuple[float, float, float]) -> int:
"""Convert a normalized RGB color tuple to an 24 bit integer.
Parameters
----------
rgb : Tuple[float, float, float]
rgb : tuple[float, float, float]
The color as RGB tuple. Values must be in the range 0.0-1.0.
Returns
Expand All @@ -122,13 +123,13 @@ def _color_rgb_normalized_to_int(rgb: Tuple[float, float, float]) -> int:
return _color_rgb_to_int(_color_rgb_normalized_to_rgb(rgb))


def _shuffled_tab20_colors() -> List[int]:
def _shuffled_tab20_colors() -> list[int]:
"""Get a shuffled list of matplotlib 'tab20' colors.
Returns
-------
List[int] :
List of colors
list[int] :
list of colors
"""
num_colors = 20
Expand All @@ -143,20 +144,20 @@ def _shuffled_tab20_colors() -> List[int]:


def color_to_rgb_normalized(
color: Union[int, Tuple[int, int, int], Tuple[float, float, float]],
) -> Tuple[float, float, float]:
color: Union[int, tuple[int, int, int], tuple[float, float, float]],
) -> tuple[float, float, float]:
"""Convert an arbitrary RGB color representation into a normalized RGB triplet.
Parameters
----------
color : Union[int, Tuple[int, int, int], Tuple[float, float, float]]
color : Union[int, tuple[int, int, int], tuple[float, float, float]]
A 24 bit integer, a triplet of integers with a value range of 0-255
or a triplet of floats with a value range of 0.0-1.0
that represent an RGB color.
Returns
-------
Tuple[float, float, float] :
tuple[float, float, float] :
RGB color triplet with the value range 0.0 to 1.0
"""
Expand Down Expand Up @@ -198,7 +199,7 @@ def color_generator_function() -> Generator:

def get_color(
key: str,
color_dict: Dict[str, Union[int, Tuple[int, int, int]]],
color_dict: dict[str, Union[int, tuple[int, int, int]]],
color_generator: Generator,
) -> int:
"""Get a 24 bit RGB color from a dictionary or generator function.
Expand Down
6 changes: 3 additions & 3 deletions weldx_widgets/visualization/csm_mpl.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

from __future__ import annotations

from typing import TYPE_CHECKING, Any, List, Union
from typing import TYPE_CHECKING, Any, Union

import matplotlib.pyplot as plt
import numpy as np
Expand Down Expand Up @@ -156,7 +156,7 @@ def draw_coordinate_system_matplotlib(
tips = dsx.orientation
else:
if not isinstance(scale_vectors, np.ndarray):
if isinstance(scale_vectors, List):
if isinstance(scale_vectors, list):
scale_vectors = np.array(scale_vectors)
else:
scale_vectors = np.array([scale_vectors for _ in range(3)])
Expand Down Expand Up @@ -296,7 +296,7 @@ def _set_limits_matplotlib(
"""
if limits is not None:
if not isinstance(limits, List):
if not isinstance(limits, list):
limits = [limits]
if len(limits) == 1:
limits = [limits[0] for _ in range(3)]
Expand Down
6 changes: 3 additions & 3 deletions weldx_widgets/visualization/types.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
"""Type aliases shared in visualization package."""

from typing import List, Tuple, Union
from typing import Union

import pandas as pd

types_timeindex = Union[pd.DatetimeIndex, pd.TimedeltaIndex, List[pd.Timestamp]]
types_limits = Union[List[Tuple[float, float]], Tuple[float, float]]
types_timeindex = Union[pd.DatetimeIndex, pd.TimedeltaIndex, list[pd.Timestamp]]
types_limits = Union[list[tuple[float, float]], tuple[float, float]]

__all__ = ("types_timeindex", "types_limits")
2 changes: 1 addition & 1 deletion weldx_widgets/widget_evaluate.py
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ def make_output():
scans_available = True
try:
foo = [
_clean_nans_from_spatial_data(csm.get_data("scan_%s" % i))
_clean_nans_from_spatial_data(csm.get_data(f"scan_{i}"))
for i in range(0, 2)
]
assert len(foo) == 2
Expand Down
4 changes: 1 addition & 3 deletions weldx_widgets/widget_gas.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
"""Widgets to handle shielding gas selection."""

from typing import List

from bidict import bidict
from ipywidgets import Button, Dropdown, HBox, IntSlider, Layout, Output

Expand Down Expand Up @@ -119,7 +117,7 @@ def to_tree(self) -> dict:
return dict(gas_component=gas_components)

def from_tree(self, tree):
gc_list: List[GasComponent] = tree["gas_component"]
gc_list: list[GasComponent] = tree["gas_component"]
self._clear()
for gc in gc_list:
# create widget for gas element with percentage, then add to components dict
Expand Down
4 changes: 1 addition & 3 deletions weldx_widgets/widget_measurement.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
"""Widget to wrap around a measurement."""

from typing import List

from matplotlib import pylab as plt

import weldx
Expand Down Expand Up @@ -62,7 +60,7 @@ def plot_measurements(
class WidgetMeasurement(WidgetSimpleOutput):
"""Widget to wrap around a measurement."""

def __init__(self, measurements: List["weldx.measurement.Measurement"], out=None):
def __init__(self, measurements: list["weldx.measurement.Measurement"], out=None):
super().__init__(out=out)

n = len(measurements)
Expand Down

0 comments on commit 3cc86be

Please sign in to comment.