Skip to content

cli: deprecate old config files and plugin dirs #3784

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

Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
cli: deprecate old config files and plugin dirs
- wrap deprecated config and plugin paths in `DeprecatedPath`,
  subclassed from pathlib.Path
- log info messages when loading deprecated configs or plugins
- return success from `Streamlink.load_plugins(path)` to be able to
  log plugin loading messages in the main cli module
  • Loading branch information
bastimeyer committed Jun 6, 2021
commit 7a16adee7a81df3bff161fd5f142c6cf57b2fcfd
24 changes: 24 additions & 0 deletions docs/cli.rst
Original file line number Diff line number Diff line change
Expand Up @@ -96,11 +96,20 @@ your platform:
Platform Location
================= ====================================================
Linux, BSD - ``${XDG_CONFIG_HOME:-${HOME}/.config}/streamlink/config``

Deprecated:

- ``${HOME}/.streamlinkrc``
macOS - ``${HOME}/Library/Application Support/streamlink/config``

Deprecated:

- ``${XDG_CONFIG_HOME:-${HOME}/.config}/streamlink/config``
- ``${HOME}/.streamlinkrc``
Windows - ``%APPDATA%\streamlink\config``

Deprecated:

- ``%APPDATA%\streamlink\streamlinkrc``
================= ====================================================

Expand Down Expand Up @@ -163,11 +172,20 @@ Examples
Platform Location
================= ====================================================
Linux, BSD - ``${XDG_CONFIG_HOME:-${HOME}/.config}/streamlink/config.pluginname``

Deprecated:

- ``${HOME}/.streamlinkrc.pluginname``
macOS - ``${HOME}/Library/Application Support/streamlink/config.pluginname``

Deprecated:

- ``${XDG_CONFIG_HOME:-${HOME}/.config}/streamlink/config.pluginname``
- ``${HOME}/.streamlinkrc.pluginname``
Windows - ``%APPDATA%\streamlink\config.pluginname``

Deprecated:

- ``%APPDATA%\streamlink\streamlinkrc.pluginname``
================= ====================================================

Expand All @@ -186,8 +204,14 @@ Streamlink will attempt to load standalone plugins from these directories:
Platform Location
================= ====================================================
Linux, BSD - ``${XDG_DATA_HOME:-${HOME}/.local/share}/streamlink/plugins``

Deprecated:

- ``${XDG_CONFIG_HOME:-${HOME}/.config}/streamlink/plugins``
macOS - ``${HOME}/Library/Application Support/streamlink/plugins``

Deprecated:

- ``${XDG_CONFIG_HOME:-${HOME}/.config}/streamlink/plugins``
Windows - ``%APPDATA%\streamlink\plugins``
================= ====================================================
Expand Down
8 changes: 6 additions & 2 deletions src/streamlink/session.py
Original file line number Diff line number Diff line change
Expand Up @@ -444,12 +444,13 @@ def get_plugins(self):
def load_builtin_plugins(self):
self.load_plugins(plugins.__path__[0])

def load_plugins(self, path):
def load_plugins(self, path: str) -> bool:
"""Attempt to load plugins from the path specified.

:param path: full path to a directory where to look for plugins

:return: success
"""
success = False
user_input_requester = self.get_option("user-input-requester")
for loader, name, ispkg in pkgutil.iter_modules([path]):
# set the full plugin module name
Expand All @@ -462,12 +463,15 @@ def load_plugins(self, path):

if not hasattr(mod, "__plugin__") or not issubclass(mod.__plugin__, Plugin):
continue
success = True
plugin = mod.__plugin__
plugin.bind(self, name, user_input_requester)
if plugin.module in self.plugins:
log.debug(f"Plugin {plugin.module} is being overridden by {mod.__file__}")
self.plugins[plugin.module] = plugin

return success

@property
def version(self):
return __version__
Expand Down
8 changes: 7 additions & 1 deletion src/streamlink_cli/compat.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,16 @@
import os
import sys
from pathlib import Path


is_darwin = sys.platform == "darwin"
is_win32 = os.name == "nt"

stdout = sys.stdout.buffer


__all__ = ["is_darwin", "is_win32", "stdout"]
class DeprecatedPath(type(Path())):
pass


__all__ = ["is_darwin", "is_win32", "stdout", "DeprecatedPath"]
16 changes: 8 additions & 8 deletions src/streamlink_cli/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from pathlib import Path
from typing import List

