Skip to content

Fix default entrypoint handling on older Pythons #475

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

Merged
merged 21 commits into from
Oct 17, 2023

Conversation

vyasr
Copy link
Contributor

@vyasr vyasr commented Oct 9, 2023

The fallback here for updating a dictionary needs to be a dictionary, not a list.

I haven't added any new tests or anything, but I can if I'm pointed in the right direction. Not sure how this library wants to test these types of edge cases with entry points.

Resolves #478

TODO:

  • Unit tests and/or doctests in docstrings
  • Tests pass locally
  • Docstrings and API docs for any new/modified user-facing classes and functions
  • Changes documented in docs/release.rst
  • Docs build locally
  • GitHub Actions CI passes
  • Test coverage to 100% (Codecov passes)

@jakirkham jakirkham changed the title Replace default list with dict Fix default entrypoint handling on older Pythons Oct 9, 2023
@jakirkham
Copy link
Member

Thanks Vyas! 🙏

Made some tweaks to handle the release note. Hope that is ok. Please update as needed

Also maybe we should test this somehow. Currently we test the presence of a single entrypoint. Maybe we should also test the absence of any entrypoints?

def test_entrypoint_codec(set_path):
cls = numcodecs.registry.get_codec({"id": "test"})
assert cls.codec_id == "test"

@codecov
Copy link

codecov bot commented Oct 9, 2023

Codecov Report

Merging #475 (aeef761) into main (c28f5c9) will not change coverage.
The diff coverage is 100.00%.

Additional details and impacted files
@@            Coverage Diff            @@
##              main      #475   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files           56        57    +1     
  Lines         2242      2261   +19     
=========================================
+ Hits          2242      2261   +19     
Files Coverage Δ
numcodecs/registry.py 100.00% <100.00%> (ø)
numcodecs/tests/test_entrypoints.py 100.00% <100.00%> (ø)
numcodecs/tests/test_entrypoints_backport.py 100.00% <100.00%> (ø)

raydouglass pushed a commit to rapidsai/kvikio that referenced this pull request Oct 10, 2023
numcodecs 0.12 appears to have some breaking changes. I've submitted a fix upstream, but for this release of RAPIDS we'll need to upper bound the version to be safe.

xref: zarr-developers/numcodecs#475

Authors:
   - Vyas Ramasubramani (https://github.com/vyasr)

Approvers:
   - Bradley Dice (https://github.com/bdice)
@vyasr vyasr marked this pull request as draft October 10, 2023 18:59
@vyasr vyasr marked this pull request as ready for review October 10, 2023 21:14
@jakirkham
Copy link
Member

@martindurant , could you please look over this?

@jakirkham jakirkham closed this Oct 11, 2023
@jakirkham jakirkham reopened this Oct 11, 2023
@jakirkham
Copy link
Member

Was seeing AVX2 issues on macOS builds, that I thought we just fixed with PR ( #479 ). So toggling PR to ensure latest changes in main are picked up

@joshmoore
Copy link
Member

joshmoore commented Oct 12, 2023

OSX failures are still the sporadic:

#error AVX2 is not supported by the target architecture/platform and/or this compiler.

Trying a rebuild on the action itself.

Otherwise, 👍 for the PR.

@vyasr
Copy link
Contributor Author

vyasr commented Oct 13, 2023

Maybe one more rerun? Looks like attempt 2 passed one of the previously failing jobs but the other failed again.

@jakirkham
Copy link
Member

Have added a fix in main to disable AVX2 in macOS GHA jobs and merged that into here. That should resolve that issue

@jakirkham
Copy link
Member

Since the only entrypoint added is coming from the test entrypoint that we load ourselves. Wonder if we can avoid using a subprocess by simply testing there are no entrypoints present (and effectively those code paths work) before trying to add our own entrypoint (to test that we can load entrypoints). What do you think Vyas?

@vyasr
Copy link
Contributor Author

vyasr commented Oct 17, 2023

Since the only entrypoint added is coming from the test entrypoint that we load ourselves. Wonder if we can avoid using a subprocess by simply testing there are no entrypoints present (and effectively those code paths work) before trying to add our own entrypoint (to test that we can load entrypoints). What do you think Vyas?

I'm afraid I don't understand how your suggestion avoids the problem. My concern is that because importlib_metadata is patching the standard library, as soon as the test importing it runs all subsequent tests in the same process will see the patched library. If there are any other edge cases where simply importing importlib_metadata causes problems, we would start seeing random unexpected failures in other tests based on test ordering (and of course partitioning if tests are run with pytest-xdist). At present, that mostly affects the other test in test_entrypoints.py, so we might be OK just based on pytest's default ordering of tests, but I don't know that we want to rely on that. Also, there's no guarantee that the monkey-patching wouldn't affect any of numcodecs dependencies in unexpected ways.

If you think those cases aren't worth worrying about, though, then I can revert the multiprocessing change.

@jakirkham
Copy link
Member

Ah missed we added tests for the backport package importlib_metadata

Ok would it be possible to move these into their own test file? Maybe test_entrypoints_backport.py or similar? We could then also have some top-level check to make sure importlib_metadata is around before testing (ideally without importing given the associated issues)

@vyasr
Copy link
Contributor Author

vyasr commented Oct 17, 2023

Done. The test is now in its own module and only runs if importlib_metadata is available.

Comment on lines +22 to +25
sys.path.append(here)
numcodecs.registry.run_entrypoints()
cls = numcodecs.registry.get_codec({"id": "test"})
assert cls.codec_id == "test"
Copy link
Member

Choose a reason for hiding this comment

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

Would it make sense to reuse set_path here somehow? Should cleanup sys.path and the numcodecs.registry after?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I thought about reusing, but I think it'd be more work than it's worth. We can't use a fixture directly because it's not supposed to affect the actual test function, we need it to affect the helper function that's run in the subprocess and that function isn't a test so pytest won't patch in fixtures. We could try and split it into a helper function like I had initially, but it's not really necessary. Since the function is running in a subprocess we don't need to clean things up, it shouldn't affect the modules in the parent process.

@jakirkham jakirkham enabled auto-merge (squash) October 17, 2023 22:57
@jakirkham
Copy link
Member

Thanks Vyas! 🙏

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.

Default entry point is being updated incorrectly
4 participants