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
33 steps:33 steps:
34 - uses: actions/checkout@v434 - uses: actions/checkout@v4
35 - uses: lunarmodules/luacheck@v135 - 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
58 proc = subprocess.run(argv, check=True)58 proc = subprocess.run(argv, check=True)
59 if depfile is not None:59 if depfile is not None:
60 convert_depfile(output, depfile)60 convert_depfile(output, depfile)
61except:61except Exception:
62 remove(output)62 remove(output)
63 if depfile is not None:63 if depfile is not None:
64 remove(depfile)64 remove(depfile)
TOOLS/dylib_unhell.py+10−10
@@ -16,13 +16,13 @@ def is_user_lib(objfile, libname): · 15 unmodified lines
16 return not sys_re.match(libname) and \16 return not sys_re.match(libname) and \
17 not usr_re.match(libname) and \17 not usr_re.match(libname) and \
18 not exe_re.match(libname) and \18 not exe_re.match(libname) and \
19 not "libobjc." in libname and \19 "libobjc." not in libname and \
20 not "libSystem." in libname and \20 "libSystem." not in libname and \
21 not "libc." in libname and \21 "libc." not in libname and \
22 not "libgcc." in libname and \22 "libgcc." not in libname and \
23 not os.path.basename(libname) == 'Python' and \23 not os.path.basename(libname) == 'Python' and \
24 not os.path.basename(objfile) in libname and \24 os.path.basename(objfile) not in libname and \
25 not "libswift" in libname25 "libswift" not in libname
26 26
27def otool(objfile, rapths):27def otool(objfile, rapths):
28 command = "otool -L '%s' | grep -e '\t' | awk '{ print $1 }'" % objfile28 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 try:47 try:
48 result = subprocess.check_output(command, shell = True, universal_newlines=True)48 result = subprocess.check_output(command, shell = True, universal_newlines=True)
49 except:49 except Exception:
50 return rpaths50 return rpaths
51 51
52 for line in result.splitlines():52 for line in result.splitlines():
@@ -90,9 +90,9 @@ def resolve_lib_path(objfile, lib, rapths): · 37 unmodified lines
90 90
91def check_vulkan_max_version(version):91def check_vulkan_max_version(version):
92 try: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 return True94 return True
95 except:95 except Exception:
96 return False96 return False
97 97
98def get_homebrew_prefix():98def get_homebrew_prefix():
@@ -100,7 +100,7 @@ def get_homebrew_prefix(): · 1 unmodified line
100 result = "/opt/homebrew"100 result = "/opt/homebrew"
101 try:101 try:
102 result = subprocess.check_output("brew --prefix", universal_newlines=True, shell=True, stderr=subprocess.DEVNULL).strip()102 result = subprocess.check_output("brew --prefix", universal_newlines=True, shell=True, stderr=subprocess.DEVNULL).strip()
103 except:103 except Exception:
104 pass104 pass
105 105
106 return result106 return result
TOOLS/macos-sdk-version.py+1−3
@@ -3,9 +3,7 @@ · 2 unmodified lines
3# This checks for the sdk path, the sdk version, and3# This checks for the sdk path, the sdk version, and
4# the sdk build version.4# the sdk build version.
5 5
6import re
7import os6import os
8import string
9import subprocess7import subprocess
10import sys8import sys
11from shutil import which9from shutil import which
@@ -33,7 +31,7 @@ def find_macos_sdk(): · 21 unmodified lines
33 try:31 try:
34 sdk_version = check_output([xcodebuild, '-sdk', 'macosx', '-version', 'ProductVersion'],32 sdk_version = check_output([xcodebuild, '-sdk', 'macosx', '-version', 'ProductVersion'],
35 encoding="UTF-8", stderr=subprocess.DEVNULL)33 encoding="UTF-8", stderr=subprocess.DEVNULL)
36 except:34 except Exception:
37 pass35 pass
38 36
39 if not isinstance(sdk_version, str):37 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
4Can also be used to directly parse Matroska files and display their contents.4Can also be used to directly parse Matroska files and display their contents.
5"""5"""
6 6
7import sys
8from math import ldexp
9from binascii import hexlify
10
7#11#
8# This file is part of mpv.12# This file is part of mpv.
9#13#
@@ -242,14 +246,11 @@ elements_matroska = ( · 232 unmodified lines
242)246)
243 247
244 248
245import sys
246from math import ldexp
247from binascii import hexlify
248
249def byte2num(s):249def byte2num(s):
250 return int(hexlify(s), 16)250 return int(hexlify(s), 16)
251 251
252class EOF(Exception): pass252class EOF(Exception):
253 pass
253 254
254def camelcase_to_words(name):255def camelcase_to_words(name):
255 parts = []256 parts = []
@@ -291,9 +292,9 @@ class MatroskaElement(object): · 35 unmodified lines
291 292
292elementd = {}293elementd = {}
293elementlist = []294elementlist = []
294def parse_elems(l, namespace):295def parse_elems(elements, namespace):
295 subelements = []296 subelements = []
296 for el in l:297 for el in elements:
297 if isinstance(el, str):298 if isinstance(el, str):
298 name, hexid, eltype = [x.strip() for x in el.split(',')]299 name, hexid, eltype = [x.strip() for x in el.split(',')]
299 hexid = hexid.lower()300 hexid = hexid.lower()
@@ -328,10 +329,10 @@ def generate_C_header(out): · 28 unmodified lines
328 continue329 continue
329 printf(out)330 printf(out)
330 printf(out, 'struct {0.structname} {{'.format(el))331 printf(out, 'struct {0.structname} {{'.format(el))
331 l = max(len(subel.valname) for subel, multiple in el.subelements)+1332 length = max(len(subel.valname) for subel, multiple in el.subelements)+1
332 for subel, multiple in el.subelements:333 for subel, multiple in el.subelements:
333 printf(out, ' {e.valname:{l}} {star}{e.fieldname};'.format(334 printf(out, ' {e.valname:{length}} {star}{e.fieldname};'.format(
334 e=subel, l=l, star=' *'[multiple]))335 e=subel, length=length, star=' *'[multiple]))
335 printf(out)336 printf(out)
336 for subel, multiple in el.subelements:337 for subel, multiple in el.subelements:
337 printf(out, ' int n_{0.fieldname};'.format(subel))338 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
161 161
162for e in G.sevents:162for e in G.sevents:
163 cur = ax[1 if e.type == "value" else 0]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 G.curveno[cur] = 0165 G.curveno[cur] = 0
166 args = {'name': e.name,'antialias':True}166 args = {'name': e.name,'antialias':True}
167 color = mkColor(colors[G.curveno[cur] % len(colors)])167 color = mkColor(colors[G.curveno[cur] % len(colors)])
ci/lint-commit-msg.py+5−1
@@ -1,5 +1,9 @@
1#!/usr/bin/env python31#!/usr/bin/env python3
2import os, sys, json, subprocess, re2import os
3import sys
4import json
5import subprocess
6import re
3from typing import Dict, Tuple, Callable, Optional7from typing import Dict, Tuple, Callable, Optional
4 8
5def call(cmd) -> str:9def 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