Skip to content

Commit

Permalink
ci/lint: add python linting
Browse files Browse the repository at this point in the history
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 mpv-player#13608.
  • Loading branch information
nathanruiz committed Sep 29, 2024
1 parent 4c19df1 commit 9ca5182
Show file tree
Hide file tree
Showing 7 changed files with 35 additions and 26 deletions.
6 changes: 6 additions & 0 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 1 addition & 1 deletion TOOLS/docutils-wrapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
20 changes: 10 additions & 10 deletions TOOLS/dylib_unhell.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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():
Expand Down Expand Up @@ -90,17 +90,17 @@ 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():
# set default to standard ARM path, intel path is already in the vulkan loader search array
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
Expand Down
4 changes: 1 addition & 3 deletions TOOLS/macos-sdk-version.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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):
Expand Down
21 changes: 11 additions & 10 deletions TOOLS/matroska.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
#
Expand Down Expand Up @@ -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 = []
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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))
Expand Down
2 changes: 1 addition & 1 deletion TOOLS/stats-conv.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)])
Expand Down
6 changes: 5 additions & 1 deletion ci/lint-commit-msg.py
Original file line number Diff line number Diff line change
@@ -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:
Expand Down

0 comments on commit 9ca5182

Please sign in to comment.