Commit Graph

25 Commits

Author SHA1 Message Date
bastimeyer 45e515eb5a session/plugin: fix DeprecationWarning stacklevel 2023-03-24 09:41:23 -07:00
bastimeyer 151a8d7dbc options: add some MutableMapping methods 2023-02-17 09:54:35 -08:00
bastimeyer 6c2d710eda chore: fix PT009 ruff rule 2023-02-15 17:29:22 -08:00
bastimeyer 656ded9d6c chore: fix PT0{01,03,22,23} ruff rules 2023-02-15 17:29:22 -08:00
bastimeyer 57fa6f80e8 chore: add "COM" rules to ruff config 2023-02-09 10:26:50 -08:00
bastimeyer 0589750c8f options: deprecate global plugin arguments
- Raise `StreamlinkDeprecationWarning` when `is_global=True`
- Remove all global plugin arguments and replace them with simple
  option lookups on the Streamlink session instance
- Remove global argument detection in custom Sphinx plugins extension
- Remove supported plugins list from custom Sphinx argparse extension
  and remove respective setup from `setup_plugin_args` in the CLI module
- Add deprecation note to the docs
- Update tests
  - Check whether builtin plugins define global plugin arguments
  - Capture deprecation warnings
2023-02-03 10:21:31 -08:00
bastimeyer 41c6fa197e options: add support for mapped getters+setters 2023-01-07 18:04:38 -08:00
bastimeyer 6ec535f88f plugin: remove Plugin.bind()
This changes the way how the Streamlink session and other objects like
the plugin cache and logger are stored on each plugin.

Previously, those objects were set as class attributes on every `Plugin`
class via `Plugin.bind()` when loading plugins via the session's
`load_plugins()` method that gets called on initialization.

This meant that whenever a new Streamlink session was initialized,
references to it (including a dict of every loaded plugin) were set
on each `Plugin` class as a class attribute, and Python's garbage
collector could not get rid of this memory when deleting the session
instance that was created last.

Removing `Plugin.bind()`, passing the session via the `Plugin.__init__`
constructor, and setting the cache, logger, etc. on `Plugin` instances
instead (only one gets initialized by `streamlink_cli`), removes those
static references that prevent the garbage collector to work.

Since the plugin "module" name now doesn't get set via `Plugin.bind()`
anymore, it derives its name via `self.__class__.__module__` on its own,
which means a change of the return type of `Streamlink.resolve_url()`
is necessary in order to pass the plugin name to `streamlink_cli`,
so that it can load config files and initialize plugin arguments, etc.

Breaking changes:

- Remove `Plugin.bind()`
- Pass the `session` instance via the Plugin constructor and set the
  `module`, `cache` and `logger` on the plugin instance instead.
  Derive `module` from the actual module name.
- Change the return type of `Session.resolve_url()` and include the
  resolved plugin name in the returned tuple

Other changes:

- Remove `pluginclass.bind()` call from `Session.load_plugins()` and
  use the loader's module name directly on the `Session.plugins` dict
- Remove initialization check from `Plugin` cookie methods
- Update streamlink_cli.main module according to breaking changes
- Update tests respectively
  - Add explicit plugin initialization test
  - Update tests with plugin constructors and custom plugin names
  - Move testplugin override module, so that it shares the same module
    name as the main testplugin module. Rel `Session.load_plugins()`
  - Refactor most session tests and replace unneeded `resolve_url()`
    wrappers in favor of calling `session.streams()`
2022-08-28 12:24:56 -07:00
bastimeyer 60e8724385 tests: refactor options tests 2022-08-24 11:33:54 -07:00
bastimeyer 5985f08570 cli: refactor nested argparse argument groups
- Use a custom mapping of parent->child argument group relations
  instead of calling `group.add_argument_group()` for creating
  a tree structure of argument groups (deprecated in Python 3.11)
- Override `parser.add_argument_group()` and add the `parent` keyword
  for being able to have nested argument group defintions
- Update custom `--help` format output
- Update the argparser Sphinx extension
- Fix tests
2022-07-12 09:42:09 -07:00
bastimeyer f5c19bb08f cli: move plugin args into their own args group
This adds a second layer of plugin argument groups, so that the docs can
show menu items for each plugin which makes finding them is easier.

- make the doc's argparse extension read argparse groups recursively
- override argparse.ArgumentParser.format_help and show nested groups
- fix/update tests
2020-12-10 11:57:53 -08:00
bastimeyer 9a961f6ddc plugin: implement global plugin arguments
- Add `is_global` parameter to `streamlink.options.Argument`
  Global plugin arguments reference Streamlink's global arguments by
  name and cannot receive any other parameters, like `required`, etc.
- In `streamlink_cli.main.setup_plugin_args`, find the global argument
  references of each plugin, set the available default values and add
  the plugin to the argument's `plugins` list, which will be read by
  the docs generator
