Skip to content

Commit c25580b

Browse files
authored
Fix pydantic error due to future type annotation (#310)
* pre-commit autoupdate to fix isort error in CI * remove pipe for type union in pydantic Settings model * pre-commit run black --all-files * exclude crystal_toolkit/settings.py from auto-upgrading * fix flake8 errors and skip docformatter in pre-commit.ci
1 parent 72736c6 commit c25580b

40 files changed

+19
-195
lines changed

.pre-commit-config.yaml

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
ci:
22
autoupdate_schedule: quarterly
3-
skip: [mypy, flake8]
3+
skip: [mypy, flake8, docformatter]
44

55
default_stages: [commit]
66

@@ -12,12 +12,12 @@ exclude: ^(docs/.+|.*lock.*|jupyterlab-extension/.+|.*\.(svg|js|css))$
1212

1313
repos:
1414
- repo: https://github.com/PyCQA/isort
15-
rev: 5.11.4
15+
rev: 5.12.0
1616
hooks:
1717
- id: isort
1818

1919
- repo: https://github.com/psf/black
20-
rev: 22.12.0
20+
rev: 23.1.0
2121
hooks:
2222
- id: black-jupyter
2323

@@ -32,6 +32,7 @@ repos:
3232
hooks:
3333
- id: pyupgrade
3434
args: [--py38-plus]
35+
exclude: ^crystal_toolkit/settings.py$
3536

3637
- repo: https://github.com/pre-commit/mirrors-mypy
3738
rev: v0.991
@@ -55,12 +56,12 @@ repos:
5556
stages: [commit, commit-msg]
5657

5758
- repo: https://github.com/PyCQA/autoflake
58-
rev: v2.0.0
59+
rev: v2.0.1
5960
hooks:
6061
- id: autoflake
6162

6263
- repo: https://github.com/nbQA-dev/nbQA
63-
rev: 1.6.0
64+
rev: 1.6.1
6465
hooks:
6566
- id: nbqa-pyupgrade
6667
args: [--py38-plus]
@@ -75,7 +76,7 @@ repos:
7576
args: [--drop-empty-cells, --keep-output]
7677

7778
- repo: https://github.com/PyCQA/docformatter
78-
rev: v1.5.1
79+
rev: v1.6.0.rc1
7980
hooks:
8081
- id: docformatter
8182
args: [--config, setup.cfg]

crystal_toolkit/_version.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,3 @@
1-
__version__ = "2023.01.31"
1+
from __future__ import annotations
2+
3+
__version__ = "2023.01.31"

crystal_toolkit/apps/examples/mpcontribs/catalysis.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -230,7 +230,6 @@ def get_plot_data(smile: str) -> pd.DataFrame:
230230
)
231231
@cache.memoize(timeout=60 * 60 * 24)
232232
def update_figure(smile, mid_E, range_E, active_tab):
233-
234233
# guard statement to ensure callback is not triggered unless viewing visualization
235234
if active_tab != "visualization":
236235
raise PreventUpdate
@@ -302,7 +301,6 @@ def get_visualization(self, structure):
302301
).layout()
303302

