Skip to content

Make URL Access Pluggable #5323

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 6 commits into from
Jun 13, 2025
Merged

Conversation

haileyhemmingsen
Copy link
Collaborator

Adding URL plugins by changing the existing plugin system to be more generic. From there, we can apply it to the existing batch system plugins and the new URL access implementation. Documentation will be added when example plugin is added. Fixes #5302.

Changelog Entry

To be copied to the draft changelog by merger:

  • Deleted deprecated addBatchSystemFactory, BATCH_SYSTEM_FACTORY_REGISTRY, and BATCH_SYSTEMS. Use add_batch_system_factory instead.
  • Added new unified plugin system
  • Toil now supports URL plugins. To provide a plugin, add toil_url_access_ at beginning of python package name. To register a new URL scheme use register_plugin("url_access", scheme, implementation_type_factory).

Reviewer Checklist

  • Make sure it is coming from issues/XXXX-fix-the-thing in the Toil repo, or from an external repo.
    • If it is coming from an external repo, make sure to pull it in for CI with:
      contrib/admin/test-pr otheruser theirbranchname issues/XXXX-fix-the-thing
      
    • If there is no associated issue, create one.
  • Read through the code changes. Make sure that it doesn't have:
    • Addition of trailing whitespace.
    • New variable or member names in camelCase that want to be in snake_case.
    • New functions without type hints.
    • New functions or classes without informative docstrings.
    • Changes to semantics not reflected in the relevant docstrings.
    • New or changed command line options for Toil workflows that are not reflected in docs/running/{cliOptions,cwl,wdl}.rst
    • New features without tests.
  • Comment on the lines of code where problems exist with a review comment. You can shift-click the line numbers in the diff to select multiple lines.
  • Finish the review with an overall description of your opinion.

Merger Checklist

  • Make sure the PR passed tests, including the Gitlab tests, for the most recent commit in its branch.
  • Make sure the PR has been reviewed. If not, review it. If it has been reviewed and any requested changes seem to have been addressed, proceed.
  • Merge with the Github "Squash and merge" feature.
    • If there are multiple authors' commits, add Co-authored-by to give credit to all contributing authors.
  • Copy its recommended changelog entry to the Draft Changelog.
  • Append the issue number in parentheses to the changelog entry.

Copy link
Member

@adamnovak adamnovak left a comment

Choose a reason for hiding this comment

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

I think this is pretty good, but it needs to be adjusted to pass tests (and the local make mypy which should replicate some of the test failures), and I think some of the docstrings should explain more about how it is meant to be used.

@@ -0,0 +1,66 @@
import importlib
Copy link
Member

Choose a reason for hiding this comment

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

We probably want to have the copyright header at the top here like we have in the other Toil source files, and also maybe a note (module-level docstring?) about what this file is for.

Comment on lines +12 to +16
def register_plugin(
plugin_type: PluginType, plugin_name: str, plugin_being_registered: Any
) -> None:
"""
Adds a plugin to the registry for the given type of plugin.
Copy link
Member

Choose a reason for hiding this comment

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

Since the type annotations don't define it, it might be good to note here what the expected plugin values are meant to be for a given plugin type (i.e. functions that return a class implementing blah interface).

It also might be good to explain what plugin_name is used for: for patch systems it is the value the user passes to --batchSystem to actually use it, and for URLs it is the URL scheme value that the plugin gets called to handle. It's not really the "name of the plugin" like the variable name would suggest; you shouldn't pass "My Cool Plugin" or something.


def get_plugin(plugin_type: PluginType, plugin_name: str) -> Any:
"""
Get a plugin class by name.
Copy link
Member

Choose a reason for hiding this comment

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

This sounds a little misleading to me because when I read it I think that:

  1. The result will be a class, when it's really a function that returns a class when called.
  2. The argument is the name of the class (like toil_plugin_url_access_foobar.lib.plugin.MyCoolClass), when it's really a user-facing batch system name or URL scheme.

@@ -0,0 +1,108 @@
# Copyright (C) 2015-2021 Regents of the University of California
Copy link
Member

Choose a reason for hiding this comment

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

This should be bumped up to 2025.

remove_plugin("url_access", "fake")
super().tearDown()

def test_url_exists(self):
Copy link
Member

Choose a reason for hiding this comment

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

MyPy is complaining on the CI run that a lot of these test functions are missing a -> None return type annotation.

return ["file1.txt", "subdir/"]

@classmethod
def _read_from_url(cls, url: ParseResult, writable: io.BytesIO) -> tuple[int, bool]:
Copy link
Member

Choose a reason for hiding this comment

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

MyPy complained in CI that the writable needs to be an IO[bytes] like the URLAccess has it, and not an io.BytesIO which MyPy reads as slightly different.

Copy link
Member

@adamnovak adamnovak left a comment

Choose a reason for hiding this comment

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

I've made the changes I wanted from the code review, so I think this can be merged now.

@adamnovak adamnovak merged commit 275fb04 into master Jun 13, 2025
3 checks passed
@adamnovak adamnovak deleted the issues/5302-make-url-access-pluggable branch June 13, 2025 15:55
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.

Make URL access implementations pluggable
2 participants