feature/SOF 7901 qol#321
Conversation
|
Check out this pull request on See visual diffs & provide feedback on Jupyter Notebooks. Powered by ReviewNB |
📝 WalkthroughWalkthroughThis PR refactors the material I/O infrastructure to support flexible folder paths for persistence and refines Pyodide patch application logic. The MACE-MP relaxation notebook is updated to leverage the new ChangesMaterial I/O Infrastructure and Notebook Integration
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Possibly related PRs
Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 inconclusive)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🧹 Nitpick comments (1)
src/py/mat3ra/notebooks_utils/io.py (1)
25-37: ⚡ Quick win
folder_pathis silently ignored in the Pyodide path.If callers pass a custom path while running in Pyodide, the value is dropped with no signal. Please add an explicit warning (or clear docstring note at runtime) when
folder_path != UPLOADS_FOLDERin the Pyodide branch.🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@src/py/mat3ra/notebooks_utils/io.py` around lines 25 - 37, The Pyodide branch of set_data silently ignores the folder_path argument; update set_data so that when ENVIRONMENT == EnvironmentsEnum.PYODIDE and folder_path != UPLOADS_FOLDER it emits an explicit runtime warning (e.g., using warnings.warn or your module logger) indicating that custom folder_path is ignored in Pyodide and that set_data_pyodide will use UPLOADS_FOLDER; keep the existing calls to set_data_pyodide and set_data_python unchanged and reference the functions set_data, set_data_pyodide, set_data_python, ENVIRONMENT, EnvironmentsEnum, and UPLOADS_FOLDER when making this change.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@src/py/mat3ra/notebooks_utils/core/io.py`:
- Around line 45-46: The code currently does a check-then-create using
os.path.exists(folder_path) followed by os.makedirs(folder_path), which can race
under concurrent calls; update the logic to create the directory atomically by
calling os.makedirs(folder_path, exist_ok=True) (or wrap os.makedirs in
try/except catching FileExistsError) wherever this pattern appears (refer to the
folder_path variable and the os.makedirs call) so directory creation is safe
under concurrent execution.
---
Nitpick comments:
In `@src/py/mat3ra/notebooks_utils/io.py`:
- Around line 25-37: The Pyodide branch of set_data silently ignores the
folder_path argument; update set_data so that when ENVIRONMENT ==
EnvironmentsEnum.PYODIDE and folder_path != UPLOADS_FOLDER it emits an explicit
runtime warning (e.g., using warnings.warn or your module logger) indicating
that custom folder_path is ignored in Pyodide and that set_data_pyodide will use
UPLOADS_FOLDER; keep the existing calls to set_data_pyodide and set_data_python
unchanged and reference the functions set_data, set_data_pyodide,
set_data_python, ENVIRONMENT, EnvironmentsEnum, and UPLOADS_FOLDER when making
this change.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: ed0fdfa6-96df-4e8c-80b1-45bc7700ca87
📒 Files selected for processing (6)
other/materials_designer/workflows/local/relaxation_mlff_mace.ipynbsrc/py/mat3ra/__init__.pysrc/py/mat3ra/notebooks_utils/core/entity/material/io.pysrc/py/mat3ra/notebooks_utils/core/io.pysrc/py/mat3ra/notebooks_utils/io.pysrc/py/mat3ra/notebooks_utils/pyodide/packages/torch.py
| if not os.path.exists(folder_path): | ||
| os.makedirs(folder_path) |
There was a problem hiding this comment.
Avoid check-then-create for output directory creation.
This pattern can fail under concurrent calls (FileExistsError) between the existence check and creation.
Proposed fix
- if not os.path.exists(folder_path):
- os.makedirs(folder_path)
+ os.makedirs(folder_path, exist_ok=True)📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| if not os.path.exists(folder_path): | |
| os.makedirs(folder_path) | |
| os.makedirs(folder_path, exist_ok=True) |
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
In `@src/py/mat3ra/notebooks_utils/core/io.py` around lines 45 - 46, The code
currently does a check-then-create using os.path.exists(folder_path) followed by
os.makedirs(folder_path), which can race under concurrent calls; update the
logic to create the directory atomically by calling os.makedirs(folder_path,
exist_ok=True) (or wrap os.makedirs in try/except catching FileExistsError)
wherever this pattern appears (refer to the folder_path variable and the
os.makedirs call) so directory creation is safe under concurrent execution.
Update: add ability to pass uploads folder path
Summary by CodeRabbit
New Features
Bug Fixes
Refactor