-
Notifications
You must be signed in to change notification settings - Fork 452
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
WIP Add dependency-injector to Tribler #6197
Conversation
working_dir, config_path) | ||
|
||
self._interval_in_sec = interval_in_sec | ||
self._output_file_path = output_file_path | ||
|
||
self.application = containers.ApplicationContainer(state_dir=config.state_dir) | ||
self.application.config.from_pydantic(config) | ||
self.application.wire(modules=[Session]) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A good start point to discover PR.
endpoint = providers.Singleton( | ||
DispatcherEndpoint, | ||
providers.List(providers.Object("UDPIPv4")), | ||
UDPIPv4=providers.Dict(port=providers.Factory(config.port), ip=providers.Factory(config.address)), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yep, this line looks not too intuitive 😕. I would expect it to be just UDPIPv4={'port':config.port}
, etc. Why the Factory
stuff is necessary here, what's the semantic reason? Lazy initialization?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It can be replaced by:
endpoint = providers.Singleton(
DispatcherEndpoint, ["UDPIPv4"],
UDPIPv4=providers.Dict(port=config.port, ip=config.address),
)
Explanations later...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you use UDPIPv4={'port':config.port}
you'll get:
{'UDPIPv4': {'port': <dependency_injector.providers.ConfigurationOption('config.port') at 0x112961eb0>}}
from tribler_core.utilities.path_util import Path | ||
|
||
|
||
class TrustChainKeys: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In the future, it is better to leave only the single keypair property in the code, loading either the real key or the testnet key based on the config option. AFAIK, there are no situations where both keys are used in the code simultaneously.
Looks promising! I see you're going to introduce DependencyInjector, but you're still keeping the Session in, right? |
Looks good 👍 All my implementation feedback is already covered by @ichorid. I have two meta questions about what you wrote in O.P.:
|
Kudos, SonarCloud Quality Gate passed! |
This is an example of DI in Tribler.
I've tested it on
initial_filling.py
andrun_tribler.py
.What can I say after a day of work: it works but the framework is surprisingly difficult to understand.
I spent all day trying to make this example runnable.
Partially it is because of the
session.py
organization, but mainly because of the unintuitive framework.(I am not stating that it is bad, but only that it is unintuitive).
Please disregard the writing style, I didn't work on it.
I want to show you roughly what the Tribler with DI will look like.
Framework: https://python-dependency-injector.ets-labs.org/
@ichorid example: https://github.com/Tribler/tribler/pull/6185/files
References:
#4953
#6177