304303
def get_layout(self, payload=None):
305-
306304
tabs = dcc.Tabs(
307305
[
308306
dcc.Tab(
@@ -413,7 +411,6 @@ def get_visualization_layout(self, payload=None):
413411
return viz_div
414412

415413
def get_search_layout(self, payload=None):
416-
417414
if not payload:
418415
return self.get_catalysis_explorer()
419416

crystal_toolkit/apps/examples/tests/test_fermi_surface.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55

66

77
def test_diffraction(dash_duo: DashDuo) -> None:
8-
98
dash_duo.start_server(app)
109
dash_duo.clear_storage()
1110

crystal_toolkit/apps/main.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,6 @@
184184
if SETTINGS.MP_EMBED_MODE:
185185
mp_section: tuple[Any, ...] = (html.Div(),)
186186
else:
187-
188187
# bsdos_component = ctc.BandstructureAndDosPanelComponent(
189188
# origin_component=search_component
190189
# )
@@ -527,7 +526,6 @@ def master_update_structure(
527526
upload_data = upload_data or {}
528527

529528
if load_by == "mpid":
530-
531529
if search_mpid is None:
532530
raise PreventUpdate
533531

@@ -540,7 +538,6 @@ def master_update_structure(
540538
struct = mpr.get_structure_by_material_id(search_mpid)
541539
print("Struct from material.")
542540
else:
543-
544541
struct = MPComponent.from_data(upload_data["data"])
545542

546543
return struct

crystal_toolkit/components/bandstructure.py

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,6 @@ def __init__(
5050
id: str = None,
5151
**kwargs,
5252
) -> None:
53-
5453
# this is a compound component, can be fed by mpid or
5554
# by the BandStructure itself
5655
super().__init__(
@@ -65,7 +64,6 @@ def __init__(
6564

6665
@property
6766
def _sub_layouts(self) -> dict[str, Component]:
68-
6967
# defaults
7068
state = {"label-select": "lm", "dos-select": "ap"}
7169

@@ -191,9 +189,7 @@ def _get_bs_dos(
191189
return None, None
192190

193191
if mpid:
194-
195192
with MPRester() as mpr:
196-
197193
try:
198194
bandstructure_symm_line = mpr.get_bandstructure_by_material_id(mpid)
199195
except Exception as exc:
@@ -207,7 +203,6 @@ def _get_bs_dos(
207203
density_of_states = None
208204

209205
else:
210-
211206
if bandstructure_symm_line and isinstance(bandstructure_symm_line, dict):
212207
bandstructure_symm_line = BandStructureSymmLine.from_dict(
213208
bandstructure_symm_line
@@ -224,7 +219,6 @@ def get_ifermi_scene(bs: BandStructure) -> Scene:
224219

225220
@staticmethod
226221
def get_brillouin_zone_scene(bs: BandStructureSymmLine) -> Scene:
227-
228222
if not bs:
229223
return Scene(name="brillouin_zone", contents=[])
230224

@@ -281,7 +275,6 @@ def get_brillouin_zone_scene(bs: BandStructureSymmLine) -> Scene:
281275
vbm = bs.get_vbm()["kpoint"]
282276

283277
if cbm and vbm:
284-
285278
if cbm.label:
286279
cbm_label = cbm.label
287280
for orig, new in pretty_labels.items():
@@ -325,7 +318,6 @@ def get_brillouin_zone_scene(bs: BandStructureSymmLine) -> Scene:
325318
def get_bandstructure_traces(
326319
bs, path_convention: str, energy_window: tuple[float, float] = (-6.0, 10.0)
327320
) -> tuple:
328-
329321
if path_convention == "lm":
330322
bs = HighSymmKpath.get_continuous_path(bs)
331323

@@ -350,7 +342,6 @@ def get_bandstructure_traces(
350342
vbm_new = bs_data["vbm"]
351343

352344
for d, dist_val in enumerate(bs_data["distances"]):
353-
354345
x_dat = dist_val
355346

356347
traces_for_segment = []
@@ -474,7 +465,6 @@ def get_dos_traces(
474465
energy_window: tuple[float, float] = (-6.0, 10.0),
475466
horizontal: bool = False,
476467
) -> list:
477-
478468
if horizontal:
479469
dos_axis, en_axis = "y", "x"
480470
else:
@@ -548,7 +538,6 @@ def get_dos_traces(
548538
]
549539

550540
for label in proj_data:
551-
552541
if spin_polarized:
553542
trace = {
554543
dos_axis: -1.0
@@ -594,9 +583,7 @@ def get_figure(
594583
bs_domain=None,
595584
dos_domain=None,
596585
) -> go.Figure:
597-
598586
if (not dos) and (not bs):
599-
600587
empty_plot_style = {
601588
"xaxis": {"visible": False},
602589
"yaxis": {"visible": False},
@@ -777,7 +764,6 @@ def get_figure(
777764

778765
@staticmethod
779766
def _get_data_list_dict(bs, dos):
780-
781767
return {
782768
"Band Gap": "... eV",
783769
"Direct Gap": "...",
@@ -791,7 +777,6 @@ def generate_callbacks(self, app, cache):
791777
Output(self.id("bsdos-div"), "children"), [Input(self.id("traces"), "data")]
792778
)
793779
def update_graph(traces):
794-
795780
if traces == "error":
796781
body = MessageBody(
797782
dcc.Markdown(
@@ -822,7 +807,6 @@ def update_label_select(mpid, path_convention):
822807
if not mpid:
823808
raise PreventUpdate
824809
else:
825-
826810
label_value = path_convention
827811
label_style = {"maxWidth": "200"}
828812

@@ -887,7 +871,6 @@ def update_select(elements, mpid):
887871
Input(self.id("label-select"), "value"),
888872
)
889873
def bs_dos_data(data, path_convention, dos_select, label_select):
890-
891874
# Obtain bands to plot over and generate traces for bs data:
892875
energy_window = (-6.0, 10.0)
893876

crystal_toolkit/components/diffraction.py

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,6 @@ def grain_to_hwhm(
155155

156156
@property
157157
def _sub_layouts(self) -> dict[str, Component]:
158-
159158
state = {
160159
"peak_profile": "G",
161160
"shape_factor": 0.94,
@@ -339,7 +338,6 @@ def get_figure(
339338
x_axis,
340339
broadening=True,
341340
) -> go.Figure:
342-
343341
hkl_list = [hkl[0]["hkl"] for hkl in hkls]
344342
# convert to (h k l) format
345343
hkls = [f"hkl: ({' '.join(map(str, hkl))})" for hkl in hkl_list]
@@ -434,7 +432,6 @@ def generate_callbacks(self, app, cache):
434432
],
435433
)
436434
def update_graph(data, logsize, rad_source, peak_profile, K, x_axis, structure):
437-
438435
if not data:
439436
raise PreventUpdate
440437

@@ -480,7 +477,6 @@ def update_graph(data, logsize, rad_source, peak_profile, K, x_axis, structure):
480477
],
481478
)
482479
def pattern_from_struct(struct, rad_source):
483-
484480
if struct is None or not rad_source:
485481
raise PreventUpdate
486482

crystal_toolkit/components/diffraction_tem.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,6 @@ def generate_callbacks(self, app, cache):
188188
],
189189
)
190190
def generate_diffraction_pattern(structure, *args):
191-
192191
structure = self.from_data(structure)
193192
kwargs = self.reconstruct_kwargs_from_state()
194193

0 commit comments

Comments
 (0)