-
Notifications
You must be signed in to change notification settings - Fork 5
feature/SOF 7894 Feature: create Notebooks Utils #310
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
1562cf8
update: add new structure to nb utils
VsevolodX a53b6e2
update: pyproject
VsevolodX e72a77f
update: restructure the install packages
VsevolodX 40114a9
update: restructure the install packages 2
VsevolodX 4fe96b9
chore: imports
VsevolodX 0200b67
chore: imports 2
VsevolodX 2c0a231
chore: impor
VsevolodX 64cb92f
update: add read url
VsevolodX 048bdd9
chore: fix import
VsevolodX ebeddca
chore: address pr comment
VsevolodX 5975f35
update: split auth into ipython and core
VsevolodX cabb548
chore: fix
VsevolodX b19049a
update: move await for jobs
VsevolodX f48cd22
update: isolate made and wode from core jobs
VsevolodX 92e87c5
update: run tests on GHA
VsevolodX b24c9ac
chore: tests-cov
VsevolodX c94e537
try: pydantic
VsevolodX File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,94 @@ | ||
| # mat3ra.notebooks_utils — Developer Guide | ||
|
|
||
| ## Architecture | ||
|
|
||
| Four progressive layers, each building on the previous: | ||
|
|
||
| ``` | ||
| primitive/ → core/ → ipython/ → pyodide/ | ||
| ``` | ||
|
|
||
| Top-level files (`auth.py`, `io.py`, `ui.py`, `plot.py`, `settings.py`, `material.py`) are thin | ||
| routing/re-export adapters that keep notebook code environment-agnostic. | ||
|
|
||
| --- | ||
|
|
||
| ## Layers | ||
|
|
||
| ### `primitive/` | ||
| Only Python stdlib. No third-party packages, no domain knowledge. | ||
| Enums, environment detection, logger, CLI prompt helpers. | ||
|
|
||
| ### `core/` | ||
| Third-party packages allowed (`mat3ra.api_client`, `requests`, `numpy`, …). | ||
| No IPython, no ipywidgets, no browser/pyodide APIs. | ||
|
|
||
| ``` | ||
| core/api/ — Platform credentials and OIDC auth. | ||
| core/io.py — Plain-Python file IO and HTTP. | ||
| core/entity/<domain>/ — One folder per domain (material, workflow, job, compute, property). | ||
| api.py — REST API calls only. | ||
| io.py — Local filesystem reads/writes only. | ||
| analysis.py — Pure computation (numpy/pymatgen/ase). No API, no display. | ||
| job.py — Cross-entity helpers (e.g. property derived from job data). | ||
| ``` | ||
|
|
||
| ### `ipython/` | ||
| Imports `IPython.display`, `ipywidgets`, or generates HTML/JS for notebook output. | ||
| Must work in JupyterLab, Colab, and VS Code notebooks — not browser/pyodide specific. | ||
|
|
||
| ``` | ||
| ipython/ui.py — Generic cell output: display_JSON, image grid, viewer HTML/JS. | ||
| ipython/io.py — Browser file-download helpers. | ||
| ipython/plot/ — Domain-agnostic plot primitives (_plotly.py, _matplotlib.py). | ||
| ipython/entity/<domain>/ — Domain-specific display. | ||
| visualize.py — Renders domain objects into notebook cells. | ||
| plot.py — Domain-specific charts (RDF, strain, EOS, …). | ||
| ``` | ||
|
|
||
| ### `pyodide/` | ||
| Calls `micropip`, `pyodide.http.pyfetch`, `BroadcastChannel`, or `js` (Emscripten/WASM APIs). | ||
| JupyterLite-specific overrides of `core/` or `ipython/` capabilities. | ||
|
|
||
| ``` | ||
| pyodide/io.py — JS data bridge: kernel↔host shared state, file writes. | ||
| pyodide/ui.py — Async input widgets (PyodideFuture / BroadcastChannel). | ||
| pyodide/runtime.py — Interruptible loop and abort controller. | ||
| pyodide/packages/ — micropip installation and config.yml parsing. | ||
| pyodide/api/ — Host-to-kernel token injection. | ||
| ``` | ||
|
|
||
| --- | ||
|
|
||
| ## Dependency Rules | ||
|
|
||
| ``` | ||
| primitive/ → (nothing from this package) | ||
| core/ → primitive/ | ||
| ipython/ → primitive/, core/ | ||
| pyodide/ → primitive/, core/, ipython/ | ||
| top-level → any layer (routing only, no new logic) | ||
| ``` | ||
|
|
||
| Within `core/entity/`: domains must not import each other; `api.py`, `io.py`, and `analysis.py` | ||
| must stay separate (no cross-imports within the same entity folder). | ||
|
|
||
| Within `ipython/entity/`: may import from `core/entity/<same domain>/` and `ipython/` primitives, | ||
| but not from other entity domains. | ||
|
|
||
| --- | ||
|
|
||
| ## Where does my code go? | ||
|
|
||
| | Question | Destination | | ||
| |---|---| | ||
| | Uses only stdlib? | `primitive/` | | ||
| | Calls a 3rd-party package, produces no output? | `core/` | | ||
| | Reads/writes domain objects from disk? | `core/entity/<domain>/io.py` | | ||
| | Calls the REST API? | `core/entity/<domain>/api.py` | | ||
| | Computes/transforms domain data (no display)? | `core/entity/<domain>/analysis.py` | | ||
| | Renders into a notebook cell (IPython/HTML)? | `ipython/` | | ||
| | Domain-specific chart? | `ipython/entity/<domain>/plot.py` | | ||
| | Domain-specific visualiser? | `ipython/entity/<domain>/visualize.py` | | ||
| | Calls micropip / pyfetch / BroadcastChannel? | `pyodide/` | | ||
| | Branches on environment to pick implementation? | top-level routing file | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,29 @@ | ||
| from .core.api.settings import ( | ||
| ACCOUNT_ID, | ||
| AUTH_TOKEN, | ||
| ENDPOINT_ARGS, | ||
| HOST, | ||
| MATERIALS_PROJECT_API_KEY, | ||
| ORGANIZATION_ID, | ||
| PORT, | ||
| SECURE, | ||
| VERSION, | ||
| absolute_path_to_settings_json_file, | ||
| settings_json_config, | ||
| ) | ||
| from .settings import UPLOADS_FOLDER | ||
|
|
||
| __all__ = [ | ||
|
timurbazhirov marked this conversation as resolved.
|
||
| "absolute_path_to_settings_json_file", | ||
| "settings_json_config", | ||
| "ACCOUNT_ID", | ||
| "AUTH_TOKEN", | ||
| "MATERIALS_PROJECT_API_KEY", | ||
| "ORGANIZATION_ID", | ||
| "PORT", | ||
| "SECURE", | ||
| "VERSION", | ||
| "HOST", | ||
| "ENDPOINT_ARGS", | ||
| "UPLOADS_FOLDER", | ||
| ] | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,28 @@ | ||
| import inspect | ||
| import os | ||
|
|
||
| from mat3ra.api_client import ACCESS_TOKEN_ENV_VAR | ||
|
|
||
| from .core.api.auth import authenticate_oidc | ||
| from .io import get_data | ||
| from .ipython.ui import show_device_flow_popup | ||
| from .primitive.environment import ENVIRONMENT, EnvironmentsEnum | ||
| from .pyodide.api.auth import authenticate_jupyterlite | ||
|
|
||
| REFRESH_TOKEN_ENV_VAR = "OIDC_REFRESH_TOKEN" | ||
|
|
||
|
|
||
| async def authenticate(force=False, globals_dict=None): | ||
| if globals_dict is None: | ||
| frame = inspect.currentframe() | ||
| try: | ||
| globals_dict = frame.f_back.f_globals # type: ignore | ||
| finally: | ||
| del frame | ||
| if ENVIRONMENT == EnvironmentsEnum.PYODIDE: | ||
| get_data("data_from_host", globals_dict) | ||
| data_from_host = globals_dict.get("data_from_host") | ||
| if data_from_host: | ||
| await authenticate_jupyterlite(data_from_host) | ||
| elif ACCESS_TOKEN_ENV_VAR not in os.environ or force: | ||
| await authenticate_oidc(show_popup=show_device_flow_popup) |
Empty file.
Empty file.
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🧩 Analysis chain
🏁 Script executed:
Repository: Exabyte-io/api-examples
Length of output: 690
Fix the misspelled package name in the
workflowsextra.mar3ra-notebooks-utils[api]is a typo (should bemat3ra-notebooks-utils[api]), matching all other instances of this package in the file. This will breakpip install .[workflows].Proposed fix
📝 Committable suggestion
🤖 Prompt for AI Agents