Skip to content

Commit 8fc7273

Browse files
authored
Merge pull request #224 from pyiron/ruff
Add ruff linter
2 parents 15589ab + 8b010ec commit 8fc7273

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

44 files changed

+900
-384
lines changed

.ci_support/release.py

Lines changed: 23 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,19 @@
11
def get_setup_version_and_pattern(setup_content):
22
depend_lst, version_lst = [], []
33
for l in setup_content:
4-
if '==' in l:
5-
lst = l.split('[')[-1].split(']')[0].replace(' ', '').replace('"', '').replace("'", '').split(',')
4+
if "==" in l:
5+
lst = (
6+
l.split("[")[-1]
7+
.split("]")[0]
8+
.replace(" ", "")
9+
.replace('"', "")
10+
.replace("'", "")
11+
.split(",")
12+
)
613
for dep in lst:
7-
if dep != '\n':
8-
version_lst.append(dep.split('==')[1])
9-
depend_lst.append(dep.split('==')[0])
14+
if dep != "\n":
15+
version_lst.append(dep.split("==")[1])
16+
depend_lst.append(dep.split("==")[0])
1017

1118
version_high_dict = {d: v for d, v in zip(depend_lst, version_lst)}
1219
return version_high_dict
@@ -16,14 +23,14 @@ def get_env_version(env_content):
1623
read_flag = False
1724
depend_lst, version_lst = [], []
1825
for l in env_content:
19-
if 'dependencies:' in l:
26+
if "dependencies:" in l:
2027
read_flag = True
2128
elif read_flag:
22-
lst = l.replace('-', '').replace(' ', '').replace('\n', '').split("=")
29+
lst = l.replace("-", "").replace(" ", "").replace("\n", "").split("=")
2330
if len(lst) == 2:
2431
depend_lst.append(lst[0])
2532
version_lst.append(lst[1])
26-
return {d:v for d, v in zip(depend_lst, version_lst)}
33+
return {d: v for d, v in zip(depend_lst, version_lst)}
2734

2835

2936
def update_dependencies(setup_content, version_low_dict, version_high_dict):
@@ -35,27 +42,29 @@ def update_dependencies(setup_content, version_low_dict, version_high_dict):
3542
version_combo_dict[dep] = dep + "==" + ver
3643

3744
setup_content_new = ""
38-
pattern_dict = {d:d + "==" + v for d, v in version_high_dict.items()}
45+
pattern_dict = {d: d + "==" + v for d, v in version_high_dict.items()}
3946
for l in setup_content:
4047
for k, v in pattern_dict.items():
4148
if v in l:
4249
l = l.replace(v, version_combo_dict[k])
43-
setup_content_new +=l
50+
setup_content_new += l
4451
return setup_content_new
4552

4653

4754
if __name__ == "__main__":
48-
with open('pyproject.toml', "r") as f:
55+
with open("pyproject.toml", "r") as f:
4956
setup_content = f.readlines()
5057

51-
with open('environment.yml', "r") as f:
58+
with open("environment.yml", "r") as f:
5259
env_content = f.readlines()
5360

5461
setup_content_new = update_dependencies(
5562
setup_content=setup_content[2:],
5663
version_low_dict=get_env_version(env_content=env_content),
57-
version_high_dict=get_setup_version_and_pattern(setup_content=setup_content[2:]),
64+
version_high_dict=get_setup_version_and_pattern(
65+
setup_content=setup_content[2:]
66+
),
5867
)
5968

60-
with open('pyproject.toml', "w") as f:
69+
with open("pyproject.toml", "w") as f:
6170
f.writelines("".join(setup_content[:2]) + setup_content_new)

.pre-commit-config.yaml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
repos:
2+
- repo: https://github.com/astral-sh/ruff-pre-commit
3+
rev: v0.5.2
4+
hooks:
5+
- id: ruff
6+
name: ruff lint
7+
args: ["--select", "I", "--fix"]
8+
files: ^structuretoolkit/
9+
- id: ruff-format
10+
name: ruff format

setup.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
1-
from setuptools import setup
2-
31
import versioneer
2+
from setuptools import setup
43

54
setup(
65
version=versioneer.get_version(),
76
cmdclass=versioneer.get_cmdclass(),
8-
)
7+
)

structuretoolkit/__init__.py

Lines changed: 43 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
from . import _version
2-
31
# Analyse
42
from structuretoolkit.analyse import (
53
find_mic,
@@ -25,19 +23,59 @@
2523
get_voronoi_volumes,
2624
)
2725

