-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
session: replace usage of deprecated imp module #3366
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
Conversation
Refactor `utils.load_module`: - move it to the top and add it to `__all__` - move imports and loader_details to the global scope Refactor `session`: - replace plugin imports via `imp` with `utils.load_module` - fix incorrect plugin module names "streamlink.plugin.{name}" -> "streamlink.plugins.{name}" - use `log.exception()` to print plugin load failures - remove unused `print_small_exception` Add / fix tests: - remove session dependency from test_plugins - add proper assertions for plugin modules, methods and their signatures - add tests for invalid and for overridden plugins
5ccfe38
to
5e7a04b
Compare
streamlink/src/streamlink/session.py Lines 413 to 417 in 5e7a04b
it is not always Not that important but just to be noted.
we don't need it, could probably be removed, |
According to the docs, both the finder and loader will raise an |
Example: if you sideload a broken plugin
|
If you want, I can "revert" this change of logic by adding a secondary I personally am OK though with Streamlink failing if code of a custom plugin causes a parsing error. |
no it's fine, can stay like this. |
well, lets test this with a large user base. |
Maybe we should add a note to the sideloading plugins section in the docs that plugins which fail parsing will make Streamlink terminate its process beginning with 2.0.0. Will also take a look at the support_plugin thing again. I don't think it makes sense keeping it. |
since streamlink#3366 https://github.com/streamlink/streamlink/blob/5e7a04b006d0e4d7a884b13bf2aa8047791b837b/src/streamlink/session.py#L412 the logger is `[plugins.afreeca]` which was `[plugin.afreeca]` before update the cls.logger so it will be `[plugins.afreeca]` also after this PR ``` [plugins.afreeca][debug] Restored cookies: ... ... [plugins.afreeca][debug] Attempting to authenticate using cached cookies ```
since #3366 https://github.com/streamlink/streamlink/blob/5e7a04b006d0e4d7a884b13bf2aa8047791b837b/src/streamlink/session.py#L412 the logger is `[plugins.afreeca]` which was `[plugin.afreeca]` before update the cls.logger so it will be `[plugins.afreeca]` also after this PR ``` [plugins.afreeca][debug] Restored cookies: ... ... [plugins.afreeca][debug] Attempting to authenticate using cached cookies ```
since streamlink#3366 https://github.com/streamlink/streamlink/blob/5e7a04b006d0e4d7a884b13bf2aa8047791b837b/src/streamlink/session.py#L412 the logger is `[plugins.afreeca]` which was `[plugin.afreeca]` before update the cls.logger so it will be `[plugins.afreeca]` also after this PR ``` [plugins.afreeca][debug] Restored cookies: ... ... [plugins.afreeca][debug] Attempting to authenticate using cached cookies ```
since streamlink#3366 https://github.com/streamlink/streamlink/blob/5e7a04b006d0e4d7a884b13bf2aa8047791b837b/src/streamlink/session.py#L412 the logger is `[plugins.afreeca]` which was `[plugin.afreeca]` before update the cls.logger so it will be `[plugins.afreeca]` also after this PR ``` [plugins.afreeca][debug] Restored cookies: ... ... [plugins.afreeca][debug] Attempting to authenticate using cached cookies ```
- add proper assertions for plugin modules, methods and their signatures - add tests for invalid and for overridden plugins based on streamlink#3366
- add proper assertions for plugin modules, methods and their signatures - add tests for invalid and for overridden plugins based on streamlink#3366
- add proper assertions for plugin modules, methods and their signatures - add tests for invalid and for overridden plugins based on streamlink#3366
- add proper assertions for plugin modules, methods and their signatures - add tests for invalid and for overridden plugins based on streamlink#3366 Update test_plugins.py
Refactor
utils.load_module
:__all__
Refactor
session
:imp
withutils.load_module
"streamlink.plugin.{name}" -> "streamlink.plugins.{name}"
log.exception()
to print plugin load failuresprint_small_exception
Add / fix tests:
Based on the changes of #2570
Things to note
importlib.machinery.FileFinder
in theutils
module and use that for loading the plugins, as I had some issues with the module names while trying out thepkgutils
-based imports of session: use importlib to load plugins in Python 3 #2570, which led to plugins log calls not being recognized by the StreamlinkLogger, as their module names did not begin withstreamlink.
.test_session
is really messy as it imports everything intests.plugins
, including all plugin test modules, which are irrelevant there. The actualtestplugin
s should be moved somewhere else. Mocking certain things is also impossible when everything is run in the test'ssetUp
, and I couldn't mock the log call of the plugin override without patching the whole test class which would require adding an unused argument to every test method. That's why plugin load failures are also not tested.plugin.api.support_plugin
even exist? It's not being used and it looks totally unnecessary. This module is the reason whyutils.load_module
existed, but now it's being used bysession
as well.