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

Add "subclass match" for session.get_instance() #7060

Merged
merged 3 commits into from
Sep 23, 2022

Conversation

drew2a
Copy link
Contributor

@drew2a drew2a commented Sep 20, 2022

This PR changes the method Session.get_instance() in such a way that it returns not only instances with direct class match, but instances with subclass match.

This will allow crawlers to make changes to components and communities without making an actual change to the Tribler.

Example:

import asyncio
from pathlib import Path

from tribler.core.components.ipv8.ipv8_component import Ipv8Component
from tribler.core.components.key.key_component import KeyComponent
from tribler.core.components.metadata_store.metadata_store_component import MetadataStoreComponent
from tribler.core.components.tag.tag_component import TagComponent
from tribler.core.config.tribler_config import TriblerConfig
from tribler.core.utilities.tiny_tribler_service import TinyTriblerService


class CustomTagComponent(TagComponent):
    # Apply all necessary changes to the Tag Component here:
    ...


class Service(TinyTriblerService):
    def __init__(self, working_dir):
        super().__init__(TriblerConfig(state_dir=working_dir),
                         working_dir=working_dir,
                         components=[KeyComponent(), Ipv8Component(), MetadataStoreComponent(), CustomTagComponent()])


def run_tribler():
    service = Service(
        working_dir=Path(__file__).parent / 'tribler',
    )

    loop = asyncio.get_event_loop()
    loop.create_task(service.start_tribler())
    try:
        loop.run_forever()
    finally:
        loop.run_until_complete(loop.shutdown_asyncgens())
        loop.close()


if __name__ == "__main__":
    run_tribler()

@drew2a drew2a added this to the 7.13.0 milestone Sep 20, 2022
@drew2a drew2a self-assigned this Sep 20, 2022
@drew2a drew2a marked this pull request as ready for review September 21, 2022 11:08
@drew2a drew2a requested review from a team, xoriole and kozlovsky and removed request for a team September 21, 2022 11:08
Copy link
Contributor

@xoriole xoriole left a comment

Choose a reason for hiding this comment

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

Nice PR!
Love it 👍

src/tribler/core/components/tests/test_base_component.py Outdated Show resolved Hide resolved
@drew2a drew2a force-pushed the feature/improve_components branch 2 times, most recently from fe730ab to b9cba92 Compare September 21, 2022 15:26
@drew2a drew2a requested a review from xoriole September 21, 2022 15:27
@drew2a drew2a merged commit a04eb71 into Tribler:main Sep 23, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

3 participants