Skip to content

253 class importer - #258

Merged
krzywon merged 27 commits into
refactor_24from
253-class-importer
Nov 9, 2026
Merged

krzywon merged 27 commits into
refactor_24from
253-class-importer

Conversation

@krzywon

@krzywon krzywon commented Nov 5, 2026 •

Copy link
Copy Markdown
Collaborator

This applies the common importer class to all importers. File import no longer requires a registry mapping file extension to the reader. Instead, the file contents are examined and an importer is selected that matches the file contents the best.

Fixes #253
Refs #192 - Many of the existing files are now loading, but this will require more testing before I can say it's fully fixed

Disclaimer: Claude was used to help generate the code in the PR.

NB Changes will need to be made in sasview (coming soon) before this should be merged into the refactor branch.

@krzywon
krzywon added this pull request to stack #259 November 5, 2026 13:14
codescene-access[bot]

This comment was marked as outdated.

codescene-access[bot]

This comment was marked as outdated.

@ps1401 ps1401 left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have a few questions, but overall this looks solid.


# ------------------------------------------------------------------------------------------------------------------
# Interface to be implemented by every child importer
# ------------------------------------------------------------------------------------------------------------------

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Given they must be implemented, would it be appropriate to make these methods abstract methods?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This class holds a registry of all child Importers. Making this class abstract breaks some of that convention.

file = Path(file)
measurements, errors = self._import_from_url(file, config)
if file is None:
break

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this be break or continue? I'd have though if a single file is None, that doesn't affect the entire list, unless you want an error to be raised immediately on finding this. What's the approach here?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See my change here, but the idea is, if zip_longest finds more configs than files, this should not continue.

Comment thread sasdata/data_io/importer.py Resolved
Comment thread test/__init__.py Resolved
Comment thread test/utest_trend.py
@@ -40,7 +39,7 @@ def test_trend_build_from_xml():
and currently a single Metadata (no tree of MetaNodes), but this should be
corrected in the future in the XML reader, I guess!

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Has this now been corrected, and should the docstring be updated? I know we've got rid of sasentry for hdf5 files.

Comment thread sasdata/data_io/importers/import_xml.py Resolved
codescene-access[bot]

This comment was marked as outdated.

codescene-access[bot]

This comment was marked as outdated.

@classmethod
def can_import(cls, source: Source_Type) -> bool:
"""The file is HDF5 if the HDF5 format signature is found at offset 0 or at a user block boundary."""
if isinstance(source, (str, Path)):

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can use PathType here.


def load_data(self, source: Source_Type) -> dict[str, SasMeasurement]:
"""Load a SESANS file. The file holds a single measurement, which is keyed by its name."""
if isinstance(source, (str, Path)):

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can use PathType here.

codescene-access[bot]

This comment was marked as outdated.

Base automatically changed from 226-hdf5-name to refactor_24 November 9, 2026 16:57
codescene-access[bot]

This comment was marked as outdated.

@codescene-access codescene-access Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No quality gates enabled for this code.

See analysis details in CodeScene

Quality Gate Profile: Custom Configuration
Install CodeScene MCP: safeguard and uplift AI-generated code. Catch issues early with our IDE extension and CLI tool.

@krzywon
krzywon merged commit a899713 into refactor_24 Nov 9, 2026
35 checks passed
@krzywon
krzywon deleted the 253-class-importer branch November 9, 2026 18:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants