Skip to content

Commit

Permalink
Fix linting
Browse files Browse the repository at this point in the history
Also move load check to settings instead of a module-level variable
  • Loading branch information
kannibalox committed Jan 22, 2023
1 parent d9fbc3e commit c70d2c4
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 7 deletions.
10 changes: 4 additions & 6 deletions src/pyrosimple/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down Expand Up @@ -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)

Expand Down
2 changes: 1 addition & 1 deletion src/pyrosimple/scripts/rtxmlrpc.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down

0 comments on commit c70d2c4

Please sign in to comment.