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

Allow optional dependencies between components #6291

Merged
merged 7 commits into from
Aug 25, 2021

Conversation

kozlovsky
Copy link
Contributor

This PR adds an important possibility for components to have optional dependencies.

Basically, it means that a component B can declare: "I don't need to have component A enabled, but if it is enabled, it should be activated before me".

# inside component B:
async def run(self):
    component_a = await self.use(ComponentA, required=False)
    if component_a.enabled:
         foo = component_a.foo
         bar = component_a.bar
     else:
         foo = bar = None

Optional component dependencies are necessary to fix various scripts like run_tunnel_helper.py, as not all components are used in such scripts.

@kozlovsky kozlovsky requested review from ichorid and qstokkink August 25, 2021 08:52
@kozlovsky kozlovsky mentioned this pull request Aug 25, 2021
@kozlovsky kozlovsky marked this pull request as draft August 25, 2021 09:01
qstokkink
qstokkink previously approved these changes Aug 25, 2021
Copy link
Contributor

@qstokkink qstokkink left a comment

Choose a reason for hiding this comment

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

Seems fine to merge as-is.

Some suggestions for improvement (not critical/nitpicks):

  • Refactor out duplicate code in tests into common functions to reduce duplication.
  • Get rid of the loop fixture in these tests. If the fixture is not used (as reported Pylint) it has some hidden side effects that are needed to configure this test (or alternatively: it does nothing). This implies it should've been set somewhere higher up in the fixture hierarchy.

@kozlovsky
Copy link
Contributor Author

@qstokkink Thanks! I'll refactor the tests code a bit later to remove duplication.
Regarding the loop fixture, you are right, and it is not necessary in these tests. I removed it.

@kozlovsky kozlovsky marked this pull request as ready for review August 25, 2021 10:16
@kozlovsky kozlovsky requested a review from qstokkink August 25, 2021 10:16
@sonarqubecloud
Copy link

Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 52 Code Smells

No Coverage information No Coverage information
15.3% 15.3% Duplication

@kozlovsky kozlovsky merged commit 0a1abcf into Tribler:main Aug 25, 2021
@kozlovsky kozlovsky deleted the feature/optional_dependencies branch August 25, 2021 13:27
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.

2 participants