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

Update References with pointer to target object #34

Merged
merged 3 commits into from
Aug 24, 2020

Conversation

jmuhlich
Copy link
Collaborator

@jmuhlich jmuhlich commented Aug 7, 2020

Adds a .ref to all Reference subclasses that returns the referenced model
object. There is an underlying ref_ field to support this that is only filled
in by the root OME object's constructor. A future API addition will be
created to support proper creation of References.

Closes #27

@jmuhlich jmuhlich requested a review from tlambert03 August 7, 2020 21:51
@jmuhlich
Copy link
Collaborator Author

jmuhlich commented Aug 7, 2020

I just realized I didn't write any tests for this. I understand if you want to hold off accepting this until I get around to that.

@codecov-commenter
Copy link

codecov-commenter commented Aug 7, 2020

Codecov Report

Merging #34 into master will decrease coverage by 0.06%.
The diff coverage is 97.63%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master      #34      +/-   ##
==========================================
- Coverage   95.20%   95.13%   -0.07%     
==========================================
  Files           1        1              
  Lines         396      473      +77     
==========================================
+ Hits          377      450      +73     
- Misses         19       23       +4     
Impacted Files Coverage Δ
src/ome_autogen.py 95.13% <97.63%> (-0.07%) ⬇️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update a9d5fc4...beab9ee. Read the comment docs.

@tlambert03
Copy link
Owner

just noticing that we're building a fair amount of string literals in ome_autogen
for some of these added methods, like the class overrides here, how would you feel about putting the autogenerated code at ome_types._model, then creating a new ome_types.model module (checked into source), that is mostly a passthrough module, but reimplements a few of the classes with additional methods... eg:

#ome_types/model/ome.py
from ome_types._model.ome import OME as _OME

class OME(_OME):
    def __post_init_post_parse__(self: Any, *args: Any) -> None:
        ids = collect_ids(self)
        references = collect_references(self)
        for ref_id, ref in references.items():
            ref.ref_ = weakref.ref(ids[ref_id])

thoughts?

@jmuhlich
Copy link
Collaborator Author

jmuhlich commented Aug 9, 2020 via email

@jmuhlich
Copy link
Collaborator Author

What do you think about this PR as it stands? Maybe I add some tests and if you're happy with the API and approach we can merge it, and the next PR will work on moving all this fixed code into a separate module.

Copy link
Owner

@tlambert03 tlambert03 left a comment

Choose a reason for hiding this comment

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

sorry for the delay, I'm happy working with this approach. Couple basic tests would be good and then we can merge

@tlambert03
Copy link
Owner

just tried to write a very basic test for this:

def test_collect_ref(model):
    from ome_types import from_xml
    from ome_types.util import collect_references

    ome = from_xml(TESTING_DIR / "data" / "filter.ome.xml", model.OME)
    expected = {
        "Dichroic:1",
        "Filter:5",
        "Filter:1",
        "Filter:Dichroic:2",
        "FilterSet:2",
        "Filter:6",
        "Instrument:0",
        "Objective:0:0",
        "Filter:2",
        "Filter:3",
        "Filter:4",
    }
    assert set(collect_references(ome)) == expected

that "expected" set is what I get when I run that exact code interactively... but for some reason when I run it in the test, set(collect_references(ome)) is an empty set... any idea what's going on there?

@jmuhlich
Copy link
Collaborator Author

The model fixture imports the model module as test_model0, so the isinstance(value, Reference) check in collect_references never returns True because test_model0.reference.Reference is not the same as ome_types.model.reference.Reference. I tried running with --nogen but then I got an error from a circular import for some reason.

@tlambert03
Copy link
Owner

ah, ok. thanks, will see what I can do to clean up that testing arrangement.

@tlambert03
Copy link
Owner

since most of the testing difficulty here is unrelated to this PR, and has more to do with the way I setup testing a dynamically generated import, it's fine with me if you want to just merge this PR when you're happy with it, and we can create an issue to add tests later

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.

References should provide direct access to the referenced object
3 participants