mirror of
https://github.com/servo/servo.git
synced 2025-07-23 15:23:42 +01:00
Fix new flake8 warnings
This commit is contained in:
parent
98a40a432c
commit
96b8f39277
3 changed files with 44 additions and 41 deletions
|
@ -46,7 +46,7 @@ def notify_linux(title, text):
|
||||||
notify_obj = bus.get_object("org.freedesktop.Notifications", "/org/freedesktop/Notifications")
|
notify_obj = bus.get_object("org.freedesktop.Notifications", "/org/freedesktop/Notifications")
|
||||||
method = notify_obj.get_dbus_method("Notify", "org.freedesktop.Notifications")
|
method = notify_obj.get_dbus_method("Notify", "org.freedesktop.Notifications")
|
||||||
method(title, 0, "", text, "", [], {"transient": True}, -1)
|
method(title, 0, "", text, "", [], {"transient": True}, -1)
|
||||||
except:
|
except ImportError:
|
||||||
raise Exception("Optional Python module 'dbus' is not installed.")
|
raise Exception("Optional Python module 'dbus' is not installed.")
|
||||||
|
|
||||||
|
|
||||||
|
@ -55,7 +55,7 @@ def notify_win(title, text):
|
||||||
from servo.win32_toast import WindowsToast
|
from servo.win32_toast import WindowsToast
|
||||||
w = WindowsToast()
|
w = WindowsToast()
|
||||||
w.balloon_tip(title, text)
|
w.balloon_tip(title, text)
|
||||||
except:
|
except WindowsError:
|
||||||
from ctypes import Structure, windll, POINTER, sizeof
|
from ctypes import Structure, windll, POINTER, sizeof
|
||||||
from ctypes.wintypes import DWORD, HANDLE, WINFUNCTYPE, BOOL, UINT
|
from ctypes.wintypes import DWORD, HANDLE, WINFUNCTYPE, BOOL, UINT
|
||||||
|
|
||||||
|
@ -920,7 +920,7 @@ def package_gstreamer_dlls(env, servo_exe_dir, target, uwp):
|
||||||
for gst_lib in gst_dlls:
|
for gst_lib in gst_dlls:
|
||||||
try:
|
try:
|
||||||
shutil.copy(path.join(gst_root, "bin", gst_lib), servo_exe_dir)
|
shutil.copy(path.join(gst_root, "bin", gst_lib), servo_exe_dir)
|
||||||
except:
|
except FileNotFoundError:
|
||||||
missing += [str(gst_lib)]
|
missing += [str(gst_lib)]
|
||||||
|
|
||||||
for gst_lib in missing:
|
for gst_lib in missing:
|
||||||
|
@ -976,7 +976,7 @@ def package_gstreamer_dlls(env, servo_exe_dir, target, uwp):
|
||||||
for gst_lib in gst_dlls:
|
for gst_lib in gst_dlls:
|
||||||
try:
|
try:
|
||||||
shutil.copy(path.join(gst_plugin_path, gst_lib), servo_exe_dir)
|
shutil.copy(path.join(gst_plugin_path, gst_lib), servo_exe_dir)
|
||||||
except:
|
except FileNotFoundError:
|
||||||
missing += [str(gst_lib)]
|
missing += [str(gst_lib)]
|
||||||
|
|
||||||
for gst_lib in missing:
|
for gst_lib in missing:
|
||||||
|
|
|
@ -487,7 +487,7 @@ class CommandBase(object):
|
||||||
print("Could not fetch the available nightly versions from the repository : {}".format(
|
print("Could not fetch the available nightly versions from the repository : {}".format(
|
||||||
e.reason))
|
e.reason))
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
except AttributeError as e:
|
except AttributeError:
|
||||||
print("Could not fetch a nightly version for date {} and platform {}".format(
|
print("Could not fetch a nightly version for date {} and platform {}".format(
|
||||||
nightly_date, os_prefix))
|
nightly_date, os_prefix))
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
@ -517,8 +517,8 @@ class CommandBase(object):
|
||||||
else:
|
else:
|
||||||
print("The nightly {} does not exist yet, downloading it.".format(
|
print("The nightly {} does not exist yet, downloading it.".format(
|
||||||
destination_file))
|
destination_file))
|
||||||
download_file(destination_file, NIGHTLY_REPOSITORY_URL +
|
download_file(destination_file, NIGHTLY_REPOSITORY_URL
|
||||||
file_to_download, destination_file)
|
+ file_to_download, destination_file)
|
||||||
|
|
||||||
# Extract the downloaded nightly version
|
# Extract the downloaded nightly version
|
||||||
if os.path.isdir(destination_folder):
|
if os.path.isdir(destination_folder):
|
||||||
|
@ -537,7 +537,7 @@ class CommandBase(object):
|
||||||
try:
|
try:
|
||||||
if check_gstreamer_lib():
|
if check_gstreamer_lib():
|
||||||
return False
|
return False
|
||||||
except:
|
except subprocess.SubprocessError:
|
||||||
# Some systems don't have pkg-config; we can't probe in this case
|
# Some systems don't have pkg-config; we can't probe in this case
|
||||||
# and must hope for the best
|
# and must hope for the best
|
||||||
return False
|
return False
|
||||||
|
@ -552,7 +552,7 @@ class CommandBase(object):
|
||||||
raise Exception("Your system's gstreamer libraries are out of date \
|
raise Exception("Your system's gstreamer libraries are out of date \
|
||||||
(we need at least 1.16). Please run ./mach bootstrap-gstreamer")
|
(we need at least 1.16). Please run ./mach bootstrap-gstreamer")
|
||||||
else:
|
else:
|
||||||
raise Exception("Your system's gstreamer libraries are out of date \
|
raise Exception("Your system's gstreamer libraries are out of date \
|
||||||
(we need at least 1.16). If you're unable to \
|
(we need at least 1.16). If you're unable to \
|
||||||
install them, let us know by filing a bug!")
|
install them, let us know by filing a bug!")
|
||||||
return False
|
return False
|
||||||
|
@ -858,9 +858,9 @@ install them, let us know by filing a bug!")
|
||||||
def pick_media_stack(self, media_stack, target):
|
def pick_media_stack(self, media_stack, target):
|
||||||
if not(media_stack):
|
if not(media_stack):
|
||||||
if (
|
if (
|
||||||
not(target) or
|
not(target)
|
||||||
("armv7" in target and "android" in target) or
|
or ("armv7" in target and "android" in target)
|
||||||
("x86_64" in target)
|
or ("x86_64" in target)
|
||||||
):
|
):
|
||||||
media_stack = "gstreamer"
|
media_stack = "gstreamer"
|
||||||
else:
|
else:
|
||||||
|
@ -1032,7 +1032,7 @@ install them, let us know by filing a bug!")
|
||||||
print()
|
print()
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
raise
|
raise
|
||||||
version = tuple(map(int, re.match(b"rustup (\d+)\.(\d+)\.(\d+)", version_line).groups()))
|
version = tuple(map(int, re.match(br"rustup (\d+)\.(\d+)\.(\d+)", version_line).groups()))
|
||||||
version_needed = (1, 21, 0)
|
version_needed = (1, 21, 0)
|
||||||
if version < version_needed:
|
if version < version_needed:
|
||||||
print("rustup is at version %s.%s.%s, Servo requires %s.%s.%s or more recent." % (version + version_needed))
|
print("rustup is at version %s.%s.%s, Servo requires %s.%s.%s or more recent." % (version + version_needed))
|
||||||
|
@ -1069,8 +1069,8 @@ install them, let us know by filing a bug!")
|
||||||
|
|
||||||
def find_highest_msvc_version_ext():
|
def find_highest_msvc_version_ext():
|
||||||
def vswhere(args):
|
def vswhere(args):
|
||||||
program_files = (os.environ.get('PROGRAMFILES(X86)') or
|
program_files = (os.environ.get('PROGRAMFILES(X86)')
|
||||||
os.environ.get('PROGRAMFILES'))
|
or os.environ.get('PROGRAMFILES'))
|
||||||
if not program_files:
|
if not program_files:
|
||||||
return []
|
return []
|
||||||
vswhere = os.path.join(program_files, 'Microsoft Visual Studio',
|
vswhere = os.path.join(program_files, 'Microsoft Visual Studio',
|
||||||
|
@ -1107,8 +1107,8 @@ def find_highest_msvc_version():
|
||||||
|
|
||||||
versions = sorted(find_highest_msvc_version_ext(), key=lambda tup: float(tup[1]))
|
versions = sorted(find_highest_msvc_version_ext(), key=lambda tup: float(tup[1]))
|
||||||
if not versions:
|
if not versions:
|
||||||
print("Can't find MSBuild.exe installation under %s. Please set the VSINSTALLDIR and VisualStudioVersion" +
|
print("Can't find MSBuild.exe installation under %s. Please set the VSINSTALLDIR and VisualStudioVersion"
|
||||||
" environment variables" % base_vs_path)
|
+ " environment variables" % base_vs_path)
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
return versions[0]
|
return versions[0]
|
||||||
|
|
||||||
|
|
|
@ -33,10 +33,11 @@ wpt = os.path.join(topdir, "tests", "wpt")
|
||||||
def wpt_path(*args):
|
def wpt_path(*args):
|
||||||
return os.path.join(wpt, *args)
|
return os.path.join(wpt, *args)
|
||||||
|
|
||||||
|
|
||||||
CONFIG_FILE_PATH = os.path.join(".", "servo-tidy.toml")
|
CONFIG_FILE_PATH = os.path.join(".", "servo-tidy.toml")
|
||||||
WPT_MANIFEST_PATH = wpt_path("include.ini")
|
WPT_MANIFEST_PATH = wpt_path("include.ini")
|
||||||
# regex source https://stackoverflow.com/questions/6883049/
|
# regex source https://stackoverflow.com/questions/6883049/
|
||||||
URL_REGEX = re.compile(b'https?://(?:[-\w.]|(?:%[\da-fA-F]{2}))+')
|
URL_REGEX = re.compile(br'https?://(?:[-\w.]|(?:%[\da-fA-F]{2}))+')
|
||||||
|
|
||||||
# Import wptmanifest only when we do have wpt in tree, i.e. we're not
|
# Import wptmanifest only when we do have wpt in tree, i.e. we're not
|
||||||
# inside a Firefox checkout.
|
# inside a Firefox checkout.
|
||||||
|
@ -105,8 +106,8 @@ WEBIDL_STANDARDS = [
|
||||||
b"//github.com/immersive-web/webxr-hands-input/",
|
b"//github.com/immersive-web/webxr-hands-input/",
|
||||||
b"//gpuweb.github.io",
|
b"//gpuweb.github.io",
|
||||||
# Not a URL
|
# Not a URL
|
||||||
b"// This interface is entirely internal to Servo, and should not be" +
|
b"// This interface is entirely internal to Servo, and should not be"
|
||||||
b" accessible to\n// web pages."
|
+ b" accessible to\n// web pages."
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
||||||
|
@ -235,14 +236,14 @@ def check_license(file_name, lines):
|
||||||
max_blank_lines = 2 if lines[0].startswith(b"#!") else 1
|
max_blank_lines = 2 if lines[0].startswith(b"#!") else 1
|
||||||
license_block = []
|
license_block = []
|
||||||
|
|
||||||
for l in lines:
|
for line in lines:
|
||||||
l = l.rstrip(b'\n')
|
line = line.rstrip(b'\n')
|
||||||
if not l.strip():
|
if not line.strip():
|
||||||
blank_lines += 1
|
blank_lines += 1
|
||||||
if blank_lines >= max_blank_lines:
|
if blank_lines >= max_blank_lines:
|
||||||
break
|
break
|
||||||
continue
|
continue
|
||||||
line = uncomment(l)
|
line = uncomment(line)
|
||||||
if line is not None:
|
if line is not None:
|
||||||
license_block.append(line)
|
license_block.append(line)
|
||||||
|
|
||||||
|
@ -257,7 +258,7 @@ def check_modeline(file_name, lines):
|
||||||
for idx, line in enumerate(lines[:5]):
|
for idx, line in enumerate(lines[:5]):
|
||||||
if re.search(b'^.*[ \t](vi:|vim:|ex:)[ \t]', line):
|
if re.search(b'^.*[ \t](vi:|vim:|ex:)[ \t]', line):
|
||||||
yield (idx + 1, "vi modeline present")
|
yield (idx + 1, "vi modeline present")
|
||||||
elif re.search(b'-\*-.*-\*-', line, re.IGNORECASE):
|
elif re.search(br'-\*-.*-\*-', line, re.IGNORECASE):
|
||||||
yield (idx + 1, "emacs file variables present")
|
yield (idx + 1, "emacs file variables present")
|
||||||
|
|
||||||
|
|
||||||
|
@ -278,10 +279,10 @@ def contains_url(line):
|
||||||
|
|
||||||
def is_unsplittable(file_name, line):
|
def is_unsplittable(file_name, line):
|
||||||
return (
|
return (
|
||||||
contains_url(line) or
|
contains_url(line)
|
||||||
file_name.endswith(".rs") and
|
or file_name.endswith(".rs")
|
||||||
line.startswith(b"use ") and
|
and line.startswith(b"use ")
|
||||||
b"{" not in line
|
and b"{" not in line
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
@ -334,6 +335,7 @@ def check_flake8(file_name, contents):
|
||||||
|
|
||||||
ignore = {
|
ignore = {
|
||||||
"W291", # trailing whitespace; the standard tidy process will enforce no trailing whitespace
|
"W291", # trailing whitespace; the standard tidy process will enforce no trailing whitespace
|
||||||
|
"W503", # linebreak before binary operator; replaced by W504 - linebreak after binary operator
|
||||||
"E501", # 80 character line length; the standard tidy process will enforce line length
|
"E501", # 80 character line length; the standard tidy process will enforce line length
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -485,7 +487,7 @@ def check_shell(file_name, lines):
|
||||||
if " [ " in stripped or stripped.startswith("[ "):
|
if " [ " in stripped or stripped.startswith("[ "):
|
||||||
yield (idx + 1, "script should use `[[` instead of `[` for conditional testing")
|
yield (idx + 1, "script should use `[[` instead of `[` for conditional testing")
|
||||||
|
|
||||||
for dollar in re.finditer('\$', stripped):
|
for dollar in re.finditer(r'\$', stripped):
|
||||||
next_idx = dollar.end()
|
next_idx = dollar.end()
|
||||||
if next_idx < len(stripped):
|
if next_idx < len(stripped):
|
||||||
next_char = stripped[next_idx]
|
next_char = stripped[next_idx]
|
||||||
|
@ -605,14 +607,15 @@ def check_rust(file_name, lines):
|
||||||
multi_line_string = True
|
multi_line_string = True
|
||||||
|
|
||||||
# get rid of comments
|
# get rid of comments
|
||||||
line = re.sub('//.*?$|/\*.*?$|^\*.*?$', '//', line)
|
line = re.sub(r'//.*?$|/\*.*?$|^\*.*?$', '//', line)
|
||||||
|
|
||||||
# get rid of attributes that do not contain =
|
# get rid of attributes that do not contain =
|
||||||
line = re.sub('^#[A-Za-z0-9\(\)\[\]_]*?$', '#[]', line)
|
line = re.sub(r'^#[A-Za-z0-9\(\)\[\]_]*?$', '#[]', line)
|
||||||
|
|
||||||
# flag this line if it matches one of the following regular expressions
|
# flag this line if it matches one of the following regular expressions
|
||||||
# tuple format: (pattern, format_message, filter_function(match, line))
|
# tuple format: (pattern, format_message, filter_function(match, line))
|
||||||
no_filter = lambda match, line: True
|
def no_filter(match, line):
|
||||||
|
return True
|
||||||
regex_rules = [
|
regex_rules = [
|
||||||
# There should not be any extra pointer dereferencing
|
# There should not be any extra pointer dereferencing
|
||||||
(r": &Vec<", "use &[T] instead of &Vec<T>", no_filter),
|
(r": &Vec<", "use &[T] instead of &Vec<T>", no_filter),
|
||||||
|
@ -856,16 +859,16 @@ def check_spec(file_name, lines):
|
||||||
if SPEC_BASE_PATH not in file_name:
|
if SPEC_BASE_PATH not in file_name:
|
||||||
raise StopIteration
|
raise StopIteration
|
||||||
file_name = os.path.relpath(os.path.splitext(file_name)[0], SPEC_BASE_PATH)
|
file_name = os.path.relpath(os.path.splitext(file_name)[0], SPEC_BASE_PATH)
|
||||||
patt = re.compile("^\s*\/\/.+")
|
patt = re.compile(r"^\s*\/\/.+")
|
||||||
|
|
||||||
# Pattern representing a line with a macro
|
# Pattern representing a line with a macro
|
||||||
macro_patt = re.compile("^\s*\S+!(.*)$")
|
macro_patt = re.compile(r"^\s*\S+!(.*)$")
|
||||||
|
|
||||||
# Pattern representing a line with comment containing a spec link
|
# Pattern representing a line with comment containing a spec link
|
||||||
link_patt = re.compile("^\s*///? (<https://.+>|https://.+)$")
|
link_patt = re.compile(r"^\s*///? (<https://.+>|https://.+)$")
|
||||||
|
|
||||||
# Pattern representing a line with comment or attribute
|
# Pattern representing a line with comment or attribute
|
||||||
comment_patt = re.compile("^\s*(///?.+|#\[.+\])$")
|
comment_patt = re.compile(r"^\s*(///?.+|#\[.+\])$")
|
||||||
|
|
||||||
brace_count = 0
|
brace_count = 0
|
||||||
in_impl = False
|
in_impl = False
|
||||||
|
@ -931,7 +934,7 @@ def check_config_file(config_file, print_text=True, no_wpt=False):
|
||||||
continue
|
continue
|
||||||
|
|
||||||
# Check for invalid tables
|
# Check for invalid tables
|
||||||
if re.match("\[(.*?)\]", line.strip()):
|
if re.match(r"\[(.*?)\]", line.strip()):
|
||||||
table_name = re.findall(r"\[(.*?)\]", line)[0].strip()
|
table_name = re.findall(r"\[(.*?)\]", line)[0].strip()
|
||||||
if table_name not in ("configs", "blocked-packages", "ignore", "check_ext"):
|
if table_name not in ("configs", "blocked-packages", "ignore", "check_ext"):
|
||||||
yield config_file, idx + 1, "invalid config table [%s]" % table_name
|
yield config_file, idx + 1, "invalid config table [%s]" % table_name
|
||||||
|
@ -961,10 +964,10 @@ def check_config_file(config_file, print_text=True, no_wpt=False):
|
||||||
key = line.split("=")[0].strip()
|
key = line.split("=")[0].strip()
|
||||||
|
|
||||||
# Check for invalid keys inside [configs] and [ignore] table
|
# Check for invalid keys inside [configs] and [ignore] table
|
||||||
if (current_table == "configs" and key not in config or
|
if (current_table == "configs" and key not in config
|
||||||
current_table == "ignore" and key not in config["ignore"] or
|
or current_table == "ignore" and key not in config["ignore"]
|
||||||
# Any key outside of tables
|
# Any key outside of tables
|
||||||
current_table == ""):
|
or current_table == ""):
|
||||||
yield config_file, idx + 1, "invalid config key '%s'" % key
|
yield config_file, idx + 1, "invalid config key '%s'" % key
|
||||||
|
|
||||||
# Parse config file
|
# Parse config file
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue