🚨 Updated lints (#308)

This commit is contained in:
Nikhil Badyal
2023-08-25 15:36:50 +05:30
committed by GitHub
parent 09b815cb21
commit 77377cdd48
26 changed files with 404 additions and 487 deletions
+23 -34
View File
@@ -1,18 +1,18 @@
"""Revanced Parser."""
from subprocess import PIPE, Popen
from time import perf_counter
from typing import List
from typing import List, Self
from loguru import logger
from src.app import APP
from src.config import RevancedConfig
from src.exceptions import PatchingFailed
from src.exceptions import PatchingFailedError
from src.patches import Patches
from src.utils import possible_archs
class Parser(object):
class Parser:
"""Revanced Parser."""
CLI_JAR = "-jar"
@@ -23,13 +23,13 @@ class Parser(object):
KEYSTORE_ARG = "--keystore"
OPTIONS_ARG = "--options"
def __init__(self, patcher: Patches, config: RevancedConfig) -> None:
def __init__(self: Self, patcher: Patches, config: RevancedConfig) -> None:
self._PATCHES: List[str] = []
self._EXCLUDED: List[str] = []
self.patcher = patcher
self.config = config
def include(self, name: str) -> None:
def include(self: Self, name: str) -> None:
"""The function `include` adds a given patch to a list of patches.
Parameters
@@ -39,9 +39,8 @@ class Parser(object):
"""
self._PATCHES.extend(["-i", name])
def exclude(self, name: str) -> None:
"""The `exclude` function adds a given patch to the list of excluded
patches.
def exclude(self: Self, name: str) -> None:
"""The `exclude` function adds a given patch to the list of excluded patches.
Parameters
----------
@@ -51,9 +50,8 @@ class Parser(object):
self._PATCHES.extend(["-e", name])
self._EXCLUDED.append(name)
def get_excluded_patches(self) -> List[str]:
"""The function `get_excluded_patches` is a getter method that returns
a list of excluded patches.
def get_excluded_patches(self: Self) -> List[str]:
"""The function `get_excluded_patches` is a getter method that returns a list of excluded patches.
Returns
-------
@@ -61,9 +59,8 @@ class Parser(object):
"""
return self._EXCLUDED
def get_all_patches(self) -> List[str]:
"""The function "get_all_patches" is a getter method that returns a
list of all patches.
def get_all_patches(self: Self) -> List[str]:
"""The function "get_all_patches" is a getter method that returns a ist of all patches.
Returns
-------
@@ -71,9 +68,8 @@ class Parser(object):
"""
return self._PATCHES
def invert_patch(self, name: str) -> bool:
"""The function `invert_patch` takes a name as input, it toggles the
status of the patch and returns True, otherwise it returns False.
def invert_patch(self: Self, name: str) -> bool:
"""The function `invert_patch` takes a name as input, it toggles the status of the patch.
Parameters
----------
@@ -94,27 +90,23 @@ class Parser(object):
self._PATCHES[patch_index - 1] = "-i"
else:
self._PATCHES[patch_index - 1] = "-e"
return True
except ValueError:
return False
else:
return True
def exclude_all_patches(self) -> None:
"""The function `exclude_all_patches` replaces all occurrences of "-i"
with "-e" in the list `self._PATCHES`.
Hence exclude all patches
"""
def exclude_all_patches(self: Self) -> None:
"""The function `exclude_all_patches` exclude all the patches."""
for idx, item in enumerate(self._PATCHES):
if item == "-i":
self._PATCHES[idx] = "-e"
# noinspection IncorrectFormatting
def patch_app(
self,
self: Self,
app: APP,
) -> None:
"""The function `patch_app` is used to patch an app using the Revanced
CLI tool.
"""The function `patch_app` is used to patch an app using the Revanced CLI tool.
Parameters
----------
@@ -151,16 +143,13 @@ class Parser(object):
for arch in excluded:
args.extend(("--rip-lib", arch))
start = perf_counter()
logger.debug(
f"Sending request to revanced cli for building with args java {args}"
)
logger.debug(f"Sending request to revanced cli for building with args java {args}")
process = Popen(["java", *args], stdout=PIPE)
output = process.stdout
if not output:
raise PatchingFailed("Failed to send request for patching.")
msg = "Failed to send request for patching."
raise PatchingFailedError(msg)
for line in output:
logger.debug(line.decode(), flush=True, end="")
process.wait()
logger.info(
f"Patching completed for app {app} in {perf_counter() - start:.2f} seconds."
)
logger.info(f"Patching completed for app {app} in {perf_counter() - start:.2f} seconds.")