mirror of
https://github.com/apache/superset.git
synced 2026-04-19 08:04:53 +00:00
chore: enforce more ruff rules (#31447)
Co-authored-by: Elizabeth Thompson <eschutho@gmail.com>
This commit is contained in:
committed by
GitHub
parent
9da65d6bfd
commit
e51b95ffa8
@@ -70,7 +70,7 @@ def extract_modified_tables(module: ModuleType) -> set[str]:
|
||||
return tables
|
||||
|
||||
|
||||
def find_models(module: ModuleType) -> list[type[Model]]:
|
||||
def find_models(module: ModuleType) -> list[type[Model]]: # noqa: C901
|
||||
"""
|
||||
Find all models in a migration script.
|
||||
"""
|
||||
@@ -94,7 +94,7 @@ def find_models(module: ModuleType) -> list[type[Model]]:
|
||||
# downgrade
|
||||
sqlalchemy_uri = current_app.config["SQLALCHEMY_DATABASE_URI"]
|
||||
engine = create_engine(sqlalchemy_uri)
|
||||
Base = automap_base()
|
||||
Base = automap_base() # noqa: N806
|
||||
Base.prepare(engine, reflect=True)
|
||||
seen = set()
|
||||
while tables:
|
||||
@@ -138,7 +138,7 @@ def find_models(module: ModuleType) -> list[type[Model]]:
|
||||
@click.option("--limit", default=1000, help="Maximum number of entities.")
|
||||
@click.option("--force", is_flag=True, help="Do not prompt for confirmation.")
|
||||
@click.option("--no-auto-cleanup", is_flag=True, help="Do not remove created models.")
|
||||
def main(
|
||||
def main( # noqa: C901
|
||||
filepath: str, limit: int = 1000, force: bool = False, no_auto_cleanup: bool = False
|
||||
) -> None:
|
||||
auto_cleanup = not no_auto_cleanup
|
||||
|
||||
@@ -49,7 +49,7 @@ github_repo = os.environ.get("GITHUB_REPOSITORY", "apache/superset")
|
||||
def request(
|
||||
method: Literal["GET", "POST", "DELETE", "PUT"], endpoint: str, **kwargs: Any
|
||||
) -> dict[str, Any]:
|
||||
resp = requests.request(
|
||||
resp = requests.request( # noqa: S113
|
||||
method,
|
||||
f"https://api.github.com/{endpoint.lstrip('/')}",
|
||||
headers={"Authorization": f"Bearer {github_token}"},
|
||||
@@ -152,7 +152,7 @@ Date: {date_str}
|
||||
help="Whether to also cancel running workflows.",
|
||||
)
|
||||
@click.argument("branch_or_pull", required=False)
|
||||
def cancel_github_workflows(
|
||||
def cancel_github_workflows( # noqa: C901
|
||||
branch_or_pull: Optional[str],
|
||||
repo: str,
|
||||
event: list[str],
|
||||
|
||||
@@ -51,12 +51,12 @@ GITHUB_TOKEN = os.environ.get("GITHUB_TOKEN")
|
||||
|
||||
def fetch_files_github_api(url: str): # type: ignore
|
||||
"""Fetches data using GitHub API."""
|
||||
req = Request(url)
|
||||
req = Request(url) # noqa: S310
|
||||
req.add_header("Authorization", f"Bearer {GITHUB_TOKEN}")
|
||||
req.add_header("Accept", "application/vnd.github.v3+json")
|
||||
|
||||
print(f"Fetching from {url}")
|
||||
with urlopen(req) as response:
|
||||
with urlopen(req) as response: # noqa: S310
|
||||
body = response.read()
|
||||
return json.loads(body)
|
||||
|
||||
@@ -130,7 +130,7 @@ def main(event_type: str, sha: str, repo: str) -> None:
|
||||
)
|
||||
|
||||
# Output results
|
||||
output_path = os.getenv("GITHUB_OUTPUT") or "/tmp/GITHUB_OUTPUT.txt"
|
||||
output_path = os.getenv("GITHUB_OUTPUT") or "/tmp/GITHUB_OUTPUT.txt" # noqa: S108
|
||||
with open(output_path, "a") as f:
|
||||
for check, changed in changes_detected.items():
|
||||
if changed:
|
||||
@@ -139,8 +139,8 @@ def main(event_type: str, sha: str, repo: str) -> None:
|
||||
|
||||
|
||||
def get_git_sha() -> str:
|
||||
return os.getenv("GITHUB_SHA") or subprocess.check_output(
|
||||
["git", "rev-parse", "HEAD"]
|
||||
return os.getenv("GITHUB_SHA") or subprocess.check_output( # noqa: S603
|
||||
["git", "rev-parse", "HEAD"] # noqa: S607
|
||||
).strip().decode("utf-8")
|
||||
|
||||
|
||||
|
||||
@@ -47,7 +47,7 @@ class Requirement:
|
||||
|
||||
def get_version(self) -> Optional[str]:
|
||||
try:
|
||||
version = subprocess.check_output(self.command, shell=True).decode().strip()
|
||||
version = subprocess.check_output(self.command, shell=True).decode().strip() # noqa: S602
|
||||
if self.version_post_process:
|
||||
version = self.version_post_process(version)
|
||||
return version.split()[-1]
|
||||
@@ -76,7 +76,7 @@ class Requirement:
|
||||
def format_result(self) -> str:
|
||||
ideal_range_str = f"{self.ideal_range[0]} - {self.ideal_range[1]}"
|
||||
supported_range_str = f"{self.supported_range[0]} - {self.supported_range[1]}"
|
||||
return f"{self.status.split()[0]} {self.name:<25} {self.version or 'N/A':<25} {ideal_range_str:<25} {supported_range_str:<25}"
|
||||
return f"{self.status.split()[0]} {self.name:<25} {self.version or 'N/A':<25} {ideal_range_str:<25} {supported_range_str:<25}" # noqa: E501
|
||||
|
||||
|
||||
def check_memory(min_gb: int) -> str:
|
||||
@@ -101,8 +101,9 @@ def get_cpu_info() -> str:
|
||||
def get_docker_platform() -> str:
|
||||
try:
|
||||
output = (
|
||||
subprocess.check_output(
|
||||
"docker info --format '{{.OperatingSystem}}'", shell=True
|
||||
subprocess.check_output( # noqa: S602
|
||||
"docker info --format '{{.OperatingSystem}}'", # noqa: S607
|
||||
shell=True, # noqa: S607
|
||||
)
|
||||
.decode()
|
||||
.strip()
|
||||
@@ -117,7 +118,7 @@ def get_docker_platform() -> str:
|
||||
@click.command(
|
||||
help="""
|
||||
This script checks the local environment for various software versions and other requirements, providing feedback on whether they are ideal, supported, or unsupported.
|
||||
"""
|
||||
""" # noqa: E501
|
||||
)
|
||||
@click.option(
|
||||
"--docker", is_flag=True, help="Check Docker and Docker Compose requirements"
|
||||
@@ -128,7 +129,7 @@ This script checks the local environment for various software versions and other
|
||||
help="Check frontend requirements (npm, Node.js, memory)",
|
||||
)
|
||||
@click.option("--backend", is_flag=True, help="Check backend requirements (Python)")
|
||||
def main(docker: bool, frontend: bool, backend: bool) -> None:
|
||||
def main(docker: bool, frontend: bool, backend: bool) -> None: # noqa: C901
|
||||
requirements = [
|
||||
Requirement(
|
||||
"python",
|
||||
|
||||
@@ -74,7 +74,7 @@ def run_cypress_for_test_file(
|
||||
print(f"DRY RUN: {cmd}")
|
||||
return 0
|
||||
|
||||
process = subprocess.Popen(
|
||||
process = subprocess.Popen( # noqa: S602
|
||||
cmd,
|
||||
shell=True,
|
||||
stdout=subprocess.PIPE,
|
||||
|
||||
@@ -171,7 +171,7 @@ def generate_erd(file_path: str) -> None:
|
||||
"""
|
||||
data = introspect_models()
|
||||
templates_path = os.path.dirname(__file__)
|
||||
env = jinja2.Environment(loader=jinja2.FileSystemLoader(templates_path))
|
||||
env = jinja2.Environment(loader=jinja2.FileSystemLoader(templates_path)) # noqa: S701
|
||||
|
||||
# Load the template
|
||||
template = env.get_template("erd.template.puml")
|
||||
|
||||
Reference in New Issue
Block a user