- In `streamlink_cli.main.setup_plugin_options`, set the provided
  global argument values on the plugin's `options` dictionary
- Refactor docs/ext_argparse
  - Don't override argparse.ArgumentParser when importing the parser
  - Add list of supported plugins to the parameter description if the
    `plugins` list is set on the argparse action object
- Add/improve/fix tests
2020-11-14 08:54:28 +01:00
beardypig a585e88297 chore: sort imports, fix a dependency cycle and use absolute imports
Co-authored-by: bastimeyer <mail@bastimeyer.de>
2020-10-27 17:17:49 +01:00
bastimeyer f538d684df chore: remove compat imports from tests 2020-10-19 17:48:57 +02:00
bastimeyer 2d7d15aa87 cleanup: remove unnecessary unittest.main() calls 2020-02-25 05:35:16 +01:00
bastimeyer 76f162e04c flake8: F401, F403
F401 '...' imported but unused
F403 'from ... import *' used; unable to detect undefined names
2020-02-19 18:43:05 +01:00
bastimeyer 1878c59d75 flake8: E303
E303 too many blank lines
2020-02-19 18:40:29 +01:00
beardypig c9fff48e9a Test coverage increase (#1646)
* tests: logger tests

* test: file stream

* test: missing sessions tests

* test: missing util tests

* tests: call can_handle_url for each plugin to ensure it won't error

* tests: speed up by 2 seconds, mocking sleep

* test for streamname lookups

* refactor test structure

* tests: rebase plugins tests

* tests: no need for Python 3.6 support

* tests: remove 2.6 from the travis build

* tests: rebase on master

* tests: rename plugin.api tests

* tests: add mock http resource

* move new plugin tests

* rebase master

* tests: coverage for ConsoleOutput
2018-06-29 11:31:37 -07:00
beardypig 9d63e64bbc API for plugins to request input from the user (#1827)
* API for plugins to request input from the user

* console: handle lack of TTY for user input

* New fatal plugin error, for unrecoverable errors

* tests: remove deprecated calls
2018-06-21 16:15:21 -07:00
beardypig d7a27b31b0 Plugin Arguments API (#1638)
* plugins: PluginArguments API

Allow plugins to specify arguments within the Plugin class.
This makes it easier to add and test plugin specific arguments, as well
as enabling sideloaded plugins to support command line arguments.

* update docs build to work with the new plugin arguments

* fix argument name override for funimation and ustream

* add some more tests for options/arguments

* rebase with abweb plugin

* switch to RuntimeException for py2 compat

* fix bug where required arguments were not prompted

* bug fixes for option names in plugins, should match existing names

* restore "normal" exception messages

* missed a RecursionError -> RuntimeError

* updated the api slightly with better (I think) argument name

added some docs for the Argument and Arguments classes

* options/args: normalise option names to replace - with _, and ensure the defaults are set

* normalise the plugin module name, replacing _ with -

* style issues pointed out by @back-to

* plugin.btsports: update to use PluginArguments

* plugins.bbciplayer: add hd argument

* plugins.twitch: move --twitch-oauth-authenticate back to argparser

Moved the option back to argparser as it's a special case.

* test: fixed typo
2018-05-25 14:25:15 -07:00
stepshal 34e68540d8 PEP8 (#414)
* Remove extraneous whitespace.

* Fix non-membership check.

* Add absent indentation for hanging indentation.

* Align closing bracket to match visual indentation.

* Indent to distinguish line from next logical line.

* Fix over-idented lines for visual indentation.

* Fix under-idented lines for visual indentation.

* Fix bare except:

* Remove missing whitespace.

* Fix missing whitespace around arithmetic operator.

* Fix missing whitespace around operator.

* Fix over-indented hanging indentation.

* Remove whitespace around parameter '=' sign.

* Align closing bracket to match opening bracket.

* Fix spacing after comment hash for inline comments.

* Replace tabs with spaces.

* Fix over-indented hanging indentation.

* Fix comparison with boolean.

* Remove extraneous escape of newline.

* Align closing bracket to match opening bracket.

* Make identation multiple of four.

* Fix extraneous whitespace around keywords.

* Put colon-separated compound statement on separate lines.

* Put semicolon-separated compound statement on separate lines.

* Fix extraneous whitespace around keywords.

* Add missing 2 blank lines.

* Remove extra blank lines.

* Put imports on separate lines.

* Fix do not assign a lambda expression check.

* Add missing blank line.
2017-01-16 09:57:12 -08:00
stepshal a81e405030 Remove trailing. 2017-01-12 22:12:07 +07:00
stepshal 922e169207 Add blank line after class or function definition (#408) 2017-01-12 14:54:55 +00:00
Charlie Drage a6ceedc4e7 Rename instances of "livestreamer" to "streamlink"
Renames all instances of "livestreamer" to "streamlink".
2016-09-19 15:46:06 -04:00
Christopher Rosell 443546f30b Add some unit testing. 2012-11-19 03:47:13 +01:00