Skip to content

Commit

Permalink
Merge pull request #395 from materialsproject/fix-pyproject
Browse files Browse the repository at this point in the history
Fix `pyproject.toml` malformed `[build-system] requires`
  • Loading branch information
janosh authored Jun 9, 2024
2 parents c1f0aed + 647985c commit 9d0f896
Show file tree
Hide file tree
Showing 13 changed files with 97 additions and 187 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ jobs:
python${{ matrix.python-version }} -m pip install -r requirements/ubuntu-latest_py${{ matrix.python-version }}_extras.txt
python${{ matrix.python-version }} -m pip install --upgrade pip
python${{ matrix.python-version }} -m pip install --no-deps .[server]
- name: Build package
run: python${{ matrix.python-version }} -m build

Expand Down
8 changes: 4 additions & 4 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ exclude: ^(docs/.+|.*lock.*|jupyterlab-extension/.+|.*\.(svg|js|css))|_version.p

repos:
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.1.5
rev: v0.4.8
hooks:
- id: ruff
args: [--fix, --ignore, D]
Expand All @@ -23,7 +23,7 @@ repos:
# - id: mypy

- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.5.0
rev: v4.6.0
hooks:
- id: check-case-conflict
- id: check-symlinks
Expand All @@ -33,14 +33,14 @@ repos:
- id: trailing-whitespace

- repo: https://github.com/codespell-project/codespell
rev: v2.2.6
rev: v2.3.0
hooks:
- id: codespell
stages: [commit, commit-msg]
args: [--ignore-words-list, "nd,te,ois,dscribe", --check-filenames]

- repo: https://github.com/kynan/nbstripout
rev: 0.6.1
rev: 0.7.1
hooks:
- id: nbstripout
args: [--drop-empty-cells, --keep-output]
35 changes: 13 additions & 22 deletions crystal_toolkit/apps/examples/tests/typing.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,42 +16,33 @@ class DashDuo(Protocol):

# driver = ... # selenium.webdriver.remote.WebDriver

def start_server(self, start_server) -> None:
...
def start_server(self, start_server) -> None: ...

def find_element(self, selector: str) -> dash.development.base_component.Component:
...
def find_element(
self, selector: str
) -> dash.development.base_component.Component: ...

def wait_for_text_to_equal(
self, selector: str, text: str, timeout: int | None = None
) -> None:
...
) -> None: ...

def get_logs(self) -> list[str]:
...
def get_logs(self) -> list[str]: ...

def clear_storage(self) -> None:
...
def clear_storage(self) -> None: ...

def percy_snapshot(self, name: str, wait_for_callbacks: bool = False) -> None:
...
def percy_snapshot(self, name: str, wait_for_callbacks: bool = False) -> None: ...

def multiple_click(self, selector: str, clicks: int) -> None:
...
def multiple_click(self, selector: str, clicks: int) -> None: ...

def wait_for_element(self, selector: str, timeout: int | None = None) -> None:
...
def wait_for_element(self, selector: str, timeout: int | None = None) -> None: ...

def take_snapshot(self, name: str) -> None:
...
def take_snapshot(self, name: str) -> None: ...

def wait_for_page(self, url: str | None = None, timeout: int = 10) -> None:
...
def wait_for_page(self, url: str | None = None, timeout: int = 10) -> None: ...

def find_elements(
self, selector: str
) -> list[dash.development.base_component.Component]:
...
) -> list[dash.development.base_component.Component]: ...

def select_dcc_dropdown(
self,
Expand Down
5 changes: 1 addition & 4 deletions crystal_toolkit/components/bandstructure.py
Original file line number Diff line number Diff line change
Expand Up @@ -523,7 +523,6 @@ def get_dos_traces(
raise PreventUpdate

# Projected DOS
count = 0
colors = [
"#d62728", # brick red
"#2ca02c", # cooked asparagus green
Expand All @@ -534,7 +533,7 @@ def get_dos_traces(
"#e377c2", # raspberry yogurt pink
]

for label in proj_data:
for count, label in enumerate(proj_data):
if spin_polarized:
trace = {
dos_axis: -1.0
Expand Down Expand Up @@ -565,8 +564,6 @@ def get_dos_traces(

dos_traces.append(trace)

count += 1

return dos_traces

@staticmethod
Expand Down
7 changes: 2 additions & 5 deletions crystal_toolkit/components/phonon.py
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ def layout(self) -> html.Div:

@staticmethod
def _get_ph_bs_dos(
data: dict[str, Any] | None
data: dict[str, Any] | None,
) -> tuple[PhononBandStructureSymmLine, CompletePhononDos]:
data = data or {}

Expand Down Expand Up @@ -399,7 +399,6 @@ def get_ph_dos_traces(dos: CompletePhononDos, freq_range: tuple[float, float]):
dos_traces.append(trace_tdos)

# Projected DOS
count = 0
colors = [
"#d62728", # brick red
"#2ca02c", # cooked asparagus green
Expand All @@ -411,7 +410,7 @@ def get_ph_dos_traces(dos: CompletePhononDos, freq_range: tuple[float, float]):
]

ele_dos = dos.get_element_dos() # project DOS onto elements
for label in ele_dos:
for count, label in enumerate(ele_dos):
spin_up_label = str(label)

trace = {
Expand All @@ -426,8 +425,6 @@ def get_ph_dos_traces(dos: CompletePhononDos, freq_range: tuple[float, float]):

dos_traces.append(trace)

count += 1

return dos_traces

@staticmethod
Expand Down
34 changes: 8 additions & 26 deletions crystal_toolkit/core/jupyter.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,10 @@ class _JupyterRenderer:

@staticmethod
def _find_available_port():
"""
Find an available port.
"""Find an available port.
Thank you Mihai Capotă, https://stackoverflow.com/a/61685162
"""

import socketserver

with socketserver.TCPServer(("localhost", 0), None) as s:
Expand All @@ -46,10 +44,7 @@ def _find_available_port():
# check docs about proxy settings

def run(self, layout):
"""
Run Dash app.
"""

"""Run Dash app."""
app = Dash(plugins=[CrystalToolkitPlugin(layout=layout)])

port = SETTINGS.JUPYTER_EMBED_PORT or self._find_available_port()
Expand All @@ -63,10 +58,7 @@ def run(self, layout):
app.run(port=free_port, jupyter_mode=SETTINGS.JUPYTER_EMBED_MODE)

def display(self, obj):
"""
Display a provided object.
"""

"""Display a provided object."""
for kls, component in self.registry.items():
if isinstance(obj, kls):
layout = ctl.Block(
Expand All @@ -79,35 +71,27 @@ def display(self, obj):


def _to_plotly_json(self):
"""
Patch to ensure MSONable objects can be serialized into JSON by plotly tools.
"""
"""Patch to ensure MSONable objects can be serialized into JSON by plotly tools."""
return self.as_dict()


def _display_json(self, **kwargs):
"""
Display JSON representation of an MSONable object inside Jupyter.
"""
"""Display JSON representation of an MSONable object inside Jupyter."""
from IPython.display import JSON

JSON(self.as_dict(), **kwargs)


def _repr_mimebundle_(self, include=None, exclude=None):
"""
Method used by Jupyter. A default for MSONable objects to return JSON representation.
"""
"""Method used by Jupyter. A default for MSONable objects to return JSON representation."""
return {
"application/json": self.as_dict(),
"text/plain": repr(self),
}


def _ipython_display_(self):
"""
Display MSONable objects using a Crystal Toolkit component, if available.
"""
"""Display MSONable objects using a Crystal Toolkit component, if available."""
from IPython.display import publish_display_data

if any(isinstance(self, x) for x in _JupyterRenderer.registry):
Expand Down Expand Up @@ -140,11 +124,9 @@ def _ipython_display_(self):


def patch_msonable():
"""
Patch MSONable to allow MSONable objects to render in Jupyter
"""Patch MSONable to allow MSONable objects to render in Jupyter
environments using Crystal Toolkit components.
"""

from monty.json import MSONable

MSONable.to_plotly_json = _to_plotly_json
Expand Down
2 changes: 1 addition & 1 deletion crystal_toolkit/core/mpcomponent.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
CT_NAMESPACE = "CT"


class MPComponent(ABC):
class MPComponent(ABC): # noqa: B024
"""The abstract base class for an MPComponent.
MPComponent is designed to help render an MSONable object.
Expand Down
14 changes: 4 additions & 10 deletions crystal_toolkit/core/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,7 @@


class CrystalToolkitPlugin:
"""
Enables Crystal Toolkit components to work with your Dash app.
"""Enables Crystal Toolkit components to work with your Dash app.
This is a replacement for the previous `register_crystal_toolkit`
function, to instead use Dash's native plugin system.
Expand All @@ -27,8 +26,7 @@ class CrystalToolkitPlugin:
def __init__(
self, layout, cache: Cache | None = None, use_default_css=True
) -> None:
"""
Provide your initial app layout.
"""Provide your initial app layout.
Provide a cache to improve performance. If running
in debug mode, the cache will be automatically disabled. If
Expand All @@ -51,9 +49,7 @@ def __init__(
self.use_default_css = use_default_css

def plug(self, app: Dash):
"""
Initialize Crystal Toolkit plugin for the specified Dash app.
"""
"""Initialize Crystal Toolkit plugin for the specified Dash app."""
self.app = app
self.cache.init_app(app.server)

Expand Down Expand Up @@ -83,15 +79,13 @@ def plug(self, app: Dash):
app.config.external_stylesheets.append(font_awesome_css)

def crystal_toolkit_layout(self, layout) -> html.Div:
"""
Crystal Toolkit currently requires a set of dcc.Store components
"""Crystal Toolkit currently requires a set of dcc.Store components
to be added to the layout in order to function.
Eventually, it is hoped to remove the need for this method through
use of All-in-One components. All-in-One components were not yet
available when Crystal Toolkit was first developed.
"""

from crystal_toolkit.core.mpcomponent import MPComponent

# Crystal Toolkit has not been tested with dynamic layouts
Expand Down
1 change: 1 addition & 0 deletions crystal_toolkit/defaults.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Populate the default values from the JSON file."""

from __future__ import annotations

import json
Expand Down
1 change: 1 addition & 0 deletions crystal_toolkit/helpers/asymptote_renderer.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
TODO The code should also append a set of special points at the end in case the user wants to add
more "hand drawn" features to the plot.
"""

from __future__ import annotations

import logging
Expand Down
Loading

0 comments on commit 9d0f896

Please sign in to comment.