🚨 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
+36 -66
View File
@@ -2,6 +2,8 @@
import os
import re
import subprocess
import sys
from pathlib import Path
from typing import Any, Dict, List
import requests
@@ -9,7 +11,8 @@ from loguru import logger
from requests import Response
from src.config import RevancedConfig
from src.exceptions import DownloadFailure
from src.downloader.utils import status_code_200
from src.exceptions import DownloadError
default_build = [
"youtube",
@@ -28,8 +31,7 @@ bs4_parser = "html.parser"
def update_changelog(name: str, response: Dict[str, str]) -> None:
"""The function `update_changelog` updates the changelog file with the
provided name and response.
"""The function `update_changelog` updates the changelog file.
Parameters
----------
@@ -46,8 +48,7 @@ def update_changelog(name: str, response: Dict[str, str]) -> None:
def format_changelog(name: str, response: Dict[str, str], parent_repo: str) -> str:
"""The `format_changelog` function takes in a name, a response dictionary,
and a parent repository, and returns a formatted changelog string.
"""The `format_changelog` returns formatted changelog string.
Parameters
----------
@@ -67,43 +68,28 @@ def format_changelog(name: str, response: Dict[str, str], parent_repo: str) -> s
a formatted changelog as a string.
"""
collapse_start = f"\n<details> <summary>👀 {name} </summary>\n\n"
release_version = (
f"**Release Version** - [{response['tag_name']}]({response['html_url']})<br>"
)
release_version = f"**Release Version** - [{response['tag_name']}]({response['html_url']})<br>"
change_log = f"**Changelog** -<br> {response['body']}"
publish_time = f"**Published at** -<br> {response['published_at']}"
footer = (
f"<br><sub>Change logs generated by [Docker Py Revanced]({parent_repo})</sub>\n"
)
footer = f"<br><sub>Change logs generated by [Docker Py Revanced]({parent_repo})</sub>\n"
collapse_end = "</details>"
return "".join(
[
collapse_start,
release_version,
change_log,
publish_time,
footer,
collapse_end,
]
)
return f"{collapse_start}{release_version}{change_log}{publish_time}{footer}{collapse_end}"
def write_to_file(change_log: str) -> None:
"""The function `write_to_file` writes a given changelog string to a file
named "changelog.md".
"""The function `write_to_file` writes a given changelog string to a file.
Parameters
----------
change_log : str
A string representing the changelog that you want to write to the file.
"""
with open("changelog.md", "w", encoding="utf_8") as file1:
with Path("changelog.md").open("w", encoding="utf_8") as file1:
file1.write(change_log)
def get_parent_repo() -> str:
"""The function `get_parent_repo()` returns the URL of the parent
repository.
"""The `get_parent_repo()` function returns the URL of the parent repository.
Returns
-------
@@ -113,8 +99,7 @@ def get_parent_repo() -> str:
def handle_request_response(response: Response) -> None:
"""The function handles the response of a GET request and raises an
exception if the response code is not 200.
"""The function handles the response of a GET request and raises an exception if the response code is not 200.
Parameters
----------
@@ -124,14 +109,13 @@ def handle_request_response(response: Response) -> None:
server, such as the status code, headers, and response body.
"""
response_code = response.status_code
if response_code != 200:
raise DownloadFailure(f"Unable to downloaded assets. Reason - {response.text}")
if response_code != status_code_200:
msg = f"Unable to downloaded assets. Reason - {response.text}"
raise DownloadError(msg)
def slugify(string: str) -> str:
"""The `slugify` function converts a string to a slug format by converting
it to lowercase, removing special characters, replacing spaces with dashes,
removing consecutive dashes, and removing leading and trailing dashes.
"""The `slugify` function converts a string to a slug format.
Parameters
----------
@@ -155,47 +139,36 @@ def slugify(string: str) -> str:
modified_string = re.sub(r"-+", "-", modified_string)
# Remove leading and trailing dashes
modified_string = modified_string.strip("-")
return modified_string
return modified_string.strip("-")
def check_java(dry_run: bool) -> None:
"""The function `check_java` checks if Java version 17 or higher is
installed and logs an error message if it is not.
def _check_version(output: str) -> None:
"""Check version."""
if "Runtime Environment" not in output:
raise subprocess.CalledProcessError(-1, "java -version")
if "17" not in output and "20" not in output:
raise subprocess.CalledProcessError(-1, "java -version")
Parameters
----------
dry_run : bool
The `dry_run` parameter is a boolean flag that determines whether the function should actually
check if Java is installed or just simulate the check. If `dry_run` is `True`, the function will
return without performing the check. If `dry_run` is `False`, the function will execute the
def check_java() -> None:
"""The function `check_java` checks if Java version 17 or higher is installed.
Returns
-------
The function `check_java` does not return any value. It has a return type annotation of `None`,
indicating that it does not return anything.
The function `check_java` does not return any value.
"""
try:
if dry_run:
return
jd = subprocess.check_output(
["java", "-version"], stderr=subprocess.STDOUT
).decode("utf-8")
jd = subprocess.check_output(["java", "-version"], stderr=subprocess.STDOUT).decode("utf-8")
jd = jd[1:-1]
if "Runtime Environment" not in jd:
raise subprocess.CalledProcessError(-1, "java -version")
if "17" not in jd and "20" not in jd:
raise subprocess.CalledProcessError(-1, "java -version")
_check_version(jd)
logger.debug("Cool!! Java is available")
except subprocess.CalledProcessError:
logger.error("Java>= 17 must be installed")
exit(-1)
sys.exit(-1)
def extra_downloads(config: RevancedConfig) -> None:
"""The function `extra_downloads` downloads extra files specified in the
`config` object using the `APP.download` method.
"""The function `extra_downloads` downloads extra files specified.
Parameters
----------
@@ -217,15 +190,11 @@ def extra_downloads(config: RevancedConfig) -> None:
file_name=new_file_name,
)
except (ValueError, IndexError):
logger.info(
"Unable to download extra file. Provide input in url@name.apk format."
)
logger.info("Unable to download extra file. Provide input in url@name.apk format.")
def apkmirror_status_check(package_name: str) -> Any:
"""The `apkmirror_status_check` function checks if an app exists on
APKMirror by making a POST request to the APKMirror API with the package
name as a parameter.
"""The `apkmirror_status_check` function checks if an app exists on APKMirror.
Parameters
----------
@@ -239,9 +208,10 @@ def apkmirror_status_check(package_name: str) -> Any:
"""
api_url = f"{apk_mirror_base_url}/wp-json/apkm/v1/app_exists/"
body = {"pnames": [package_name]}
response = requests.post(api_url, json=body, headers=request_header)
response = requests.post(api_url, json=body, headers=request_header, timeout=60)
return response.json()
def contains_any_word(string: str, words: List[str]) -> bool:
"""Checks if a string contains any word."""
return any(word in string for word in words)