diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 0e9f20820..670d2f745 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -21,7 +21,7 @@ repos: # Python - repo: https://github.com/astral-sh/ruff-pre-commit # Ruff version. - rev: v0.8.6 + rev: v0.9.1 hooks: - id: ruff args: ["--fix"] diff --git a/dpdata/abacus/md.py b/dpdata/abacus/md.py index 1b5971655..dbe86735f 100644 --- a/dpdata/abacus/md.py +++ b/dpdata/abacus/md.py @@ -56,9 +56,9 @@ def get_coords_from_dump(dumplines, natoms): if "VIRIAL" in dumplines[6]: calc_stress = True check_line = 10 - assert ( - "POSITION" in dumplines[check_line] - ), "keywords 'POSITION' cannot be found in the 6th line. Please check." + assert "POSITION" in dumplines[check_line], ( + "keywords 'POSITION' cannot be found in the 6th line. Please check." + ) if "FORCE" in dumplines[check_line]: calc_force = True diff --git a/dpdata/deepmd/mixed.py b/dpdata/deepmd/mixed.py index 2aff3a28a..fe5bdaa86 100644 --- a/dpdata/deepmd/mixed.py +++ b/dpdata/deepmd/mixed.py @@ -15,9 +15,9 @@ def to_system_data(folder, type_map=None, labels=True): if type_map is not None: assert isinstance(type_map, list) missing_type = [i for i in old_type_map if i not in type_map] - assert ( - not missing_type - ), f"These types are missing in selected type_map: {missing_type} !" + assert not missing_type, ( + f"These types are missing in selected type_map: {missing_type} !" + ) index_map = np.array([type_map.index(i) for i in old_type_map]) data["atom_names"] = type_map.copy() else: diff --git a/dpdata/plugins/n2p2.py b/dpdata/plugins/n2p2.py index 28942ff5f..f9974fbab 100644 --- a/dpdata/plugins/n2p2.py +++ b/dpdata/plugins/n2p2.py @@ -85,18 +85,18 @@ def from_labeled_system(self, file_name: FileType, **kwargs): energy = None elif line.lower() == "end": # If we are at the end of a section, process the section - assert ( - len(coord) == len(atype) == len(force) - ), "Number of atoms, atom types, and forces must match." + assert len(coord) == len(atype) == len(force), ( + "Number of atoms, atom types, and forces must match." + ) # Check if the number of atoms is consistent across all frames natom = len(coord) if natom0 is None: natom0 = natom else: - assert ( - natom == natom0 - ), "The number of atoms in all frames must be the same." + assert natom == natom0, ( + "The number of atoms in all frames must be the same." + ) # Check if the number of atoms of each type is consistent across all frames atype = np.array(atype) @@ -108,9 +108,9 @@ def from_labeled_system(self, file_name: FileType, **kwargs): if natoms0 is None: natoms0 = natoms else: - assert ( - natoms == natoms0 - ), "The number of atoms of each type in all frames must be the same." + assert natoms == natoms0, ( + "The number of atoms of each type in all frames must be the same." + ) if atom_types0 is None: atom_types0 = atype atom_order = match_indices(atom_types0, atype) diff --git a/dpdata/stat.py b/dpdata/stat.py index ed74c258d..31e972306 100644 --- a/dpdata/stat.py +++ b/dpdata/stat.py @@ -55,12 +55,12 @@ class ErrorsBase(metaclass=ABCMeta): SYSTEM_TYPE = object def __init__(self, system_1: SYSTEM_TYPE, system_2: SYSTEM_TYPE) -> None: - assert isinstance( - system_1, self.SYSTEM_TYPE - ), f"system_1 should be {self.SYSTEM_TYPE.__name__}" - assert isinstance( - system_2, self.SYSTEM_TYPE - ), f"system_2 should be {self.SYSTEM_TYPE.__name__}" + assert isinstance(system_1, self.SYSTEM_TYPE), ( + f"system_1 should be {self.SYSTEM_TYPE.__name__}" + ) + assert isinstance(system_2, self.SYSTEM_TYPE), ( + f"system_2 should be {self.SYSTEM_TYPE.__name__}" + ) self.system_1 = system_1 self.system_2 = system_2 diff --git a/dpdata/vasp/outcar.py b/dpdata/vasp/outcar.py index 0fa4cb68e..08b8fce96 100644 --- a/dpdata/vasp/outcar.py +++ b/dpdata/vasp/outcar.py @@ -161,9 +161,9 @@ def analyze_block(lines, ntot, nelm, ml=False): not lines[idx + in_kB_index].split()[0:2] == ["in", "kB"] ): in_kB_index += 1 - assert idx + in_kB_index < len( - lines - ), 'ERROR: "in kB" is not found in OUTCAR. Unable to extract virial.' + assert idx + in_kB_index < len(lines), ( + 'ERROR: "in kB" is not found in OUTCAR. Unable to extract virial.' + ) tmp_v = [float(ss) for ss in lines[idx + in_kB_index].split()[2:8]] virial = np.zeros([3, 3]) virial[0][0] = tmp_v[0] diff --git a/dpdata/vasp/xml.py b/dpdata/vasp/xml.py index c99f9d320..91c29bf9c 100755 --- a/dpdata/vasp/xml.py +++ b/dpdata/vasp/xml.py @@ -7,9 +7,9 @@ def check_name(item, name): - assert ( - item.attrib["name"] == name - ), "item attrib '{}' dose not math required '{}'".format(item.attrib["name"], name) + assert item.attrib["name"] == name, ( + "item attrib '{}' dose not math required '{}'".format(item.attrib["name"], name) + ) def get_varray(varray): diff --git a/tests/comp_sys.py b/tests/comp_sys.py index a3a916a09..4a38e4d30 100644 --- a/tests/comp_sys.py +++ b/tests/comp_sys.py @@ -118,15 +118,15 @@ def _make_comp_ms_test_func(comp_sys_test_func): """ def comp_ms_test_func(iobj): - assert hasattr(iobj, "ms_1") and hasattr( - iobj, "ms_2" - ), "Multi-system objects must be present" + assert hasattr(iobj, "ms_1") and hasattr(iobj, "ms_2"), ( + "Multi-system objects must be present" + ) iobj.assertEqual(len(iobj.ms_1), len(iobj.ms_2)) keys = [ii.formula for ii in iobj.ms_1] keys_2 = [ii.formula for ii in iobj.ms_2] - assert sorted(keys) == sorted( - keys_2 - ), f"Keys of two MS are not equal: {keys} != {keys_2}" + assert sorted(keys) == sorted(keys_2), ( + f"Keys of two MS are not equal: {keys} != {keys_2}" + ) for kk in keys: iobj.system_1 = iobj.ms_1[kk] iobj.system_2 = iobj.ms_2[kk] @@ -197,17 +197,17 @@ def test_is_nopbc(self): class MSAllIsPBC: def test_is_pbc(self): - assert hasattr(self, "ms_1") and hasattr( - self, "ms_2" - ), "Multi-system objects must be present and iterable" + assert hasattr(self, "ms_1") and hasattr(self, "ms_2"), ( + "Multi-system objects must be present and iterable" + ) self.assertTrue(all([not ss.nopbc for ss in self.ms_1])) self.assertTrue(all([not ss.nopbc for ss in self.ms_2])) class MSAllIsNoPBC: def test_is_nopbc(self): - assert hasattr(self, "ms_1") and hasattr( - self, "ms_2" - ), "Multi-system objects must be present and iterable" + assert hasattr(self, "ms_1") and hasattr(self, "ms_2"), ( + "Multi-system objects must be present and iterable" + ) self.assertTrue(all([ss.nopbc for ss in self.ms_1])) self.assertTrue(all([ss.nopbc for ss in self.ms_2]))