26+
# Analyse - for backwards compatibility
27+
from structuretoolkit.analyse import (
28+
find_solids as analyse_find_solids,
29+
)
30+
from structuretoolkit.analyse import (
31+
get_adaptive_cna_descriptors as analyse_cna_adaptive,
32+
)
33+
from structuretoolkit.analyse import (
34+
get_centro_symmetry_descriptors as analyse_centro_symmetry,
35+
)
36+
from structuretoolkit.analyse import (
37+
get_cluster_positions as cluster_positions,
38+
)
39+
from structuretoolkit.analyse import (
40+
get_diamond_structure_descriptors as analyse_diamond_structure,
41+
)
42+
from structuretoolkit.analyse import (
43+
get_equivalent_atoms as analyse_phonopy_equivalent_atoms,
44+
)
45+
from structuretoolkit.analyse import (
46+
get_steinhardt_parameters as get_steinhardt_parameter_structure,
47+
)
48+
from structuretoolkit.analyse import (
49+
get_voronoi_volumes as analyse_voronoi_volume,
50+
)
51+
2852
# Build
2953
from structuretoolkit.build import (
3054
B2,
3155
C14,
3256
C15,
3357
C36,
3458
D03,
59+
create_mesh,
3560
get_grainboundary_info,
3661
get_high_index_surface_info,
3762
grainboundary,
3863
high_index_surface,
3964
sqs_structures,
40-
create_mesh,
65+
)
66+
67+
# Build - for backwards compatibility
68+
from structuretoolkit.build import (
69+
get_grainboundary_info as grainboundary_info,
70+
)
71+
from structuretoolkit.build import (
72+
get_high_index_surface_info as high_index_surface_info,
73+
)
74+
from structuretoolkit.build import (
75+
grainboundary as grainboundary_build,
76+
)
77+
from structuretoolkit.build import (
78+
sqs_structures as get_sqs_structures,
4179
)
4280

4381
# Common
@@ -47,35 +85,17 @@
4785
ase_to_pymatgen,
4886
ase_to_pyscal,
4987
center_coordinates_in_unit_cell,
88+
get_cell,
5089
get_extended_positions,
5190
get_vertical_length,
5291
get_wrapped_coordinates,
5392
pymatgen_to_ase,
5493
select_index,
55-
get_cell,
5694
)
5795

5896
# Visualize
5997
from structuretoolkit.visualize import plot3d
6098

61-
# Analyse - for backwards compatibility
62-
from structuretoolkit.analyse import (
63-
find_solids as analyse_find_solids,
64-
get_adaptive_cna_descriptors as analyse_cna_adaptive,
65-
get_centro_symmetry_descriptors as analyse_centro_symmetry,
66-
get_cluster_positions as cluster_positions,
67-
get_diamond_structure_descriptors as analyse_diamond_structure,
68-
get_equivalent_atoms as analyse_phonopy_equivalent_atoms,
69-
get_steinhardt_parameters as get_steinhardt_parameter_structure,
70-
get_voronoi_volumes as analyse_voronoi_volume,
71-
)
72-
73-
# Build - for backwards compatibility
74-
from structuretoolkit.build import (
75-
get_grainboundary_info as grainboundary_info,
76-
get_high_index_surface_info as high_index_surface_info,
77-
grainboundary as grainboundary_build,
78-
sqs_structures as get_sqs_structures,
79-
)
99+
from . import _version
80100

81101
__version__ = _version.get_versions()["version"]

structuretoolkit/_version.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,12 @@
1111
"""Git implementation of _version.py."""
1212

1313
import errno
14+
import functools
1415
import os
1516
import re
1617
import subprocess
1718
import sys
1819
from typing import Any, Callable, Dict, List, Optional, Tuple
19-
import functools
2020

2121

2222
def get_keywords() -> Dict[str, str]:

structuretoolkit/analyse/__init__.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,11 @@
1212
get_steinhardt_parameters,
1313
get_voronoi_volumes,
1414
)
15+
from structuretoolkit.analyse.snap import (
16+
get_snap_descriptor_derivatives,
17+
get_snap_descriptor_names,
18+
get_snap_descriptors_per_atom,
19+
)
1520
from structuretoolkit.analyse.spatial import (
1621
get_average_of_unique_labels,
1722
get_cluster_positions,
@@ -23,11 +28,6 @@
2328
get_voronoi_vertices,
2429
)
2530
from structuretoolkit.analyse.strain import get_strain
26-
from structuretoolkit.analyse.snap import (
27-
get_snap_descriptor_names,
28-
get_snap_descriptors_per_atom,
29-
get_snap_descriptor_derivatives,
30-
)
3131

3232

3333
def get_symmetry(

structuretoolkit/analyse/distance.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
from typing import Optional
2-
from ase.atoms import Atoms
2+
33
import numpy as np
4+
from ase.atoms import Atoms
45

56

67
def get_distances_array(

structuretoolkit/analyse/dscribe.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1+
from typing import Optional
2+
13
import numpy as np
24
from ase.atoms import Atoms
3-
from typing import Optional
45

56

67
def soap_descriptor_per_atom(

structuretoolkit/analyse/neighbors.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@
66
import warnings
77
from typing import Optional
88

9-
from ase.atoms import Atoms
109
import numpy as np
10+
from ase.atoms import Atoms
1111
from scipy.sparse import coo_matrix
1212
from scipy.spatial import cKDTree
1313
from scipy.spatial.transform import Rotation

structuretoolkit/analyse/phonopy.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22
# Copyright (c) Max-Planck-Institut für Eisenforschung GmbH - Computational Materials Design (CM) Department
33
# Distributed under the terms of "New BSD License", see the LICENSE file.
44

5-
from ase.atoms import Atoms
65
import numpy as np
6+
from ase.atoms import Atoms
77

88
__author__ = "Osamu Waseda"
99
__copyright__ = (

0 commit comments

Comments
 (0)