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

no disk caching #20

Merged
merged 11 commits into from
Aug 6, 2020
Merged

no disk caching #20

merged 11 commits into from
Aug 6, 2020

Conversation

tlambert03
Copy link
Owner

closes #19 (good enough for now). by adding xmlschema.__version__ and ome_types.__version__ to cache key, and using shelve instead of pickle directly. That has the potential to make the cache big for local development, so added clear_schema_cache function that gets called on import when the cache is >30MB.

@codecov-commenter
Copy link

codecov-commenter commented Jul 22, 2020

Codecov Report

Merging #20 into master will decrease coverage by 0.01%.
The diff coverage is 100.00%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master      #20      +/-   ##
==========================================
- Coverage   95.20%   95.18%   -0.02%     
==========================================
  Files           1        1              
  Lines         396      436      +40     
==========================================
+ Hits          377      415      +38     
- Misses         19       21       +2     
Impacted Files Coverage Δ
src/ome_autogen.py 95.18% <100.00%> (-0.02%) ⬇️

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 4c667ff...c504438. Read the comment docs.

@tlambert03 tlambert03 changed the title better caching no disk caching Jul 22, 2020
@tlambert03
Copy link
Owner Author

@jmuhlich thoughts? I removed all disk caching, moved the 2016-06 schema into source and use it in the special case that the url matches... and use lrucache for within session caching.

For the special case of retrieving the 2016-06 OME Schema, use local file.
"""
if url == "http://www.openmicroscopy.org/Schemas/OME/2016-06/ome.xsd":
url = os.path.join(os.path.dirname(__file__), "ome-2016-06.xsd")
Copy link
Collaborator

Choose a reason for hiding this comment

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

Cleaner to use pkg_resources.resource_stream here rather than direct file access:
https://setuptools.readthedocs.io/en/latest/pkg_resources.html#basic-resource-access
That will work from within wheels and such where the source is not expanded onto an actual filesystem. Should be able to use url = pkg_resources.resource_stream(__name__, "ome-2016-06.xsd").

Copy link
Owner Author

Choose a reason for hiding this comment

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

don't love the implicit setuptools dependency, though I know it's ubiquitous. but the point/goal is well-taken. will look at it

src/ome_types/schema.py Outdated Show resolved Hide resolved
src/ome_types/schema.py Outdated Show resolved Hide resolved
@@ -18,12 +17,12 @@ def model(tmp_path_factory, request):
raise RuntimeError(
f"Please generate local {SRC_MODEL} before using --nogen"
)
sys.path.insert(0, str(SRC_MODEL.parent))
sys.path.insert(0, str(SRC_MODEL))
Copy link
Collaborator

Choose a reason for hiding this comment

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

Global side-effects in a test are bad news, since they can affect other tests and the results can end up depending on the other in which the tests are run. I don't have a better suggestion in this case that totally avoids modifying the path, but maybe undoing the path change after the test runs would at least contain the side-effect to the duration of the test. Also goes for the other path manipulation below.

Copy link
Owner Author

Choose a reason for hiding this comment

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

we can use pytest monkeypatch fixture as contextmanager... (but this is also a bit of an unusual scenario, since the model is the only thing we really test at this point... so it kinda needs to be there for all tests)

@jmuhlich
Copy link
Collaborator

jmuhlich commented Aug 3, 2020

Where does this stand? Do you want to change anything or should I look it over one last time?

@tlambert03
Copy link
Owner Author

lemme have one more look. I think I was convinced about something (:smile:) previously and needed to go back and implement it.

@tlambert03
Copy link
Owner Author

ok, have another look. I didn't quite hardcode it, but I made sure that no network requests are happening (fully turned off internet and tests still pass...) and prevented the potential KeyError for identities.
Tests actually now run 3x faster without all the requests! thanks for pushing on that.

src/ome_types/schema.py Outdated Show resolved Hide resolved
@jmuhlich
Copy link
Collaborator

jmuhlich commented Aug 5, 2020

And whoa do those tests fly now!

@tlambert03
Copy link
Owner Author

Shouldn't the namespace be checked with == not in? Also we should only have that literal URL string written one place in the code

both changes made, thanks! merging

@tlambert03 tlambert03 merged commit bb37ec0 into master Aug 6, 2020
@tlambert03 tlambert03 deleted the change-caching branch August 6, 2020 13:09
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.

schema caching needs xmlschema version
3 participants