from streamlink_cli.compat import is_darwin, is_win32
from streamlink_cli.compat import DeprecatedPath, is_darwin, is_win32

PLAYER_ARGS_INPUT_DEFAULT = "playerinput"
PLAYER_ARGS_INPUT_FALLBACK = "filename"
Expand Down Expand Up @@ -31,7 +31,7 @@
APPDATA = Path(os.environ.get("APPDATA") or Path.home() / "AppData")
CONFIG_FILES = [
APPDATA / "streamlink" / "config",
APPDATA / "streamlink" / "streamlinkrc"
DeprecatedPath(APPDATA / "streamlink" / "streamlinkrc")
]
PLUGIN_DIRS = [
APPDATA / "streamlink" / "plugins"
Expand All @@ -41,25 +41,25 @@
XDG_CONFIG_HOME = Path(os.environ.get("XDG_CONFIG_HOME", "~/.config")).expanduser()
CONFIG_FILES = [
Path.home() / "Library" / "Application Support" / "streamlink" / "config",
XDG_CONFIG_HOME / "streamlink" / "config",
Path.home() / ".streamlinkrc"
DeprecatedPath(XDG_CONFIG_HOME / "streamlink" / "config"),
DeprecatedPath(Path.home() / ".streamlinkrc")
]
PLUGIN_DIRS = [
Path.home() / "Library" / "Application Support" / "streamlink" / "plugins",
XDG_CONFIG_HOME / "streamlink" / "plugins"
DeprecatedPath(XDG_CONFIG_HOME / "streamlink" / "plugins")
]
LOG_DIR = Path.home() / "Library" / "Logs" / "streamlink"
LOG_DIR = DeprecatedPath(Path.home() / "Library" / "Logs" / "streamlink")
else:
XDG_CONFIG_HOME = Path(os.environ.get("XDG_CONFIG_HOME", "~/.config")).expanduser()
XDG_DATA_HOME = Path(os.environ.get("XDG_DATA_HOME", "~/.local/share")).expanduser()
XDG_STATE_HOME = Path(os.environ.get("XDG_STATE_HOME", "~/.local/state")).expanduser()
CONFIG_FILES = [
XDG_CONFIG_HOME / "streamlink" / "config",
Path.home() / ".streamlinkrc"
DeprecatedPath(Path.home() / ".streamlinkrc")
]
PLUGIN_DIRS = [
XDG_DATA_HOME / "streamlink" / "plugins",
XDG_CONFIG_HOME / "streamlink" / "plugins"
DeprecatedPath(XDG_CONFIG_HOME / "streamlink" / "plugins")
]
LOG_DIR = XDG_STATE_HOME / "streamlink" / "logs"

Expand Down
8 changes: 6 additions & 2 deletions src/streamlink_cli/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
from streamlink.stream import StreamProcess
from streamlink.utils import LazyFormatter, NamedPipe
from streamlink_cli.argparser import build_parser
from streamlink_cli.compat import is_win32, stdout
from streamlink_cli.compat import DeprecatedPath, is_win32, stdout
from streamlink_cli.console import ConsoleOutput, ConsoleUserInputRequester
from streamlink_cli.constants import CONFIG_FILES, DEFAULT_STREAM_METADATA, LOG_DIR, PLUGIN_DIRS, STREAM_SYNONYMS
from streamlink_cli.output import FileOutput, PlayerOutput
Expand Down Expand Up @@ -620,7 +620,9 @@ def load_plugins(dirs: List[Path], showwarning: bool = True):
"""Attempts to load plugins from a list of directories."""
for directory in dirs:
if directory.is_dir():
streamlink.load_plugins(str(directory))
success = streamlink.load_plugins(str(directory))
if success and type(directory) is DeprecatedPath:
log.info(f"Loaded plugins from deprecated path, see CLI docs for how to migrate: {directory}")
elif showwarning:
log.warning(f"Plugin path {directory} does not exist or is not a directory!")

Expand All @@ -632,6 +634,8 @@ def setup_args(parser: argparse.ArgumentParser, config_files: List[Path] = None,

# Load arguments from config files
for config_file in filter(lambda path: path.is_file(), config_files or []):
if type(config_file) is DeprecatedPath:
log.info(f"Loaded config from deprecated path, see CLI docs for how to migrate: {config_file}")
arglist.insert(0, f"@{config_file}")

args, unknown = parser.parse_known_args(arglist)
Expand Down