History

ci/lint: add python linting

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.

Nathan Ruiz committed 2 years ago

Commit bee35981 parent f46975c7 files · +35 −26Browse files

Unified · Split

7 files
  1. .github/workflows/lint.yml +6 −0
  2. TOOLS/docutils-wrapper.py +1 −1
  3. TOOLS/dylib_unhell.py +10 −10
  4. TOOLS/macos-sdk-version.py +1 −3
  5. TOOLS/matroska.py +11 −10
  6. TOOLS/stats-conv.py +1 −1
  7. ci/lint-commit-msg.py +5 −1
.github/workflows/lint.yml+6−0
@@ -33,3 +33,9 @@ jobs: · 32 unmodified lines
3333 steps:
3434 - uses: actions/checkout@v4
3535 - 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
TOOLS/docutils-wrapper.py+1−1
@@ -58,7 +58,7 @@ try: · 57 unmodified lines
5858 proc = subprocess.run(argv, check=True)
5959 if depfile is not None:
6060 convert_depfile(output, depfile)
61−except:
61+except Exception:
6262 remove(output)
6363 if depfile is not None:
6464 remove(depfile)
TOOLS/dylib_unhell.py+10−10
@@ -16,13 +16,13 @@ def is_user_lib(objfile, libname): · 15 unmodified lines
1616 return not sys_re.match(libname) and \
1717 not usr_re.match(libname) and \
1818 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 \
2323 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
2626
2727 def otool(objfile, rapths):
2828 command = "otool -L '%s' | grep -e '\t' | awk '{ print $1 }'" % objfile
@@ -46,7 +46,7 @@ def get_rapths(objfile): · 17 unmodified lines
4646
4747 try:
4848 result = subprocess.check_output(command, shell = True, universal_newlines=True)
49− except:
49+ except Exception:
5050 return rpaths
5151
5252 for line in result.splitlines():
@@ -90,9 +90,9 @@ def resolve_lib_path(objfile, lib, rapths): · 37 unmodified lines
9090
9191 def check_vulkan_max_version(version):
9292 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)
9494 return True
95− except:
95+ except Exception:
9696 return False
9797
9898 def get_homebrew_prefix():
@@ -100,7 +100,7 @@ def get_homebrew_prefix(): · 1 unmodified line
100100 result = "/opt/homebrew"
101101 try:
102102 result = subprocess.check_output("brew --prefix", universal_newlines=True, shell=True, stderr=subprocess.DEVNULL).strip()
103− except:
103+ except Exception:
104104 pass
105105
106106 return result
TOOLS/macos-sdk-version.py+1−3
@@ -3,9 +3,7 @@ · 2 unmodified lines
33 # This checks for the sdk path, the sdk version, and
44 # the sdk build version.
55
6−import re
76 import os
8−import string
97 import subprocess
108 import sys
119 from shutil import which
@@ -33,7 +31,7 @@ def find_macos_sdk(): · 21 unmodified lines
3331 try:
3432 sdk_version = check_output([xcodebuild, '-sdk', 'macosx', '-version', 'ProductVersion'],
3533 encoding="UTF-8", stderr=subprocess.DEVNULL)
36− except:
34+ except Exception:
3735 pass
3836
3937 if not isinstance(sdk_version, str):
TOOLS/matroska.py+11−10
@@ -4,6 +4,10 @@ Generate C definitions for parsing Matroska files. · 3 unmodified lines
44 Can also be used to directly parse Matroska files and display their contents.
55 """
66
7+import sys
8+from math import ldexp
9+from binascii import hexlify
10+
711 #
812 # This file is part of mpv.
913 #
@@ -242,14 +246,11 @@ elements_matroska = ( · 232 unmodified lines
242246 )
243247
244248
245−import sys
246−from math import ldexp
247−from binascii import hexlify
248−
249249 def byte2num(s):
250250 return int(hexlify(s), 16)
251251
252−class EOF(Exception): pass
252+class EOF(Exception):
253+ pass
253254
254255 def camelcase_to_words(name):
255256 parts = []
@@ -291,9 +292,9 @@ class MatroskaElement(object): · 35 unmodified lines
291292
292293 elementd = {}
293294 elementlist = []
294−def parse_elems(l, namespace):
295+def parse_elems(elements, namespace):
295296 subelements = []
296− for el in l:
297+ for el in elements:
297298 if isinstance(el, str):
298299 name, hexid, eltype = [x.strip() for x in el.split(',')]
299300 hexid = hexid.lower()
@@ -328,10 +329,10 @@ def generate_C_header(out): · 28 unmodified lines
328329 continue
329330 printf(out)
330331 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
332333 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]))
335336 printf(out)
336337 for subel, multiple in el.subelements:
337338 printf(out, ' int n_{0.fieldname};'.format(subel))
TOOLS/stats-conv.py+1−1
@@ -161,7 +161,7 @@ for cur in ax: · 160 unmodified lines
161161
162162 for e in G.sevents:
163163 cur = ax[1 if e.type == "value" else 0]
164− if not cur in G.curveno:
164+ if cur not in G.curveno:
165165 G.curveno[cur] = 0
166166 args = {'name': e.name,'antialias':True}
167167 color = mkColor(colors[G.curveno[cur] % len(colors)])
ci/lint-commit-msg.py+5−1
@@ -1,5 +1,9 @@
11 #!/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
37 from typing import Dict, Tuple, Callable, Optional
48
59 def call(cmd) -> str:

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t