Skip to content

Commit

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

updates:
- [github.com/charliermarsh/ruff-pre-commit: v0.0.242 → v0.0.259](astral-sh/ruff-pre-commit@v0.0.242...v0.0.259)
- [github.com/nbQA-dev/nbQA: 1.6.1 → 1.6.4](nbQA-dev/nbQA@1.6.1...1.6.3)
- fix formatting (black).
- use importlib.util.find_spec for module availability check.
- set explicit stacklevel for warnings.warn calls.
- ignore too high complexity of get_schema_tree.
- fixed some grammar mistakes Pycharm found.


Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Co-authored-by: Martin K. Scherer <m.scherer@fu-berlin.de>
Co-authored-by: Martin K. Scherer <marscher@users.noreply.github.com>
  • Loading branch information
3 people authored Mar 27, 2023
1 parent 51fd46f commit 4215eb0
Show file tree
Hide file tree
Showing 8 changed files with 55 additions and 28 deletions.
6 changes: 3 additions & 3 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ repos:
hooks:
- id: black
- repo: https://github.com/charliermarsh/ruff-pre-commit
rev: v0.0.242
rev: v0.0.259
hooks:
- id: ruff
args:
Expand All @@ -45,7 +45,7 @@ repos:
- id: validate-pyproject
# ----- Jupyter Notebooks -----
- repo: https://github.com/nbQA-dev/nbQA
rev: 1.6.1
rev: 1.6.4
hooks:
- id: nbqa-black
- id: nbqa-ruff # ruff handles isort
Expand All @@ -60,7 +60,7 @@ repos:
- --remove-kernel-metadata
# ----- spellchecking -----
- repo: https://github.com/codespell-project/codespell/
rev: v2.2.2
rev: v2.2.4
hooks:
- id: codespell
exclude: doc/src/legal-notice.md
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ addopts = "--tb=short --color=yes -rsw --cov=weldx --cov-report=term-missing:ski
testpaths = "weldx"
# custom test markers, see https://docs.pytest.org/en/latest/example/markers.html#mark-examples
markers = "slow: marks tests as slow to run (skipped by default, enable with --runslow option)"
asdf_schema_root = "weldx/schemas/weldx.bam.de/weldx" # TODO: couldn"t we just use the entry points to resolve this?
asdf_schema_root = "weldx/schemas/weldx.bam.de/weldx" # TODO: couldn't we just use the entry points to resolve this?
#asdf_schema_tests_enabled = true
#asdf_schema_skip_tests =
# weldx.bam.de/weldx/datamodels/single_pass_weld-1.0.0.schema.yaml
Expand Down
11 changes: 8 additions & 3 deletions weldx/asdf/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,10 @@ def get_schema_path(schema: str) -> Path: # pragma: no cover
if len(schemas) == 0:
raise ValueError(f"No matching schema for filename '{schema}'.")
elif len(schemas) > 1:
warn(f"Found more than one matching schema for filename '{schema}'.")
warn(
f"Found more than one matching schema for filename '{schema}'.",
stacklevel=1,
)
return schemas[0]


Expand Down Expand Up @@ -477,7 +480,9 @@ def get_converter_for_tag(tag: str) -> Union[WeldxConverter, None]:
"""Get the converter class that handles a given tag."""
converters = [s for s in WeldxConverter.__subclasses__() if uri_match(s.tags, tag)]
if len(converters) > 1:
warn(f"Found more than one converter class for {tag=}", UserWarning)
warn(
f"Found more than one converter class for {tag=}", UserWarning, stacklevel=1
)
if converters:
return converters[0]
return None
Expand Down Expand Up @@ -664,7 +669,7 @@ def _warn_protected_keys(self, stacklevel=3):
)


