8000 update ruff by lukaspie · Pull Request #657 · FAIRmat-NFDI/pynxtools · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

update ruff #657

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Jun 18, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
repos:
- repo: https://github.com/astral-sh/ruff-pre-commit
# Ruff version.
rev: v0.9.3
rev: v0.12.0
hooks:
# Run the linter.
- id: ruff
Expand Down
17 changes: 12 additions & 5 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ docs = [
]
dev = [
"mypy",
"ruff>=0.9.3",
"ruff>=0.12.0",
"pytest",
"pytest-timeout",
"pytest-cov",
Expand Down Expand Up @@ -135,24 +135,31 @@ select = [
"E", # pycodestyle
"W", # pycodestyle
"PL", # pylint
"UP", # pyupgrade
# "F401", # remove unused import
"I001", # sort imports
# "NPY201", # reactivate when np>2.0 is used
]
ignore = [
"E402", # Module level import not at top of file
"E501", # Line too long ({width} > {limit} characters)
"E701", # Multiple statements on one line (colon)
"E731", # Do not assign a lambda expression, use a def
"E402", # Module level import not at top of file
"PLC0415", # `import` should be at the top-level of a file
"PLR0904", # too-many-public-methods
"PLR0911", # Too many return statements
"PLR0912", # Too many branches
"PLR0913", # Too many arguments in function definition
"PLR0915", # Too many statements
"PLR2004", # Magic value used instead of constant
"PLW0603", # Using the global statement
"PLW2901", # redefined-loop-name
"PLR0917", # too-many-positional-arguments
"PLR1714", # consider-using-in
"PLR2004", # Magic value used instead of constant
"PLR5501", # else-if-used
"PLW0603", # Using the global statement
"PLW2901", # redefined-loop-name,
]
fixable = ["ALL"]
isort.split-on-trailing-comma = false

[tool.ruff.format]
quote-style = "double"
Expand Down
2 changes: 1 addition & 1 deletion src/pynxtools/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,11 @@
# limitations under the License.
#

from typing import Dict
import logging
import os
import re
from datetime import datetime
from typing import Dict

from pynxtools._build_wrapper import get_vcs_version
from pynxtools.definitions.dev_tools.globals.nxdl import get_nxdl_version
Expand Down
10 changes: 4 additions & 6 deletions src/pynxtools/dataconverter/convert.py
Original file line number Diff line number Diff line change
Expand Up @@ -373,12 +373,10 @@ def convert_cli(
except TypeError as exc:
sys.tracebacklimit = 0
raise click.UsageError(
(
"Please make sure you have the following entries in your "
"parameter file:\n\n# NeXusParser Parameter File - v0.0.1"
"\n\ndataconverter:\n\treader: value\n\tnxdl: value\n\tin"
"put-file: value"
)
"Please make sure you have the following entries in your "
"parameter file:\n\n# NeXusParser Parameter File - v0.0.1"
"\n\ndataconverter:\n\treader: value\n\tnxdl: value\n\tin"
"put-file: value"
) from exc
if nxdl is None:
raise click.UsageError("Missing option '--nxdl'")
Expand Down
2 changes: 1 addition & 1 deletion src/pynxtools/dataconverter/file_hashing.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ def get_file_hashvalue(file_name: str) -> str:
# Read and update hash string value in blocks of 4K
for byte_block in iter(lambda: file_handle.read(4096), b""):
sha256_hash.update(byte_block)
except IOError:
except OSError:
print(f"File {file_name} is not accessible !")

return sha256_hash.hexdigest()
3 changes: 1 addition & 2 deletions src/pynxtools/dataconverter/hdfdict.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
"""Taken from: https://github.com/SiggiGue/hdfdict/blob/master/hdfdict/hdfdict.py"""

from collections import UserDict
Expand Down Expand Up @@ -196,7 +195,7 @@ def dump(data, hdf, *args, packer=pack_dataset, **kwargs):
def _recurse(datadict, hdfobject):
for key, value in datadict.items():
if isinstance(key, tuple):
key = "_".join((str(i) for i in key))
key = "_".join(str(i) for i in key)
if isinstance(value, (dict, LazyHdfDict)):
hdfgroup = hdfobject.create_group(key)
_recurse(value, hdfgroup)
Expand Down
2 changes: 1 addition & 1 deletion src/pynxtools/dataconverter/helpers.py
F438
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
from datetime import datetime, timezone
from enum import Enum, auto
from functools import lru_cache
from typing import Any, Callable, List, Optional, Tuple, Union, Sequence, cast
from typing import Any, Callable, List, Optional, Sequence, Tuple, Union, cast

import h5py
import lxml.etree as ET
Expand Down
9 changes: 4 additions & 5 deletions src/pynxtools/dataconverter/nexus_tree.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,25 +29,24 @@
"""

from functools import lru_cache, reduce
from typing import Any, List, Dict, Literal, Optional, Set, Tuple, Union
from typing import Any, Dict, List, Literal, Optional, Set, Tuple, Union

import lxml.etree as ET
from anytree.node.nodemixin import NodeMixin

from pynxtools import get_definitions_url
from pynxtools import NX_DOC_BASES, get_definitions_url
from pynxtools.dataconverter.helpers import (
NEXUS_TO_PYTHON_DATA_TYPES,
get_all_parents_for,
get_nxdl_root_and_path,
is_variadic,
is_appdef,
is_variadic,
remove_namespace_from_tag,
NEXUS_TO_PYTHON_DATA_TYPES,
)
from pynxtools.definitions.dev_tools.utils.nxdl_utils import (
get_nx_namefit,
is_name_type,
)
from pynxtools import NX_DOC_BASES

NexusType = Literal[
"NX_BINARY",
Expand Down
4 changes: 2 additions & 2 deletions src/pynxtools/dataconverter/readers/example/reader.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,11 @@ def read(
data: dict = {}

if not file_paths:
raise IOError("No input files were given to Example Reader.")
raise OSError("No input files were given to Example Reader.")

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

Expand Down
8 changes: 4 additions & 4 deletions src/pynxtools/dataconverter/readers/json_map/reader.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@
from typing import Any, Tuple

import numpy as np
import yaml
import xarray
import yaml
from mergedeep import merge

from pynxtools.dataconverter import hdfdict
Expand Down Expand Up @@ -186,7 +186,7 @@ def read(
for file_path in file_paths:
file_extension = file_path[file_path.rindex(".") :]
if file_extension == ".json":
with open(file_path, "r", encoding="utf-8") as input_file:
with open(file_path, encoding="utf-8") as input_file:
if ".mapping" in file_path:
mapping = json.loads(input_file.read())
else:
Expand All @@ -195,7 +195,7 @@ def read(
with open(file_path, "rb") as input_file: # type: ignore[assignment]
data = pickle.load(input_file) # type: ignore[arg-type]
elif file_extension == ".yaml":
with open(file_path, "r") as input_file:
with open(file_path) as input_file:
merge(data, yaml.safe_load(input_file))
else:
is_hdf5 = False
Expand All @@ -216,7 +216,7 @@ def read(
template = Template(
{x: "/hierarchical/path/in/your/datafile" for x in template}
)
raise IOError(
raise OSError(
"Please supply a JSON mapping file: "
" my_nxdl_map.mapping.json\n\n You can use this "
"template for the required fields: \n" + str(template)
Expand Down
2 changes: 1 addition & 1 deletion src/pynxtools/dataconverter/readers/json_yml/reader.py
Original file line number Diff line number Diff line change< E377 /th>
Expand Up @@ -17,8 +17,8 @@
#
"""An example reader implementation for the DataConverter."""

from typing import Tuple, Any, Callable, Dict, List
import os
from typing import Any, Callable, Dict, List, Tuple

from pynxtools.dataconverter.readers.base.reader import BaseReader
from pynxtools.dataconverter.template import Template
Expand Down
2 changes: 1 addition & 1 deletion src/pynxtools/dataconverter/readers/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,7 @@ def parse_json(file_path: Union[str, Path]) -> Dict[str, Any]:
Returns:
Dict[str, Any]: The dictionary containing the data readout from the json.
"""
with open(file_path, "r", encoding="utf-8") as file:
with open(file_path, encoding="utf-8") as file:
return json.load(file)


Expand Down
6 changes: 3 additions & 3 deletions src/pynxtools/dataconverter/validation.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,22 +16,22 @@
# See the License for the specific language governing permissions and
# limitations under the License.
#
import re
import copy
import re
from collections import defaultdict
from functools import reduce
from operator import getitem
from typing import (
Any,
Dict,
Iterable,
List,
Literal,
Mapping,
MutableMapping,
Optional,
Tuple,
Union,
Dict,
Literal,
)

import h5py
Expand Down
4 changes: 2 additions & 2 deletions src/pynxtools/dataconverter/writer.py
Original file line number Diff line number Diff line change
Expand Up @@ -300,7 +300,7 @@ def add_units_key(dataset, path):
except InvalidDictProvided as exc:
print(str(exc))
except Exception as exc:
raise IOError(
raise OSError(
f"Unknown error occured writing the path: {path} "
f"with the following message: {str(exc)}"
) from exc
Expand Down Expand Up @@ -335,7 +335,7 @@ def add_units_key(dataset, path):
)
dataset.attrs[entry_name[1:]] = data
except Exception as exc:
raise IOError(
raise OSError(
f"Unknown error occured writing the path: {path}"
f", while writing the value: {value} "
f"with the following message: {str(exc)}"
Expand Down
4 changes: 2 additions & 2 deletions src/pynxtools/eln_mapper/eln.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@
# limitations under the License.
#

import re
import logging
import re
from abc import ABC, abstractmethod
from typing import Any, List, Dict, Optional
from typing import Any, Dict, List, Optional

import yaml

Expand Down
2 changes: 1 addition & 1 deletion src/pynxtools/eln_mapper/eln_mapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@
# limitations under the License.
#

from typing import Union, Optional
from pathlib import Path
from typing import Optional, Union

import click

Expand Down
8 changes: 2 additions & 6 deletions src/pynxtools/eln_mapper/reader_eln.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,9 @@
#

import re
from typing import List, Dict
from typing import Dict, List

from pynxtools.dataconverter.nexus_tree import (
NexusEntity,
NexusGroup,
NexusNode,
)
from pynxtools.dataconverter.nexus_tree import NexusEntity, NexusGroup, NexusNode
from pynxtools.eln_mapper.eln import ElnGenerator


Expand Down
8 changes: 2 additions & 6 deletions src/pynxtools/eln_mapper/schema_eln.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,9 @@
#

import re
from typing import List, Dict, Union, Tuple
from typing import Dict, List, Tuple, Union

from pynxtools.dataconverter.nexus_tree import (
NexusEntity,
NexusGroup,
NexusNode,
)
from pynxtools.dataconverter.nexus_tree import NexusEntity, NexusGroup, NexusNode
from pynxtools.eln_mapper.eln import ElnGenerator

NEXUS_TO_NOMAD_QUANTITY: Dict[str, Tuple[str, str]] = {
Expand Down
8 changes: 5 additions & 3 deletions src/pynxtools/nomad/dataconverter.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@
from pynxtools.dataconverter import convert as pynxtools_converter
from pynxtools.dataconverter import writer as pynxtools_writer
from pynxtools.dataconverter.template import Template
from pynxtools.definitions.dev_tools.utils.nxdl_utils import get_app_defs_names # pylint: disable=import-error
from pynxtools.definitions.dev_tools.utils.nxdl_utils import (
get_app_defs_names, # pylint: disable=import-error
)

m_package = Package(name="nexus_data_converter")

Expand Down Expand Up @@ -176,7 +178,7 @@ class ElnYamlConverter(EntryData):
)

def normalize(self, archive, logger):
super(ElnYamlConverter, self).normalize(archive, logger)
super().normalize(archive, logger)

eln_dict = create_eln_dict(archive)
write_yaml(archive, archive.data.output, eln_dict)
Expand Down Expand Up @@ -231,7 +233,7 @@ class NexusDataConverter(EntryData):
)

def normalize(self, archive, logger):
super(NexusDataConverter, self).normalize(archive, logger)
super().normalize(archive, logger)

raw_path = archive.m_context.raw_path()
eln_dict = create_eln_dict(archive)
Expand Down
7 changes: 5 additions & 2 deletions src/pynxtools/nomad/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,11 @@

import pynxtools.nomad.schema as nexus_schema
from pynxtools.nexus.nexus import HandleNexus
from pynxtools.nomad.utils import FIELD_STATISTICS
from pynxtools.nomad.utils import REPLACEMENT_FOR_NX, get_quantity_base_name
from pynxtools.nomad.utils import (
FIELD_STATISTICS,
REPLACEMENT_FOR_NX,
get_quantity_base_name,
)
from pynxtools.nomad.utils import _rename_nx_for_nomad as rename_nx_for_nomad


Expand Down
4 changes: 2 additions & 2 deletions src/pynxtools/nomad/schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,14 +75,14 @@
from nomad.normalizing.common import nomad_atoms_from_ase_atoms
from nomad.normalizing.topology import add_system, add_system_info
from nomad.units import ureg
from nomad.utils import get_logger, strip, hash
from nomad.utils import get_logger, hash, strip

except ImportError as exc:
raise ImportError(
"Could not import nomad package. Please install the package 'nomad-lab'."
) from exc

from pynxtools import get_definitions_url, NX_DOC_BASES
from pynxtools import NX_DOC_BASES, get_definitions_url
from pynxtools.definitions.dev_tools.utils.nxdl_utils import get_nexus_definitions_path
from pynxtools.nomad.utils import (
FIELD_STATISTICS,
Expand Down
Loading
Loading
0