Combine step exporters with storage interface#1182
Open
dwhswenson wants to merge 5 commits into
Open
Conversation
This should, in principle, make it so that we're no longer requiring that exports go to files. Assisted-by: Codex.app:GPT-5.5
Contributor
There was a problem hiding this comment.
Pull request overview
This PR refactors trajectory/step exporting to target a generic storage interface (not just filesystem paths), enabling exports to alternate backends (e.g., in-memory or object stores) while keeping compatibility with path-based writer libraries via staging.
Changes:
- Extend
StorageInterfacewithforce=overwrite semantics plusstore_bytes/load_bytes,open, andas_pathhelpers for byte and staged-path workflows. - Update
TrajectoryWriterto support writing to aStorageInterface(and keepwrite_filefor direct filesystem output). - Introduce a
StepExporterbase class and updateSymLinkStepExporterto inherit it, plus add tests for new storage + base_dir behaviors.
Reviewed changes
Copilot reviewed 10 out of 10 changed files in this pull request and generated 7 comments.
Show a summary per file
| File | Description |
|---|---|
| openpathsampling/utils/storage_interfaces.py | Adds byte-based and staged-path APIs; implements/extends local + memory storage backends. |
| openpathsampling/exports/trajectories/core.py | Adds storage-aware TrajectoryWriter.write and refactors file writing through LocalFileStorageInterface. |
| openpathsampling/exports/steps/core.py | New abstract StepExporter interface and default export_step orchestration. |
| openpathsampling/exports/steps/symlink_step_exporter.py | Makes symlink exporter a StepExporter and adds base_dir path resolution. |
| openpathsampling/tests/utils/test_storage_interfaces.py | Expands coverage for force, bytes APIs, open, and as_path (including atomic behavior). |
| openpathsampling/tests/exports/trajectories/test_trrtrajectorywriter.py | Adds storage-interface export test coverage for TRR writer. |
| openpathsampling/tests/exports/trajectories/test_mdtrajtrajectorywriter.py | Adds storage-interface export test coverage for MDTraj writer. |
| openpathsampling/tests/exports/trajectories/test_core.py | Adds storage-interface export tests for core trajectory writer behavior. |
| openpathsampling/tests/exports/steps/test_symlink_step_exporter.py | Adds tests for StepExporter inheritance and base_dir behavior without chdir. |
| openpathsampling/tests/exports/steps/test_step_exporter_core.py | New unit test for StepExporter.export_step orchestration ordering. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
+178
to
+182
| def _local_path(self, storage_label): | ||
| storage_label = pathlib.Path(storage_label) | ||
| if storage_label.is_absolute(): | ||
| raise ValueError("Storage labels must be relative paths") | ||
| return self.root / storage_label |
Comment on lines
199
to
200
| _logger.debug("Copying file from {str(local_path)} " | ||
| f"to {str(target_path)}") |
Comment on lines
209
to
210
| @@ -105,17 +210,88 @@ def delete(self, storage_label): | |||
| os.remove(obj) | |||
Comment on lines
+220
to
+225
| self._check_can_write(storage_label, force) | ||
| target_path = self._local_path(storage_label) | ||
| target_path.parent.mkdir(parents=True, exist_ok=True) | ||
| if force and target_path.exists(): | ||
| os.remove(target_path) | ||
| shutil.move(source_path, target_path) |
| if 'b' not in mode: | ||
| raise ValueError("StorageInterface.open only supports binary " | ||
| "modes") | ||
| if _mode_writes(mode): |
Comment on lines
+133
to
+144
| suffix = suffix or pathlib.Path(storage_label).suffix | ||
| fd, tmp_path = tempfile.mkstemp(suffix=suffix) | ||
| os.close(fd) | ||
| tmp_path = pathlib.Path(tmp_path) | ||
| write_mode = _mode_writes(mode) | ||
| try: | ||
| if write_mode: | ||
| if not force and storage_label in self: | ||
| raise FileExistsError(f"Storage label {storage_label} " | ||
| "already exists") | ||
| else: | ||
| self.load(storage_label, tmp_path) |
Comment on lines
169
to
172
| # ensure parent directory exists | ||
| pathlib.Path(raw_data_path).parent.mkdir(parents=True, exist_ok=True) | ||
| raw_data_path.parent.mkdir(parents=True, exist_ok=True) | ||
| writer = self._get_writer(sample) | ||
| writer(sample.trajectory, raw_data_path) |
Ensure that paths are actually inside the root; avoid anchored paths (storage labels should not be absolute). Assisted-by: Codex.app:GPT-5.4
Assisted-by: Codex.app:GPT-5.4
This should make it easier for downstream writers to use this. Assisted-by: Codex.app:GPT-5.4
… into traj-export-via-storage-interface
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## master #1182 +/- ##
==========================================
+ Coverage 81.55% 81.57% +0.01%
==========================================
Files 148 149 +1
Lines 15915 16093 +178
==========================================
+ Hits 12980 13128 +148
- Misses 2935 2965 +30 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
This should, in principle, make it so that we're no longer requiring that exports go to files. This will help us add flexibility in the future to export to non-filesystem setups (e.g., S3 or similar).
Assisted-by: Codex.app:GPT-5.5