def get_schema_tree( # noqa: C901 # ignore too high complexity
def get_schema_tree( # noqa: C901, MC0001, RUF100, codacy:ignore
schemafile: Union[str, Path], *, drop: set = None
) -> dict:
"""Get a dictionary representation of a weldx schema file with custom formatting.
Expand Down
15 changes: 9 additions & 6 deletions weldx/measurement.py
Original file line number Diff line number Diff line change
Expand Up @@ -490,7 +490,7 @@ def _determine_output_signal(

@staticmethod
def _determine_output_signal_type(type_transformation: str, input_type: str) -> str:
"""Determine the type of a transformations' output signal.
"""Determine the type of given transformations' output signal.
Parameters
----------
Expand Down Expand Up @@ -636,7 +636,7 @@ def add_transformation(
... )
Use the mathematical expression to create a signal transformation which also
performs a analog-digital conversion.
performs analog-digital conversion.
>>> current_ad_transform = SignalTransformation(
... name="Current AD conversion",
Expand Down Expand Up @@ -713,7 +713,7 @@ def add_transformation_from_equipment(
... )
Use the mathematical expression to create a signal transformation which also
performs a analog-digital conversion.
performs analog-digital conversion.
>>> current_ad_transform = SignalTransformation(
... name="Current AD conversion",
Expand All @@ -722,7 +722,7 @@ def add_transformation_from_equipment(
... type_transformation="AD"
... )
Create a new equipment that performs the transformation
Create new equipment that performs the transformation
>>> current_ad_converter = MeasurementEquipment(
... name="Current AD converter",
Expand Down Expand Up @@ -812,7 +812,7 @@ def create_transformation(
... )
Use the mathematical expression to create a new transformation which also
performs a analog-digital conversion.
performs an analog-digital conversion.
>>> mc.create_transformation(name="Current AD conversion",
... error=Error(deviation=Q_(1,"percent")),
Expand All @@ -825,7 +825,10 @@ def create_transformation(
output_signal_unit = U_(output_signal_unit)

if output_signal_type is None and output_signal_unit is None and func is None:
warn("The created transformation does not perform any transformations.")
warn(
"The created transformation does not perform any transformations.",
stacklevel=1,
)

input_signal_source = self._check_and_get_node_name(input_signal_source)
input_signal: Signal = self._graph.nodes[input_signal_source]["signal"]
Expand Down
4 changes: 3 additions & 1 deletion weldx/tags/core/mathematical_expression.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,9 @@ def to_yaml_tree(self, obj: MathematicalExpression, tag: str, ctx) -> dict:
for k, v in obj.parameters.items():
if isinstance(v, DataArray):
if len(v.coords) > 0:
warnings.warn("Coordinates are dropped during serialization.")
warnings.warn(
"Coordinates are dropped during serialization.", stacklevel=0
)
dims = v.dims
v = v.data
setattr(v, META_ATTR, dict(dims=dims))
Expand Down
3 changes: 2 additions & 1 deletion weldx/transformations/cs_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -1920,7 +1920,8 @@ def unmerge(self) -> list[CoordinateSystemManager]:
warnings.warn(
"The following coordinate systems are not part of any subsystem and "
f"lost connection to the CoordinateSystemManager instance: {lcs_rem}\n"
"These systems are removed."
"These systems are removed.",
stacklevel=1,
)

return subsystems
Expand Down
18 changes: 12 additions & 6 deletions weldx/transformations/local_cs.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,8 @@ def __init__(
):
warnings.warn(
"Provided time is dropped because of the given coordinates and "
"orientation."
"orientation.",
stacklevel=2,
)

if construction_checks:
Expand All @@ -113,7 +114,10 @@ def __init__(

# warn about dropped reference time
if time_ref is not None and time is None and self._time_ref is None:
warnings.warn("Reference time dropped. The system is not time dependent.")
warnings.warn(
"Reference time dropped. The system is not time dependent.",
stacklevel=2,
)

def __repr__(self):
"""Give __repr_ output in xarray format."""
Expand Down Expand Up @@ -167,6 +171,8 @@ def __add__(self, rhs_cs: LocalCoordinateSystem) -> LocalCoordinateSystem:
)

# handle time
# TODO: time var is unused! why? The var should be used in line 201?
# e.g. ... rhs_cs.interp_time(lhs_cs.time, time_ref)
time = lhs_cs.time
if time is None:
time = rhs_cs.time
Expand Down Expand Up @@ -407,7 +413,7 @@ def _unify_time_axis(
orientation = ut.xr_interp_orientation_in_time(orientation, time_union)
coordinates = ut.xr_interp_coordinates_in_time(coordinates, time_union)

return (orientation, coordinates)
return orientation, coordinates

@classmethod
def from_euler(
Expand All @@ -422,7 +428,7 @@ def from_euler(
"""Construct a local coordinate system from an euler sequence.
This function uses scipy.spatial.transform.Rotation.from_euler method to define
the coordinate systems orientation. Take a look at it's documentation, if some
the coordinate systems orientation. Take a look at its documentation, if some
information is missing here. The related parameter docs are a copy of the scipy
documentation.
Expand Down Expand Up @@ -724,7 +730,7 @@ def interp_time(
value will be stripped from the result.
Additionally, if the passed time range does not overlap with the time range of
the coordinate system, the resulting system won't be time dependent neither
because the values outside of the coordinate systems time range are considered
because the values outside the coordinate systems time range are considered
as being constant.
Parameters
Expand Down Expand Up @@ -826,7 +832,7 @@ def plot(
A reference timestamp that can be provided if the ``time`` parameter is a
`pandas.TimedeltaIndex`
time_index: int
If the coordinate system is time dependent, this parameter can be used to
If the coordinate system is time dependent, this parameter can be used
to select a specific key frame by its index.
scale_vectors :
A scaling factor or array to adjust the vector length
Expand Down
24 changes: 17 additions & 7 deletions weldx/util/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import warnings
from collections.abc import Callable, Sequence, Set
from functools import wraps
from importlib.util import find_spec
from inspect import getmembers, isfunction
from typing import ClassVar, Collection, Hashable, Mapping, Union

Expand Down Expand Up @@ -36,6 +37,7 @@


class WeldxDeprecationWarning(DeprecationWarning):

"""Deprecation warning type."""


Expand Down Expand Up @@ -419,15 +421,23 @@ def apply_func_by_mapping(func_map: dict[Hashable, Callable], inputs):
@decorator
def check_matplotlib_available(func, *args, **kwargs):
"""Emit a warning if matplotlib is not available."""
try:
import matplotlib.pyplot as plt # noqa: F401
except ModuleNotFoundError:

def _warn():
warnings.warn(
"Matplotlib unavailable! Cannot plot. "
"Please install matplotlib or weldx_widgets.",
stacklevel=2,
stacklevel=3,
)
else:
return func(*args, **kwargs)

return None
try:
if find_spec("matplotlib.pyplot") is None:
_warn()
return
except ModuleNotFoundError:
_warn()
return
except ValueError:
warnings.warn("Matplotlib is unavailable (module set to None).", stacklevel=2)
return

return func(*args, **kwargs)

0 comments on commit 4215eb0

Please sign in to comment.