Skip to content

Commit 7098073

Browse files
authored
Merge pull request #272 from materialsproject/pre-commit
`pre-commit` hooks
2 parents 3626ccb + 0d3e20b commit 7098073

File tree

93 files changed

+733
-737
lines changed

Some content is hidden

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

93 files changed

+733
-737
lines changed

.github/workflows/pytest_docs.yml

-1
Original file line numberDiff line numberDiff line change
@@ -50,4 +50,3 @@ jobs:
5050
PERCY_TOKEN: ${{ secrets.PERCY_TOKEN }}
5151
run: |
5252
poetry run pytest --color=yes --webdriver Firefox --headless crystal_toolkit/apps/examples/tests/
53-

.github/workflows/release.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
name: release
22

3-
on:
3+
on:
44
workflow_dispatch
55

66
jobs:

.pre-commit-config.yaml

+80-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,83 @@
1+
ci:
2+
autoupdate_schedule: quarterly
3+
4+
default_stages: [commit]
5+
6+
default_install_hook_types: [pre-commit, commit-msg]
7+
8+
# ignore generated doc and dependency lock files
9+
exclude: ^(docs/.+|.*lock.*)$
10+
111
repos:
2-
- repo: https://github.com/ambv/black
12+
- repo: https://github.com/PyCQA/isort
13+
rev: 5.10.1
14+
hooks:
15+
- id: isort
16+
17+
- repo: https://github.com/psf/black
318
rev: 22.6.0
419
hooks:
5-
- id: black
20+
- id: black-jupyter
21+
22+
- repo: https://github.com/PyCQA/flake8
23+
rev: 4.0.1
24+
hooks:
25+
- id: flake8
26+
27+
- repo: https://github.com/asottile/pyupgrade
28+
rev: v2.34.0
29+
hooks:
30+
- id: pyupgrade
31+
args: [--py38-plus]
32+
33+
- repo: https://github.com/pre-commit/mirrors-mypy
34+
rev: v0.961
35+
hooks:
36+
- id: mypy
37+
38+
- repo: https://github.com/pre-commit/pre-commit-hooks
39+
rev: v4.3.0
40+
hooks:
41+
- id: check-case-conflict
42+
- id: check-symlinks
43+
- id: check-yaml
44+
- id: destroyed-symlinks
45+
- id: end-of-file-fixer
46+
exclude: ^assets/.+\.(svg|html)$
47+
- id: mixed-line-ending
48+
- id: trailing-whitespace
49+
50+
- repo: https://github.com/codespell-project/codespell
51+
rev: v2.1.0
52+
hooks:
53+
- id: codespell
54+
stages: [commit, commit-msg]
55+
exclude_types: [csv, svg, html, yaml, jupyter]
56+
57+
- repo: local
58+
hooks:
59+
- id: svg-assets
60+
name: SVG assets
61+
entry: Files under assets/* must end in .(svg|html)
62+
language: fail
63+
files: ^assets/.*(?<!\.svg)(?<!\.html)$
64+
65+
- repo: https://github.com/myint/autoflake
66+
rev: v1.4
67+
hooks:
68+
- id: autoflake
69+
args:
70+
- --in-place
71+
- --remove-unused-variables
72+
- --remove-all-unused-imports
73+
- --expand-star-imports
74+
- --ignore-init-module-imports
75+
76+
- repo: https://github.com/nbQA-dev/nbQA
77+
rev: 1.3.1
78+
hooks:
79+
- id: nbqa-pyupgrade
80+
args: [--py38-plus]
81+
- id: nbqa-isort
82+
- id: nbqa-flake8
83+
args: [--ignore=E402]

README.md

+3-3
Original file line numberDiff line numberDiff line change
@@ -41,16 +41,16 @@ New contributors are welcome, please see our [Code of Conduct.](code-of-conduct.
4141

4242
The Crystal Toolkit repo currently contains three major parts:
4343

44-
* An object-orientated Python framework for rendering materials science data based on the schema employed by the Materials Proejct
44+
* An object-orientated Python framework for rendering materials science data based on the schema employed by the Materials Project
4545
* A few custom Plotly Dash components (Simple3DSceneComponent, JSONComponent, GraphComponent)
4646
* Some example apps using these components
4747

4848
It is likely the custom Plotly Dash components might be spun off into a separate repo at some point to reduce the complexity of the Crystal Toolkit repo itself.
4949

5050
## Acknowledgements
5151

52-
Thank you to all the authors and maintainers of the libraries Crystal Toolkit
53-
depends upon, and in particular [pymatgen](http://pymatgen.org) for crystallographic
52+
Thank you to all the authors and maintainers of the libraries Crystal Toolkit
53+
depends upon, and in particular [pymatgen](http://pymatgen.org) for crystallographic
5454
analysis and [Dash from Plotly](https://plot.ly/products/dash/) for their web app framework.
5555

5656
Thank you to the [NERSC Spin](http://www.nersc.gov/users/data-analytics/spin/) service for

code-of-conduct.md

-1
Original file line numberDiff line numberDiff line change
@@ -46,4 +46,3 @@ This Code of Conduct is adapted from the [Contributor Covenant][homepage],
4646
version 1.3.0, available at https://www.contributor-covenant.org/version/1/3/0/code-of-conduct.html
4747

4848
[homepage]: https://www.contributor-covenant.org
49-

crystal_toolkit/__init__.py

+16-4
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,24 @@
1+
from __future__ import annotations
2+
13
import json
24
import os as _os
35
from collections import defaultdict
46
from pathlib import Path
7+
from typing import Any
58

69
# pleasant hack to support MSONable objects in Dash callbacks natively
710
from monty.json import MSONable
811

9-
from crystal_toolkit.renderables import *
12+
from crystal_toolkit.renderables import (
13+
Lattice,
14+
Molecule,
15+
MoleculeGraph,
16+
PhaseDiagram,
17+
Site,
18+
Structure,
19+
StructureGraph,
20+
VolumetricData,
21+
)
1022

1123
__version__ = "2022.07.25"
1224

@@ -21,7 +33,7 @@ def to_plotly_json(self):
2133

2234

2335
# Populate the default values from the JSON file
24-
_DEFAULTS = defaultdict(lambda: None)
36+
_DEFAULTS: dict[str, Any] = defaultdict()
2537
default_js = _os.path.join(
2638
_os.path.join(_os.path.dirname(_os.path.abspath(__file__))), "./", "defaults.json"
2739
)
@@ -43,8 +55,8 @@ def _repr_mimebundle_(self, include=None, exclude=None):
4355
This only works in Jupyter Lab 3.x or above.\n\n
4456
"""
4557

46-
help_text_plotly = """If you see this text, the Plotly Jupyter Lab extension
47-
is not installed, please consult Plotly documentation for information on how to
58+
help_text_plotly = """If you see this text, the Plotly Jupyter Lab extension
59+
is not installed, please consult Plotly documentation for information on how to
4860
install.
4961
"""
5062

Original file line numberDiff line numberDiff line change
@@ -1,7 +1,3 @@
1-
2-
3-
41
body, html, .body {
52
background: #f3f3f3 !important;
63
}
7-
+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
{"10.26434/chemrxiv.11294480.v1": "D. Waroquiers, J. George, M. Horton, S. Schenk, K. Persson, G.-M. Rignanese, X. Gonze, and G. Hautier, \u201cChemEnv\u202f: A Fast and Robust Coordination Environment Identification Tool,\u201d Dec. 2019.\n", "10.3389/fmats.2017.00034": "N. E. R. Zimmermann, M. K. Horton, A. Jain, and M. Haranczyk, \u201cAssessing Local Structure Motifs Using Order Parameters for Motif Recognition, Interstitial Identification, and Diffusion Path Characterization,\u201d Frontiers in Materials, vol. 4, Nov. 2017.\n"}
1+
{"10.26434/chemrxiv.11294480.v1": "D. Waroquiers, J. George, M. Horton, S. Schenk, K. Persson, G.-M. Rignanese, X. Gonze, and G. Hautier, \u201cChemEnv\u202f: A Fast and Robust Coordination Environment Identification Tool,\u201d Dec. 2019.\n", "10.3389/fmats.2017.00034": "N. E. R. Zimmermann, M. K. Horton, A. Jain, and M. Haranczyk, \u201cAssessing Local Structure Motifs Using Order Parameters for Motif Recognition, Interstitial Identification, and Diffusion Path Characterization,\u201d Frontiers in Materials, vol. 4, Nov. 2017.\n"}

crystal_toolkit/apps/assets/task_ids_on_load.json

+1-1
Large diffs are not rendered by default.

crystal_toolkit/apps/examples/GaN_bs.json

+1-1
Large diffs are not rendered by default.

crystal_toolkit/apps/examples/GaN_dos.json

+1-1
Large diffs are not rendered by default.

crystal_toolkit/apps/examples/Si_bs.json

+1-1
Large diffs are not rendered by default.

crystal_toolkit/apps/examples/Si_dos.json

+1-1
Large diffs are not rendered by default.

crystal_toolkit/apps/examples/bandstructure.py

+7-10
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,14 @@
1-
# standard Dash imports
2-
import dash
3-
from dash import html
4-
from dash import dcc
1+
import os
52

6-
# standard Crystal Toolkit import
7-
import crystal_toolkit.components as ctc
8-
from crystal_toolkit.settings import SETTINGS
9-
from crystal_toolkit.helpers.layouts import H1, H2, Container
3+
import dash
104

115
# dos and bs data from local jsons
126
from monty.serialization import loadfn
13-
import os
147

8+
# standard Crystal Toolkit import
9+
import crystal_toolkit.components as ctc
10+
from crystal_toolkit.helpers.layouts import H1, Container
11+
from crystal_toolkit.settings import SETTINGS
1512

1613
# create Dash app as normal, assets folder set for visual styles only
1714
app = dash.Dash(assets_folder=SETTINGS.ASSETS_PATH)
@@ -35,7 +32,7 @@
3532

3633
# example layout to demonstrate capabilities of component
3734
my_layout = Container(
38-
[H1("Band Structure and Density of States Example"), bsdos_component.layout(),]
35+
[H1("Band Structure and Density of States Example"), bsdos_component.layout()]
3936
)
4037

4138
# wrap your app.layout with crystal_toolkit_layout()

crystal_toolkit/apps/examples/basic_hello_world.py

-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
1-
# standard Dash imports
21
import dash
32
from dash import html
4-
from dash import dcc
53

64
# standard Crystal Toolkit import
75
import crystal_toolkit.components as ctc

crystal_toolkit/apps/examples/diffraction.py

+5-12
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,17 @@
1-
# standard Dash imports
21
import dash
3-
from dash import html
4-
from dash import dcc
2+
3+
# create our crystal structure using pymatgen
4+
from pymatgen.core.lattice import Lattice
5+
from pymatgen.core.structure import Structure
56

67
# standard Crystal Toolkit import
78
import crystal_toolkit.components as ctc
8-
from crystal_toolkit.settings import SETTINGS
99
from crystal_toolkit.helpers.layouts import H1, H3, Container
10-
11-
# import for this example
12-
from pymatgen.ext.matproj import MPRester
13-
from pymatgen.analysis.phase_diagram import PhaseDiagram
14-
from pymatgen.analysis.diffraction.xrd import XRDCalculator
10+
from crystal_toolkit.settings import SETTINGS
1511

1612
# create Dash app as normal
1713
app = dash.Dash(assets_folder=SETTINGS.ASSETS_PATH)
1814

19-
# create our crystal structure using pymatgen
20-
from pymatgen.core.structure import Structure
21-
from pymatgen.core.lattice import Lattice
2215

2316
structure = Structure(Lattice.cubic(4.2), ["Na", "K"], [[0, 0, 0], [0.5, 0.5, 0.5]])
2417

crystal_toolkit/apps/examples/diffraction_dynamic.py

-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
# standard Dash imports
21
import dash
32
from dash.dependencies import Input, Output
43

crystal_toolkit/apps/examples/diffraction_empty.py

+6-16
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,24 @@
1-
# standard Dash imports
21
import dash
3-
from dash import html
4-
from dash import dcc
2+
3+
# create our crystal structure using pymatgen
4+
from pymatgen.core.lattice import Lattice
5+
from pymatgen.core.structure import Structure
56

67
# standard Crystal Toolkit import
78
import crystal_toolkit.components as ctc
9+
from crystal_toolkit.helpers.layouts import H1, Container
810
from crystal_toolkit.settings import SETTINGS
9-
from crystal_toolkit.helpers.layouts import H1, H2, Container
10-
11-
# import for this example
12-
from pymatgen.core.structure import Structure
13-
from pymatgen.core.lattice import Lattice
14-
from pymatgen.ext.matproj import MPRester
15-
from pymatgen.analysis.phase_diagram import PhaseDiagram
16-
from pymatgen.analysis.diffraction.xrd import XRDCalculator
1711

1812
# create Dash app as normal
1913
app = dash.Dash(assets_folder=SETTINGS.ASSETS_PATH)
2014

21-
# create our crystal structure using pymatgen
22-
from pymatgen.core.structure import Structure
23-
from pymatgen.core.lattice import Lattice
24-
2515
structure = Structure(Lattice.cubic(4.2), ["Na", "K"], [[0, 0, 0], [0.5, 0.5, 0.5]])
2616

2717
xrd_component = ctc.XRayDiffractionComponent()
2818

2919
# example layout to demonstrate capabilities of component
3020
my_layout = Container(
31-
[H1("XRDComponent Example (Empty, No Structure Defined)"), xrd_component.layout(),]
21+
[H1("XRDComponent Example (Empty, No Structure Defined)"), xrd_component.layout()]
3222
)
3323

3424
# as explained in "preamble" section in documentation

crystal_toolkit/apps/examples/kwarg_inputs.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
import random
22

33
import dash
4-
from dash import html, dcc, Input, Output
5-
4+
from dash import Input, Output, dcc, html
65
from dash.exceptions import PreventUpdate
76

87
import crystal_toolkit.components as ctc

crystal_toolkit/apps/examples/phase_diagram.py

+2-6
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,7 @@
1-
# standard Dash imports
21
import dash
3-
from dash import dcc
4-
from dash import html
5-
6-
# import for this example
7-
from pymatgen.ext.matproj import MPRester
2+
from dash import dcc, html
83
from pymatgen.analysis.phase_diagram import PhaseDiagram
4+
from pymatgen.ext.matproj import MPRester
95

106
# standard Crystal Toolkit import
117
import crystal_toolkit.components as ctc

crystal_toolkit/apps/examples/pourbaix.py

+1-5
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,5 @@
1-
# standard Dash imports
21
import dash
3-
from dash import dcc
42
from dash import html
5-
6-
# import for this example
73
from pymatgen.ext.matproj import MPRester
84

95
# standard Crystal Toolkit import
@@ -30,7 +26,7 @@
3026
html.H1("PourbaixDiagramComponent Example"),
3127
html.Button("Get Pourbaix Diagram", id="get-pourbaix"),
3228
pourbaix_component.layout(),
33-
html.Div(id="pourbaix-output")
29+
html.Div(id="pourbaix-output"),
3430
]
3531
)
3632

crystal_toolkit/apps/examples/structure.py

-3
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,5 @@
1-
# standard Dash imports
21
import dash
32
from dash import html
4-
5-
# import for this example
63
from pymatgen.core.lattice import Lattice
74
from pymatgen.core.structure import Structure
85

crystal_toolkit/apps/examples/structure_magnetic.py

+1-6
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,7 @@
1-
# standard Dash imports
21
import dash
3-
from dash import dcc
42
from dash import html
5-
6-
# import for this example
7-
from pymatgen.core.structure import Structure
83
from pymatgen.core.lattice import Lattice
9-
from pymatgen.electronic_structure.core import Magmom
4+
from pymatgen.core.structure import Structure
105

116
# standard Crystal Toolkit import
127
import crystal_toolkit.components as ctc

crystal_toolkit/apps/examples/tests/test_bandstructure.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1-
from crystal_toolkit.apps.examples.bandstructure import app
21
import time
32

3+
from crystal_toolkit.apps.examples.bandstructure import app
4+
45

56
def test_bs(dash_duo):
67

crystal_toolkit/apps/examples/tests/test_basic.py

+2-6
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,9 @@
1-
from crystal_toolkit.apps.examples.basic_hello_world import app as hello_world_app
2-
from crystal_toolkit.apps.examples.basic_hello_structure import (
3-
app as hello_structure_app,
4-
)
1+
import time
2+
53
from crystal_toolkit.apps.examples.basic_hello_structure_interactive import (
64
app as hello_structure_interactive_app,
75
)
86

9-
import time
10-
117
#
128
# def test_hello_scientist(dash_duo):
139
#

crystal_toolkit/apps/examples/tests/test_structure.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1-
from crystal_toolkit.apps.examples.structure import app
21
import time
32

3+
from crystal_toolkit.apps.examples.structure import app
4+
45

56
def test_structure(dash_duo):
67

0 commit comments

Comments
 (0)