From c70d2c46ddb304ffe56b77579da3a5fda8dcea1b Mon Sep 17 00:00:00 2001 From: kannibalox Date: Sun, 22 Jan 2023 13:14:33 -0500 Subject: [PATCH] Fix linting Also move load check to settings instead of a module-level variable --- src/pyrosimple/config.py | 10 ++++------ src/pyrosimple/scripts/rtxmlrpc.py | 2 +- 2 files changed, 5 insertions(+), 7 deletions(-) diff --git a/src/pyrosimple/config.py b/src/pyrosimple/config.py index 7d7a3acc..5876a995 100644 --- a/src/pyrosimple/config.py +++ b/src/pyrosimple/config.py @@ -26,6 +26,7 @@ # Top-level settings Validator("RTORRENT_RC", default="~/.rtorrent.rc"), Validator("CONFIG_PY", default="~/.config/pyrosimple/config.py"), + Validator("CONFIG_PY_LOADED", default=False), Validator("SORT_FIELDS", default="name,hash"), Validator("FAST_QUERY", gte=0, lte=2, default=0), Validator("ITEM_CACHE_EXPIRATION", default=5.0), @@ -184,25 +185,22 @@ def map_announce2alias(url: str) -> str: return parts.netloc -CUSTOM_PY_LOADED = False - - def load_custom_py(): """Load custom python configuration. This only gets called when CLI tools are called to prevent some weird code injection""" - if CUSTOM_PY_LOADED: - return log = logging.getLogger(__name__) if not settings.CONFIG_PY: log.debug("Custom code loading is disabled") + if settings.CONFIG_PY_LOADED: + log.debug("Custom code has already been loaded") config_file = Path(settings.CONFIG_PY).expanduser() if config_file.exists(): log.debug("Loading '%s'...", config_file) with open(config_file, "rb") as handle: # pylint: disable=exec-used exec(handle.read()) - CUSTOM_PY_LOADED = True + settings.CONFIG_PY_LOADED = True else: log.debug("Configuration file '%s' not found.", config_file) diff --git a/src/pyrosimple/scripts/rtxmlrpc.py b/src/pyrosimple/scripts/rtxmlrpc.py index 72f5bc37..e5586a4a 100644 --- a/src/pyrosimple/scripts/rtxmlrpc.py +++ b/src/pyrosimple/scripts/rtxmlrpc.py @@ -29,7 +29,7 @@ def read_blob(arg: str) -> bytes: if any(arg.startswith(f"@{x}://") for x in ["http", "https", "ftp", "file"]): try: - import requests + import requests # pylint: disable=import-outside-toplevel response = requests.get(arg[1:], timeout=60) response.raise_for_status()