Enabled the ruff python linter in CI, and resolved the issues that were detected by it. Ruff was used due to it's faster checking compared with other linters like pylint. This was added to resolve the python linting request in #13608.
Unified · Split
| @@ -33,3 +33,9 @@ jobs: · 32 unmodified lines | ||
| 33 | 33 | steps: |
| 34 | 34 | - uses: actions/checkout@v4 |
| 35 | 35 | - uses: lunarmodules/luacheck@v1 |
| 36 | + | |
| 37 | + python-lint: | |
| 38 | + runs-on: ubuntu-latest | |
| 39 | + steps: | |
| 40 | + - uses: actions/checkout@v4 | |
| 41 | + - uses: chartboost/ruff-action@v1 | |
| @@ -58,7 +58,7 @@ try: · 57 unmodified lines | ||
| 58 | 58 | proc = subprocess.run(argv, check=True) |
| 59 | 59 | if depfile is not None: |
| 60 | 60 | convert_depfile(output, depfile) |
| 61 | −except: | |
| 61 | +except Exception: | |
| 62 | 62 | remove(output) |
| 63 | 63 | if depfile is not None: |
| 64 | 64 | remove(depfile) |
| @@ -16,13 +16,13 @@ def is_user_lib(objfile, libname): · 15 unmodified lines | ||
| 16 | 16 | return not sys_re.match(libname) and \ |
| 17 | 17 | not usr_re.match(libname) and \ |
| 18 | 18 | not exe_re.match(libname) and \ |
| 19 | − not "libobjc." in libname and \ | |
| 20 | − not "libSystem." in libname and \ | |
| 21 | − not "libc." in libname and \ | |
| 22 | − not "libgcc." in libname and \ | |
| 19 | + "libobjc." not in libname and \ | |
| 20 | + "libSystem." not in libname and \ | |
| 21 | + "libc." not in libname and \ | |
| 22 | + "libgcc." not in libname and \ | |
| 23 | 23 | not os.path.basename(libname) == 'Python' and \ |
| 24 | − not os.path.basename(objfile) in libname and \ | |
| 25 | − not "libswift" in libname | |
| 24 | + os.path.basename(objfile) not in libname and \ | |
| 25 | + "libswift" not in libname | |
| 26 | 26 | |
| 27 | 27 | def otool(objfile, rapths): |
| 28 | 28 | command = "otool -L '%s' | grep -e '\t' | awk '{ print $1 }'" % objfile |
| @@ -46,7 +46,7 @@ def get_rapths(objfile): · 17 unmodified lines | ||
| 46 | 46 | |
| 47 | 47 | try: |
| 48 | 48 | result = subprocess.check_output(command, shell = True, universal_newlines=True) |
| 49 | − except: | |
| 49 | + except Exception: | |
| 50 | 50 | return rpaths |
| 51 | 51 | |
| 52 | 52 | for line in result.splitlines(): |
| @@ -90,9 +90,9 @@ def resolve_lib_path(objfile, lib, rapths): · 37 unmodified lines | ||
| 90 | 90 | |
| 91 | 91 | def check_vulkan_max_version(version): |
| 92 | 92 | try: |
| 93 | − result = subprocess.check_output("pkg-config vulkan --max-version=" + version, shell = True) | |
| 93 | + subprocess.check_output("pkg-config vulkan --max-version=" + version, shell = True) | |
| 94 | 94 | return True |
| 95 | − except: | |
| 95 | + except Exception: | |
| 96 | 96 | return False |
| 97 | 97 | |
| 98 | 98 | def get_homebrew_prefix(): |
| @@ -100,7 +100,7 @@ def get_homebrew_prefix(): · 1 unmodified line | ||
| 100 | 100 | result = "/opt/homebrew" |
| 101 | 101 | try: |
| 102 | 102 | result = subprocess.check_output("brew --prefix", universal_newlines=True, shell=True, stderr=subprocess.DEVNULL).strip() |
| 103 | − except: | |
| 103 | + except Exception: | |
| 104 | 104 | pass |
| 105 | 105 | |
| 106 | 106 | return result |
| @@ -3,9 +3,7 @@ · 2 unmodified lines | ||
| 3 | 3 | # This checks for the sdk path, the sdk version, and |
| 4 | 4 | # the sdk build version. |
| 5 | 5 | |
| 6 | −import re | |
| 7 | 6 | import os |
| 8 | −import string | |
| 9 | 7 | import subprocess |
| 10 | 8 | import sys |
| 11 | 9 | from shutil import which |
| @@ -33,7 +31,7 @@ def find_macos_sdk(): · 21 unmodified lines | ||
| 33 | 31 | try: |
| 34 | 32 | sdk_version = check_output([xcodebuild, '-sdk', 'macosx', '-version', 'ProductVersion'], |
| 35 | 33 | encoding="UTF-8", stderr=subprocess.DEVNULL) |
| 36 | − except: | |
| 34 | + except Exception: | |
| 37 | 35 | pass |
| 38 | 36 | |
| 39 | 37 | if not isinstance(sdk_version, str): |
| @@ -4,6 +4,10 @@ Generate C definitions for parsing Matroska files. · 3 unmodified lines | ||
| 4 | 4 | Can also be used to directly parse Matroska files and display their contents. |
| 5 | 5 | """ |
| 6 | 6 | |
| 7 | +import sys | |
| 8 | +from math import ldexp | |
| 9 | +from binascii import hexlify | |
| 10 | + | |
| 7 | 11 | # |
| 8 | 12 | # This file is part of mpv. |
| 9 | 13 | # |
| @@ -242,14 +246,11 @@ elements_matroska = ( · 232 unmodified lines | ||
| 242 | 246 | ) |
| 243 | 247 | |
| 244 | 248 | |
| 245 | −import sys | |
| 246 | −from math import ldexp | |
| 247 | −from binascii import hexlify | |
| 248 | − | |
| 249 | 249 | def byte2num(s): |
| 250 | 250 | return int(hexlify(s), 16) |
| 251 | 251 | |
| 252 | −class EOF(Exception): pass | |
| 252 | +class EOF(Exception): | |
| 253 | + pass | |
| 253 | 254 | |
| 254 | 255 | def camelcase_to_words(name): |
| 255 | 256 | parts = [] |
| @@ -291,9 +292,9 @@ class MatroskaElement(object): · 35 unmodified lines | ||
| 291 | 292 | |
| 292 | 293 | elementd = {} |
| 293 | 294 | elementlist = [] |
| 294 | −def parse_elems(l, namespace): | |
| 295 | +def parse_elems(elements, namespace): | |
| 295 | 296 | subelements = [] |
| 296 | − for el in l: | |
| 297 | + for el in elements: | |
| 297 | 298 | if isinstance(el, str): |
| 298 | 299 | name, hexid, eltype = [x.strip() for x in el.split(',')] |
| 299 | 300 | hexid = hexid.lower() |
| @@ -328,10 +329,10 @@ def generate_C_header(out): · 28 unmodified lines | ||
| 328 | 329 | continue |
| 329 | 330 | printf(out) |
| 330 | 331 | printf(out, 'struct {0.structname} {{'.format(el)) |
| 331 | − l = max(len(subel.valname) for subel, multiple in el.subelements)+1 | |
| 332 | + length = max(len(subel.valname) for subel, multiple in el.subelements)+1 | |
| 332 | 333 | for subel, multiple in el.subelements: |
| 333 | − printf(out, ' {e.valname:{l}} {star}{e.fieldname};'.format( | |
| 334 | − e=subel, l=l, star=' *'[multiple])) | |
| 334 | + printf(out, ' {e.valname:{length}} {star}{e.fieldname};'.format( | |
| 335 | + e=subel, length=length, star=' *'[multiple])) | |
| 335 | 336 | printf(out) |
| 336 | 337 | for subel, multiple in el.subelements: |
| 337 | 338 | printf(out, ' int n_{0.fieldname};'.format(subel)) |
| @@ -161,7 +161,7 @@ for cur in ax: · 160 unmodified lines | ||
| 161 | 161 | |
| 162 | 162 | for e in G.sevents: |
| 163 | 163 | cur = ax[1 if e.type == "value" else 0] |
| 164 | − if not cur in G.curveno: | |
| 164 | + if cur not in G.curveno: | |
| 165 | 165 | G.curveno[cur] = 0 |
| 166 | 166 | args = {'name': e.name,'antialias':True} |
| 167 | 167 | color = mkColor(colors[G.curveno[cur] % len(colors)]) |
| @@ -1,5 +1,9 @@ | ||
| 1 | 1 | #!/usr/bin/env python3 |
| 2 | −import os, sys, json, subprocess, re | |
| 2 | +import os | |
| 3 | +import sys | |
| 4 | +import json | |
| 5 | +import subprocess | |
| 6 | +import re | |
| 3 | 7 | from typing import Dict, Tuple, Callable, Optional |
| 4 | 8 | |
| 5 | 9 | def call(cmd) -> str: |