Skip to content

Commit 3bd4b1a

Browse files
authored
update ruff (#657)
1 parent 1a650be commit 3bd4b1a

29 files changed

+80
-90
lines changed

.pre-commit-config.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
repos:
22
- repo: https://github.com/astral-sh/ruff-pre-commit
33
# Ruff version.
4-
rev: v0.9.3
4+
rev: v0.12.0
55
hooks:
66
# Run the linter.
77
- id: ruff

pyproject.toml

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ docs = [
5454
]
5555
dev = [
5656
"mypy",
57-
"ruff>=0.9.3",
57+
"ruff>=0.12.0",
5858
"pytest",
5959
"pytest-timeout",
6060
"pytest-cov",
@@ -135,24 +135,31 @@ select = [
135135
"E", # pycodestyle
136136
"W", # pycodestyle
137137
"PL", # pylint
138+
"UP", # pyupgrade
139+
# "F401", # remove unused import
140+
"I001", # sort imports
138141
# "NPY201", # reactivate when np>2.0 is used
139142
]
140143
ignore = [
144+
"E402", # Module level import not at top of file
141145
"E501", # Line too long ({width} > {limit} characters)
142146
"E701", # Multiple statements on one line (colon)
143147
"E731", # Do not assign a lambda expression, use a def
144-
"E402", # Module level import not at top of file
148+
"PLC0415", # `import` should be at the top-level of a file
149+
"PLR0904", # too-many-public-methods
145150
"PLR0911", # Too many return statements
146151
"PLR0912", # Too many branches
147152
"PLR0913", # Too many arguments in function definition
148153
"PLR0915", # Too many statements
149-
"PLR2004", # Magic value used instead of constant
150-
"PLW0603", # Using the global statement
151-
"PLW2901", # redefined-loop-name
154+
"PLR0917", # too-many-positional-arguments
152155
"PLR1714", # consider-using-in
156+
"PLR2004", # Magic value used instead of constant
153157
"PLR5501", # else-if-used
158+
"PLW0603", # Using the global statement
159+
"PLW2901", # redefined-loop-name,
154160
]
155161
fixable = ["ALL"]
162+
isort.split-on-trailing-comma = false
156163

157164
[tool.ruff.format]
158165
quote-style = "double"

src/pynxtools/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,11 @@
1616
# limitations under the License.
1717
#
1818

19-
from typing import Dict
2019
import logging
2120
import os
2221
import re
2322
from datetime import datetime
23+
from typing import Dict
2424

2525
from pynxtools._build_wrapper import get_vcs_version
2626
from pynxtools.definitions.dev_tools.globals.nxdl import get_nxdl_version

src/pynxtools/dataconverter/convert.py

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -373,12 +373,10 @@ def convert_cli(
373373
except TypeError as exc:
374374
sys.tracebacklimit = 0
375375
raise click.UsageError(
376-
(
377-
"Please make sure you have the following entries in your "
378-
"parameter file:\n\n# NeXusParser Parameter File - v0.0.1"
379-
"\n\ndataconverter:\n\treader: value\n\tnxdl: value\n\tin"
380-
"put-file: value"
381-
)
376+
"Please make sure you have the following entries in your "
377+
"parameter file:\n\n# NeXusParser Parameter File - v0.0.1"
378+
"\n\ndataconverter:\n\treader: value\n\tnxdl: value\n\tin"
379+
"put-file: value"
382380
) from exc
383381
if nxdl is None:
384382
raise click.UsageError("Missing option '--nxdl'")

src/pynxtools/dataconverter/file_hashing.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ def get_file_hashvalue(file_name: str) -> str:
2828
# Read and update hash string value in blocks of 4K
2929
for byte_block in iter(lambda: file_handle.read(4096), b""):
3030
sha256_hash.update(byte_block)
31-
except IOError:
31+
except OSError:
3232
print(f"File {file_name} is not accessible !")
3333

3434
return sha256_hash.hexdigest()

src/pynxtools/dataconverter/hdfdict.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
# -*- coding: utf-8 -*-
21
"""Taken from: https://github.com/SiggiGue/hdfdict/blob/master/hdfdict/hdfdict.py"""
32

43
from collections import UserDict
@@ -196,7 +195,7 @@ def dump(data, hdf, *args, packer=pack_dataset, **kwargs):
196195
def _recurse(datadict, hdfobject):
197196
for key, value in datadict.items():
198197
if isinstance(key, tuple):
199-
key = "_".join((str(i) for i in key))
198+
key = "_".join(str(i) for i in key)
200199
if isinstance(value, (dict, LazyHdfDict)):
201200
hdfgroup = hdfobject.create_group(key)
202201
_recurse(value, hdfgroup)

src/pynxtools/dataconverter/helpers.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
from datetime import datetime, timezone
2525
from enum import Enum, auto
2626
from functools import lru_cache
27-
from typing import Any, Callable, List, Optional, Tuple, Union, Sequence, cast
27+
from typing import Any, Callable, List, Optional, Sequence, Tuple, Union, cast
2828

2929
import h5py
3030
import lxml.etree as ET

src/pynxtools/dataconverter/nexus_tree.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,25 +29,24 @@
2929
"""
3030

3131
from functools import lru_cache, reduce
32-
from typing import Any, List, Dict, Literal, Optional, Set, Tuple, Union
32+
from typing import Any, Dict, List, Literal, Optional, Set, Tuple, Union
3333

3434
import lxml.etree as ET
3535
from anytree.node.nodemixin import NodeMixin
3636

37-
from pynxtools import get_definitions_url
37+
from pynxtools import NX_DOC_BASES, get_definitions_url
3838
from pynxtools.dataconverter.helpers import (
39+
NEXUS_TO_PYTHON_DATA_TYPES,
3940
get_all_parents_for,
4041
get_nxdl_root_and_path,
41-
is_variadic,
4242
is_appdef,
43+
is_variadic,
4344
remove_namespace_from_tag,
44-
NEXUS_TO_PYTHON_DATA_TYPES,
4545
)
4646
from pynxtools.definitions.dev_tools.utils.nxdl_utils import (
4747
get_nx_namefit,
4848
is_name_type,
4949
)
50-
from pynxtools import NX_DOC_BASES
5150

5251
NexusType = Literal[
5352
"NX_BINARY",

src/pynxtools/dataconverter/readers/example/reader.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,11 +45,11 @@ def read(
4545
data: dict = {}
4646

4747
if not file_paths:
48-
raise IOError("No input files were given to Example Reader.")
48+
raise OSError("No input files were given to Example Reader.")
4949

5050
for file_path in file_paths:
5151
file_extension = file_path[file_path.rindex(".") :]
52-
with open(file_path, "r", encoding="utf-8") as input_file:
52+
with open(file_path, encoding="utf-8") as input_file:
5353
if file_extension == ".json":
5454
data = json.loads(input_file.read())
5555

src/pynxtools/dataconverter/readers/json_map/reader.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@
2222
from typing import Any, Tuple
2323

2424
import numpy as np
25-
import yaml
2625
import xarray
26+
import yaml
2727
from mergedeep import merge
2828

2929
from pynxtools.dataconverter import hdfdict
@@ -186,7 +186,7 @@ def read(
186186
for file_path in file_paths:
187187
file_extension = file_path[file_path.rindex(".") :]
188188
if file_extension == ".json":
189-
with open(file_path, "r", encoding="utf-8") as input_file:
189+
with open(file_path, encoding="utf-8") as input_file:
190190
if ".mapping" in file_path:
191191
mapping = json.loads(input_file.read())
192192
else:
@@ -195,7 +195,7 @@ def read(
195195
with open(file_path, "rb") as input_file: # type: ignore[assignment]
196196
data = pickle.load(input_file) # type: ignore[arg-type]
197197
elif file_extension == ".yaml":
198-
with open(file_path, "r") as input_file:
198+
with open(file_path) as input_file:
199199
merge(data, yaml.safe_load(input_file))
200200
else:
201201
is_hdf5 = False
@@ -216,7 +216,7 @@ def read(
216216
template = Template(
217217
{x: "/hierarchical/path/in/your/datafile" for x in template}
218218
)
219-
raise IOError(
219+
raise OSError(
220220
"Please supply a JSON mapping file: "
221221
" my_nxdl_map.mapping.json\n\n You can use this "
222222
"template for the required fields: \n" + str(template)

0 commit comments

Comments
 (0)