Skip to content
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

feat: add transformations to from_xml #208

Merged
merged 5 commits into from
Jul 16, 2023
Merged

feat: add transformations to from_xml #208

merged 5 commits into from
Jul 16, 2023

Conversation

tlambert03
Copy link
Owner

@tlambert03 tlambert03 commented Jul 14, 2023

This PR addresses, and I'm going to say closes #129

It adds a new transformations argument to from_xml

AnyElementTree = xml.etree.ElementTree.ElementTree | lxml.etree._ElementTree
TransformationCallable = Callable[[AnyElementTree], AnyElementTree]

def from_xml(
    ...,
    transformations: Iterable[TransformationCallable] = (),
):

which lets the user add any number of "fixers" before converting xml. There is a new module ome_types.etree_fixes with some standard fixes, and PRs can be opened to add more. So, to use them all:

from ome_types import etree_fixes, from_xml

from_xml("some_bad.ome.xml", transformations=etree_fixes.ALL_FIXES)

HOWEVER:
With v0.4.0, many of the fixes that are included in the aicsimageio clean_ome_xml_for_known_issues function referenced in #129 (i.e., ID and references fixes, namespace capitalization, ordering of elements) are no longer necessary as they are handled fine by default. Some will emit warnings, and the transformations could be used to avoid those warnings. But in general, I think this is a flexible enough approach that anyone can extend if needed

@codecov
Copy link

codecov bot commented Jul 14, 2023

Codecov Report

Merging #208 (a6f8427) into main (46bae0c) will increase coverage by 0.21%.
The diff coverage is 97.29%.

@@            Coverage Diff             @@
##             main     #208      +/-   ##
==========================================
+ Coverage   86.26%   86.48%   +0.21%     
==========================================
  Files          25       26       +1     
  Lines        1223     1250      +27     
==========================================
+ Hits         1055     1081      +26     
- Misses        168      169       +1     
Impacted Files Coverage Δ
src/ome_types/_conversion.py 95.89% <93.33%> (-0.42%) ⬇️
src/ome_types/etree_fixes.py 100.00% <100.00%> (ø)

📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more

@codspeed-hq
Copy link

codspeed-hq bot commented Jul 14, 2023

CodSpeed Performance Report

Merging #208 will not alter performance

Comparing fix-common-errors (a6f8427) with main (46bae0c)

Summary

✅ 9 untouched benchmarks

@tlambert03 tlambert03 merged commit 51b6f2e into main Jul 16, 2023
@tlambert03 tlambert03 deleted the fix-common-errors branch July 16, 2023 17:25
@tlambert03 tlambert03 added the enhancement New feature or request label Jul 16, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Feature: Fix common errors from OmeXml.py
1 participant