diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml index 425e8d1a07c46..3aece2f4d71b1 100644 --- a/.github/workflows/lint.yml +++ b/.github/workflows/lint.yml @@ -33,3 +33,9 @@ jobs: steps: - uses: actions/checkout@v4 - uses: lunarmodules/luacheck@v1 + + python-lint: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - uses: chartboost/ruff-action@v1 diff --git a/TOOLS/docutils-wrapper.py b/TOOLS/docutils-wrapper.py index 31ba976e64f8b..8e4ce57dc5060 100755 --- a/TOOLS/docutils-wrapper.py +++ b/TOOLS/docutils-wrapper.py @@ -58,7 +58,7 @@ def remove(path): proc = subprocess.run(argv, check=True) if depfile is not None: convert_depfile(output, depfile) -except: +except Exception: remove(output) if depfile is not None: remove(depfile) diff --git a/TOOLS/dylib_unhell.py b/TOOLS/dylib_unhell.py index c8859692845b3..ed2136554d85d 100755 --- a/TOOLS/dylib_unhell.py +++ b/TOOLS/dylib_unhell.py @@ -16,13 +16,13 @@ def is_user_lib(objfile, libname): return not sys_re.match(libname) and \ not usr_re.match(libname) and \ not exe_re.match(libname) and \ - not "libobjc." in libname and \ - not "libSystem." in libname and \ - not "libc." in libname and \ - not "libgcc." in libname and \ + "libobjc." not in libname and \ + "libSystem." not in libname and \ + "libc." not in libname and \ + "libgcc." not in libname and \ not os.path.basename(libname) == 'Python' and \ - not os.path.basename(objfile) in libname and \ - not "libswift" in libname + os.path.basename(objfile) not in libname and \ + "libswift" not in libname def otool(objfile, rapths): command = "otool -L '%s' | grep -e '\t' | awk '{ print $1 }'" % objfile @@ -46,7 +46,7 @@ def get_rapths(objfile): try: result = subprocess.check_output(command, shell = True, universal_newlines=True) - except: + except Exception: return rpaths for line in result.splitlines(): @@ -90,9 +90,9 @@ def resolve_lib_path(objfile, lib, rapths): def check_vulkan_max_version(version): try: - result = subprocess.check_output("pkg-config vulkan --max-version=" + version, shell = True) + subprocess.check_output("pkg-config vulkan --max-version=" + version, shell = True) return True - except: + except Exception: return False def get_homebrew_prefix(): @@ -100,7 +100,7 @@ def get_homebrew_prefix(): result = "/opt/homebrew" try: result = subprocess.check_output("brew --prefix", universal_newlines=True, shell=True, stderr=subprocess.DEVNULL).strip() - except: + except Exception: pass return result diff --git a/TOOLS/macos-sdk-version.py b/TOOLS/macos-sdk-version.py index 12e1071d7588f..eadfda414dc6f 100755 --- a/TOOLS/macos-sdk-version.py +++ b/TOOLS/macos-sdk-version.py @@ -3,9 +3,7 @@ # This checks for the sdk path, the sdk version, and # the sdk build version. -import re import os -import string import subprocess import sys from shutil import which @@ -33,7 +31,7 @@ def find_macos_sdk(): try: sdk_version = check_output([xcodebuild, '-sdk', 'macosx', '-version', 'ProductVersion'], encoding="UTF-8", stderr=subprocess.DEVNULL) - except: + except Exception: pass if not isinstance(sdk_version, str): diff --git a/TOOLS/matroska.py b/TOOLS/matroska.py index 6abece6e95886..445e22237216d 100755 --- a/TOOLS/matroska.py +++ b/TOOLS/matroska.py @@ -4,6 +4,10 @@ Can also be used to directly parse Matroska files and display their contents. """ +import sys +from math import ldexp +from binascii import hexlify + # # This file is part of mpv. # @@ -242,14 +246,11 @@ ) -import sys -from math import ldexp -from binascii import hexlify - def byte2num(s): return int(hexlify(s), 16) -class EOF(Exception): pass +class EOF(Exception): + pass def camelcase_to_words(name): parts = [] @@ -291,9 +292,9 @@ def add_subelements(self, subelements): elementd = {} elementlist = [] -def parse_elems(l, namespace): +def parse_elems(elements, namespace): subelements = [] - for el in l: + for el in elements: if isinstance(el, str): name, hexid, eltype = [x.strip() for x in el.split(',')] hexid = hexid.lower() @@ -328,10 +329,10 @@ def generate_C_header(out): continue printf(out) printf(out, 'struct {0.structname} {{'.format(el)) - l = max(len(subel.valname) for subel, multiple in el.subelements)+1 + length = max(len(subel.valname) for subel, multiple in el.subelements)+1 for subel, multiple in el.subelements: - printf(out, ' {e.valname:{l}} {star}{e.fieldname};'.format( - e=subel, l=l, star=' *'[multiple])) + printf(out, ' {e.valname:{length}} {star}{e.fieldname};'.format( + e=subel, length=length, star=' *'[multiple])) printf(out) for subel, multiple in el.subelements: printf(out, ' int n_{0.fieldname};'.format(subel)) diff --git a/TOOLS/stats-conv.py b/TOOLS/stats-conv.py index 0a9cf4ee9eb25..774e77bdcce72 100755 --- a/TOOLS/stats-conv.py +++ b/TOOLS/stats-conv.py @@ -161,7 +161,7 @@ def mkColor(t): for e in G.sevents: cur = ax[1 if e.type == "value" else 0] - if not cur in G.curveno: + if cur not in G.curveno: G.curveno[cur] = 0 args = {'name': e.name,'antialias':True} color = mkColor(colors[G.curveno[cur] % len(colors)]) diff --git a/ci/lint-commit-msg.py b/ci/lint-commit-msg.py index 3ceaa24fbf0c1..36497b66e45fe 100755 --- a/ci/lint-commit-msg.py +++ b/ci/lint-commit-msg.py @@ -1,5 +1,9 @@ #!/usr/bin/env python3 -import os, sys, json, subprocess, re +import os +import sys +import json +import subprocess +import re from typing import Dict, Tuple, Callable, Optional def call(cmd) -> str: