Skip to content

ModuleNotFoundError error #217

Open
Open

Description

@tliron

I am using this wit file and am trying this simple example (plugin.py):

import wit_world
import wit_world.exports

class Dispatch(wit_world.exports.Dispatch):
    def initialize(self, id):
        pass

    def dispatch(self, name, arguments, call_site):
        pass

My command is basically this:

componentize-py \
    --wit-path wit/floria-plugins.wit \
    componentize \
    --stub-wasi \
    --python-path plugin \
    --output dist/plugin.wasm \
    plugin

The error is this:

Traceback (most recent call last):
  File "python/bin/componentize-py", line 6, in <module>
    sys.exit(script())
             ~~~~~~^^
AssertionError: ModuleNotFoundError: No module named 'dispatch'


Caused by:
    ModuleNotFoundError: No module named 'dispatch'

I tried generating the bindings and can't find anything that would cause this error. Am I doing something wrong?

Activity

  1. dicej commented on May 20, 2026

    @dicej
    Collaborator

    Hi @tliron. Thanks for reporting this.

    Since the world your component is targeting exports the dispatch interface, and that interface includes several resource types, you must provide implementations of those types as well. You can add a file named dispatch.py to the same directory that contains plugin.py with content like this:

    from wit_world.exports import dispatch
    from wit_world.exports.dispatch import Expression, CallKind
    from typing import List, Tuple
    
    class CallResource(dispatch.CallResource):
        def __init__(self, plugin: str, function: str, arguments: List[Expression], kind: CallKind) -> None:
            raise NotImplementedError
    
        def replica(self) -> Tuple[str, str, List[Expression], CallKind]:
            raise NotImplementedError
    
    class CustomResource(dispatch.CustomResource):
        def __init__(self, kind: str, expression: Expression) -> None:
            raise NotImplementedError
    
        def replica(self) -> Tuple[str, Expression]:
            raise NotImplementedError
    
    class MapResource(dispatch.MapResource):
        def __init__(self, key_value_pairs: List[Tuple[Expression, Expression]]) -> None:
            raise NotImplementedError
    
        def replica(self) -> List[Tuple[Expression, Expression]]:
            raise NotImplementedError
    
        def length(self) -> int:
            raise NotImplementedError
    
    class ListResource(dispatch.ListResource):
        def __init__(self, items: List[Expression]) -> None:
            raise NotImplementedError
    
        def replica(self) -> List[Expression]:
            raise NotImplementedError
    
        def length(self) -> int:
            raise NotImplementedError

    (replacing the raise NotImplementedError lines with whatever you want the implementations to do). That should fix the issue.

  2. pinned and unpinned a comment on May 20, 2026
  3. tliron commented on May 20, 2026

    @tliron
    Author

    Thank you, that worked! I'm sure it took some work effort to investigate this, I appreciate it.

    I would suggest a few ways moving forward:

    1. Documenting how to implement resources.
    2. Better error messages. It should have been "missing implementations for ...". This would probably mean validating each implementation instead of just importing it.
    3. Adding examples with imports, exports, resources.
    4. Perhaps there can be a new command, e.g. componentize-py skeleton, which can generate a working stub for users to flesh out with their own code.
  4. tliron commented on May 20, 2026

    @tliron
    Author

    Can you help me with something else? I am trying to use --export-interface-name to rename the dispatch export, but none of my attempts work (and there is no error message):

    --export-interface-name floria:plugin:dispatch-plugin:dispatch=test
    --export-interface-name dispatch-plugin:dispatch=test
    

    I'm not clear on what the export name should be.

  5. dicej commented on May 20, 2026

    @dicej
    Collaborator

    Try --export-interface-name floria:plugins/dispatch=test (in which case you'll need to update your plugin.py to match). And yes, this is another place the documentation should be improved.

  6. dicej commented on May 20, 2026

    @dicej
    Collaborator

    I would suggest a few ways moving forward:

    1. Documenting how to implement resources.

    Agreed!

    1. Better error messages. It should have been "missing implementations for ...". This would probably mean validating each implementation instead of just importing it.

    Agreed that this would be great, but I'm wondering how it would be implemented. Would it require parsing the Python code and statically analyzing it to determine whether it defines the expected symbols? If so, that sounds daunting given how dynamic Python is (i.e. able to add and/or delete symbols and fields at runtime). Maybe there's a simple solution I'm not seeing?

    1. Adding examples with imports, exports, resources.

    The existing examples involve imports, exports, and (imported) resources, but you're right that we also need at least one example that exports a resource.

    1. Perhaps there can be a new command, e.g. componentize-py skeleton, which can generate a working stub for users to flesh out with their own code.

    Agreed; that would be great, and mirrors the --stubs option in wit-bindgen rust.

  7. dicej commented on Sep 1, 2026

    @dicej
    Collaborator

    2. Better error messages. It should have been "missing implementations for ...". This would probably mean validating each implementation instead of just importing it.

    Note that this has been improved as of #240, which uses decorators to register implementations, allowing for better error messages.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions