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

Handle missing imports with a context manager and a wraper for classes and objects #465

Closed
davorrunje opened this issue Jan 13, 2025 · 1 comment · Fixed by #540
Closed
Assignees
Labels
documentation Improvements or additions to documentation infra:build roadmap

Comments

@davorrunje
Copy link
Collaborator

davorrunje commented Jan 13, 2025

As the dependencies become larger, many optional dependencies have mutual conflicts. To generate API documentation, we should be able to load all submodules with only the required dependencies. One way to accomplish this is as follows:

def optional_import_block(modules: Union[str, Iterable[str]], dep_target: str) -> Result:
  ...

with check_for optional_import_block() as result:
   import some_optional_module

skip_tests = result.is_successful

@require_optional_import("some_optional_module", "some-optional-dep-target")
class MyClass():
    def __init__():
        o = some_optional_module.SomeClass()

If some_optional_module module is installed, the construction of MyClass will work as expected. If not, it will raise autogen.exceptions.ImportError("MIssing imported module 'some_module', please install it using 'pip install ag2["some-optional-dep-target"]'").

@davorrunje davorrunje added this to ag2 Jan 13, 2025
@davorrunje davorrunje moved this to In Progress in ag2 Jan 13, 2025
@davorrunje davorrunje added roadmap documentation Improvements or additions to documentation and removed roadmap labels Jan 13, 2025
@davorrunje davorrunje moved this from In Progress to Todo in ag2 Jan 13, 2025
@davorrunje davorrunje moved this from Todo to In Progress in ag2 Jan 17, 2025
@davorrunje
Copy link
Collaborator Author

This is needed for #528

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Improvements or additions to documentation infra:build roadmap
Projects
Status: Done
Development

Successfully merging a pull request may close this issue.

2 participants