Skip to content

Commit

Permalink
refactor jupyterlab-extension/crystaltoolkit-extension/_version.py
Browse files Browse the repository at this point in the history
  • Loading branch information
janosh committed May 13, 2023
1 parent 29ba7f7 commit 0a9a61a
Show file tree
Hide file tree
Showing 8 changed files with 22 additions and 23 deletions.
2 changes: 1 addition & 1 deletion SECURITY.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@

We are a small, academic project without a formal security process.

If you find a security vulnerability, please contact [email protected] and CC [email protected].
If you find a security vulnerability, please contact <[email protected]> and CC <[email protected]>.

PGP keys can be made available on request.
2 changes: 1 addition & 1 deletion crystal_toolkit/_version.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = "2023.05.13"
__version__ = "2023.05.13"
Original file line number Diff line number Diff line change
Expand Up @@ -68,11 +68,11 @@ def trigger_new_data(url):
)
def save_image(image_data_timestamp, url, image_data):
if image_data:
# print(image_data.strip("data:image/png;base64,")[-1:-100])
# image_bytes = b64decode(image_data.strip("data:image/png;base64,").encode('ascii'))
# print(image_data.strip("data:image/png;base64,")[-1:-100])
# image_bytes = b64decode(image_data.strip("data:image/png;base64,").encode('ascii'))
response = urllib.request.urlopen(image_data)
with open(SCREENSHOT_PATH / f"{url[1:]}.png", "wb") as f:
f.write(response.file.read())
with open(SCREENSHOT_PATH / f"{url[1:]}.png", "wb") as file:
file.write(response.file.read())


ctc.register_crystal_toolkit(app=app, layout=my_layout)
Expand Down
6 changes: 3 additions & 3 deletions crystal_toolkit/apps/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -427,13 +427,13 @@

@app.callback(Output(search_component.id("input"), "value"), Input("url", "href"))
def update_search_term_on_page_load(href: str) -> str:
"""If an mpid is provided in the url, load that mpid. Otherwise load a random mpid from the
"""If an MP ID is provided in the url, load that MP ID. Otherwise load a random MP ID from the
DEFAULT_MPIDS global variable.
Args:
href: e.g. "http://localhost:8050/mp-11358"
Returns: an mpid
Returns: an MP ID
"""
if href is None:
raise PreventUpdate
Expand All @@ -454,7 +454,7 @@ def update_search_term_on_page_load(href: str) -> str:
def perform_search_on_page_load(
search_term: str, n_submit: int | None
) -> tuple[int, int]:
"""Loading with an mpid in the URL requires populating the search term with the mpid, this
"""Loading with an MP ID in the URL requires populating the search term with the MP ID, this
callback forces that search to then take place by force updating n_submit and n_submit_timestamp
props.
Expand Down
2 changes: 1 addition & 1 deletion crystal_toolkit/components/phase_diagram.py
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,7 @@ def create_markers(self, plotter, pd):

if dim == 4:
z_list.append(coord[2])
text.append(f"{clean_formula} ({mpid})<br> {str(energy)} eV")
text.append(f"{clean_formula} ({mpid})<br> {energy} eV")

if dim == 2 or dim == 3:
marker_plot = go.Scatter(
Expand Down
4 changes: 2 additions & 2 deletions crystal_toolkit/core/scene.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,8 +125,8 @@ def to(self, filename):
# TODO: find a way to keep the original MSONable object + scene generation options alongside
if not filename.endswith(".ctk.json"):
filename += ".ctk.json"
with open(filename, "w") as f:
dump(self.to_json(), f)
with open(filename, "w") as file:
dump(self.to_json(), file)

@property
def bounding_box(self) -> list[list[float]]:
Expand Down
13 changes: 6 additions & 7 deletions jupyterlab-extension/crystaltoolkit-extension/_version.py
Original file line number Diff line number Diff line change
@@ -1,20 +1,19 @@
__all__ = ["__version__"]
import json
import os


def _fetch_version():
import json
import os

HERE = os.path.abspath(os.path.dirname(__file__))

for d, _, _ in os.walk(HERE):
for folder, _, _ in os.walk(HERE):
try:
with open(os.path.join(d, "package.json")) as f:
return json.load(f)["version"]
with open(os.path.join(folder, "package.json")) as file:
return json.load(file)["version"]
except FileNotFoundError:
pass

raise FileNotFoundError(f"Could not find package.json under dir {HERE}")


__version__ = _fetch_version()
__all__ = ["__version__"]
8 changes: 4 additions & 4 deletions jupyterlab-extension/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@
name = "crystaltoolkit-extension"

# Get our version
with open(os.path.join(HERE, "package.json")) as f:
version = json.load(f)["version"]
with open(os.path.join(HERE, "package.json")) as file:
version = json.load(file)["version"]

lab_path = os.path.join(HERE, name, "labextension")

Expand Down Expand Up @@ -51,8 +51,8 @@
else:
cmdclass["jsdeps"] = skip_if_exists(jstargets, js_command)

with open("README.md") as fh:
long_description = fh.read()
with open("README.md") as readme:
long_description = readme.read()

setup_args = dict(
name=name,
Expand Down

0 comments on commit 0a9a61a

Please sign in to comment.